diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-04 07:46:08 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2005-12-04 07:46:08 +0000 |
commit | 95d8e4136e763541cae053a7603fcf79664acde8 (patch) | |
tree | 48ee7556711613411a8fb585b689a821c4f97d6b | |
parent | 14a95b00a23893d9c2a5f4d9545746a8d8cf8a4a (diff) | |
download | ampache-95d8e4136e763541cae053a7603fcf79664acde8.tar.gz ampache-95d8e4136e763541cae053a7603fcf79664acde8.tar.bz2 ampache-95d8e4136e763541cae053a7603fcf79664acde8.zip |
fixed a problem with m3u importing on catalog add/build
-rwxr-xr-x | docs/CHANGELOG | 9 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 29 | ||||
-rw-r--r-- | lib/class/playlist.class.php | 70 | ||||
-rw-r--r-- | 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 @@ -3,6 +3,15 @@ -------------------------------------------------------------------------- -------------------------------------------------------------------------- + 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 <? and replaced them with <?php + +-------------------------------------------------------------------------- v.3.3.2-Alpha3 11/29/2005 - Added marineam's patch to the Snoopy class which fixes a flaw in the new version which fails to escape single quotes diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 3d9718aa..5e79fa81 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -31,6 +31,9 @@ class Catalog { var $sort_pattern; var $catalog_type; + /* This is a private var that's used during catalog builds */ + var $_playlists = array(); + // Used in functions var $albums = array(); var $artists = array(); @@ -336,10 +339,7 @@ class Catalog { if (is_readable($full_file)) { if (substr($file,-3,3) == 'm3u') { - if ($this->import_m3u($full_file)) { - echo " " . _("Added Playlist From") . " $file . . . .<br />\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 . . . .<br />\n"; + flush(); + } // end if import worked + } // end foreach playlist files + /* Now Adding Album Art? */ if ($gather_art) { echo "<br />\n<b>" . _("Starting Album Art Search") . ". . .</b><br />\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 . . . .<br />\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 ?> |