From 95d8e4136e763541cae053a7603fcf79664acde8 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 4 Dec 2005 07:46:08 +0000 Subject: fixed a problem with m3u importing on catalog add/build --- docs/CHANGELOG | 9 ++++++ lib/class/catalog.class.php | 29 ++++++++++++++---- lib/class/playlist.class.php | 70 ++++++++++++++++++++++++++++++++++---------- lib/class/update.class.php | 15 ++++++++++ 4 files changed, 101 insertions(+), 22 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index b2614722..8d613048 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -2,6 +2,15 @@ --------- Ampache -- CHANGELOG --------- -------------------------------------------------------------------------- +-------------------------------------------------------------------------- + v.3.3.2-Alpha4 + - Fixed a logic flaw where it would attempt to parse the m3u + before all songs were cataloged + https://ampache.bountysource.com/Task.View?task_id=122 + - Fixed a problem where updating your normal preferences when + use_auth was off would clear admin prefs + - Found a few more import_m3u($full_file)) { - echo "   " . _("Added Playlist From") . " $file . . . .
\n"; - flush(); - } + $this->_playlists[] = $full_file; } // if it's an m3u else { @@ -726,9 +726,18 @@ class Catalog { $this->get_remote_catalog($type=0); return true; } + /* Get the songs and then insert them into the db */ $this->add_files($this->path,$type,$parse_m3u); + foreach ($this->_playlists as $full_file) { + if ($this->import_m3u($full_file)) { + $file = basename($full_file); + echo "   " . _("Added Playlist From") . " $file . . . .
\n"; + flush(); + } // end if import worked + } // end foreach playlist files + /* Now Adding Album Art? */ if ($gather_art) { echo "
\n" . _("Starting Album Art Search") . ". . .
\n"; @@ -880,6 +889,14 @@ class Catalog { /* Get the songs and then insert them into the db */ $this->add_files($this->path,$type); + foreach ($this->_playlists as $full_file) { + if ($this->import_m3u($full_file)) { + $file = basename($full_file); + echo "   " . _("Added Playlist From") . " $file . . . .
\n"; + flush(); + } // end if import worked + } // end foreach playlist files + /* Do a little stats mojo here */ $current_time = time(); @@ -1972,12 +1989,12 @@ class Catalog { } // end foreach line - if (conf('debug')) { log_event($GLOBALS['user']->username,' m3u_parse ',"Parsing $filename - Found: " . count($songs) . " Songs"); } + if (conf('debug')) { log_event($GLOBALS['user']->username,'m3u_parse',"Parsing $filename - Found: " . count($songs) . " Songs"); } if (count($songs)) { $playlist = new Playlist(); $playlist_name = "M3U - " . basename($filename); - $playlist->create_playlist($playlist_name,$GLOBALS['user']->id,'public'); + $playlist->create_playlist($playlist_name,$GLOBALS['user']->username,'public'); $playlist->add_songs($songs); return true; } diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php index 68188d25..765a2219 100644 --- a/lib/class/playlist.class.php +++ b/lib/class/playlist.class.php @@ -104,19 +104,27 @@ class Playlist { if (isset($name) && isset($user) && isset($type) && $this->check_type($type)) { $name = sql_escape($name); - $sql = "INSERT INTO playlist" . - " (name, user, type)" . + $user = sql_escape($user); + $type = sql_escape($type); + + $sql = "INSERT INTO playlist (name, user, type)" . " VALUES ('$name', '$user', '$type')"; $db_results = mysql_query($sql, $dbh); + if ($this->id = mysql_insert_id($dbh)) { $this->refresh_object(); - return TRUE; - } + return true; + } // end if it created correctly + + } // end if this is a valid playlist entry + + if (conf('debug')) { + log_event($GLOBALS['user']->username,'playlist_create',"Failed to Create Playlist of $type Type named $name for $user"); } - return FALSE; + return false; - } + } // create_playlist /*! @@ -136,17 +144,16 @@ class Playlist { " WHERE id = '$this->id'"; $db_results = mysql_query($sql, $dbh); - // Clean up this object - foreach (get_object_vars($this) as $var) { - unset($var); - } + $sql = "DELETE FROM playlist_permission" . + " WHERE playlist = '$this->id'"; + $db_results = mysql_query($sql, $dbh); - return TRUE; - } + return true; + } // if we've got a valid playlist - return FALSE; + return false; - } + } // delete /*! @@ -218,7 +225,7 @@ class Playlist { return FALSE; - } + } // add_songs /*! @@ -313,6 +320,38 @@ class Playlist { } + /*! + @function normalize_tracks + @discussion this takes the crazy out of order tracks + and numbers them in a liner fashion, not allowing for + the same track # twice, this is an optional funcition + */ + function normalize_tracks() { + + /* First get all of the songs in order of their tracks */ + $sql = "SELECT id FROM playlist_data WHERE playlist='$this->id' ORDER BY track ASC"; + $db_results = mysql_query($sql, dbh()); + + $i = 1; + + while ($r = mysql_fetch_assoc($db_results)) { + $new_data = array(); + $new_data['id'] = $r['id']; + $new_data['track'] = $i; + $results[] = $new_data; + $i++; + } // end while results + + foreach($results as $data) { + $sql = "UPDATE playlist_data SET track='" . $data['track'] . "' WHERE" . + " id='" . $data['id'] . "'"; + $db_results = mysql_query($sql, dbh()); + } // foreach re-ordered results + + return true; + + } // normalize_tracks + /*! @function get_songs @@ -366,7 +405,6 @@ class Playlist { } // show_import - } //end of playlist class ?> diff --git a/lib/class/update.class.php b/lib/class/update.class.php index af14c2a0..8ef40403 100644 --- a/lib/class/update.class.php +++ b/lib/class/update.class.php @@ -1217,5 +1217,20 @@ class Update { } // update_332003 + /*! + @function update_332004 + @discussion adds a id to the playlist_data field because of a problem + with updating the same song on the same playlist being basicly + impossible...Also re-works the indexing on the tables + */ + function update_332004() { + + $sql = "ALTER TABLE `playlist_data` ADD `id` INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT FIRST"; + $db_results = mysql_query($sql, dbh()); + + $this->set_version('db_version','332004'); + + } // update_332004 + } // end update class ?> -- cgit