diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-06-02 07:48:31 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-06-02 07:48:31 +0000 |
commit | 201cf8600085634666ae748b6bd4ac259115c94a (patch) | |
tree | ac7396fe636521449340dcdfae36c5c5c5011484 /lib | |
parent | dad4a95101543eb8576f7fb5a4c2596369e9a9f5 (diff) | |
download | ampache-201cf8600085634666ae748b6bd4ac259115c94a.tar.gz ampache-201cf8600085634666ae748b6bd4ac259115c94a.tar.bz2 ampache-201cf8600085634666ae748b6bd4ac259115c94a.zip |
catalog verify mostly works, need to clean up the album art gather before its completely better
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/album.class.php | 17 | ||||
-rw-r--r-- | lib/class/catalog.class.php | 253 | ||||
-rw-r--r-- | lib/class/song.class.php | 300 |
3 files changed, 259 insertions, 311 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php index be967ded..ec1e819b 100644 --- a/lib/class/album.class.php +++ b/lib/class/album.class.php @@ -338,7 +338,7 @@ class Album { $data = array(); /* See if we are looking for a specific filename */ - $preferred_filename = conf('album_art_preferred_filename'); + $preferred_filename = Config::get('album_art_preferred_filename'); // Init a horrible hack array of lameness $cache =array(); @@ -354,11 +354,10 @@ class Album { $handle = @opendir($dir); if (!is_resource($handle)) { - echo "<font class=\"error\">" . _("Error: Unable to open") . " $dir</font><br />\n"; + Error::add('general',_('Error: Unable to open') . ' ' . $dir); debug_event('read',"Error: Unable to open $dir for album art read",'2'); } - /* Recurse through this dir and create the files array */ while ( FALSE !== ($file = @readdir($handle)) ) { $extension = substr($file,strlen($file)-3,4); @@ -397,7 +396,7 @@ class Album { return $data; - } // get_folder_art() + } // get_folder_art /** * get_resized_db_art @@ -462,7 +461,7 @@ class Album { $amazon_base_urls = array(); /* Attempt to retrive the album art order */ - $config_value = conf('amazon_base_urls'); + $config_value = Config::get('amazon_base_urls'); /* If it's not set */ if (empty($config_value)) { @@ -472,18 +471,18 @@ class Album { array_push($amazon_base_urls,$config_value); } else { - $amazon_base_urls = array_merge($amazon_base_urls, conf('amazon_base_urls')); + $amazon_base_urls = array_merge($amazon_base_urls, Config::get('amazon_base_urls')); } /* Foreach through the base urls that we should check */ foreach ($amazon_base_urls AS $amazon_base) { // Create the Search Object - $amazon = new AmazonSearch(conf('amazon_developer_key'), $amazon_base); + $amazon = new AmazonSearch(Config::get('amazon_developer_key'), $amazon_base); $search_results = array(); /* Setup the needed variables */ - $max_pages_to_search = max(conf('max_amazon_results_pages'),$amazon->_default_results_pages); + $max_pages_to_search = max(Config::get('max_amazon_results_pages'),$amazon->_default_results_pages); $pages_to_search = $max_pages_to_search; //init to max until we know better. // while we have pages to search @@ -521,7 +520,7 @@ class Album { } /* Log this if we're doin debug */ - debug_event('amazon-xml',"Searched using $keywords with " . conf('amazon_developer_key') . " as key " . count($final_results) . " results found",'5'); + debug_event('amazon-xml',"Searched using $keywords with " . Config::get('amazon_developer_key') . " as key " . count($final_results) . " results found",'5'); // If we've hit our limit if (!empty($limit) && count($final_results) >= $limit) { diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 570fe272..39a2c77b 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -102,7 +102,7 @@ class Catalog { * get_catalog_ids * This returns an array of all catalog ids */ - function get_catalog_ids() { + public static function get_catalog_ids() { $sql = "SELECT `id` FROM `catalog`"; $db_results = Dba::qery($sql); @@ -914,11 +914,12 @@ class Catalog { } // update_single_item - /*! - @function update_song_from_tags - @discussion updates the song info based on tags - */ - function update_song_from_tags($song) { + /** + * update_song_from_tags + * updates the song info based on tags, this is called from a bunch of different places + * and passes in a full fledged song object, so it's a static function + */ + public function update_song_from_tags($song) { /* Record the reading of these tags */ debug_event('tag-read',"Reading Tags from $song->file",'5','ampache-catalog'); @@ -955,18 +956,18 @@ class Catalog { * We have the artist/genre/album name need to check it in the tables * If found then add & return id, else return id */ - $new_song->artist = $this->check_artist($artist); + $new_song->artist = self::check_artist($artist); $new_song->f_artist = $artist; - $new_song->genre = $this->check_genre($genre); + $new_song->genre = self::check_genre($genre); $new_song->f_genre = $new_song->get_genre_name(); - $new_song->album = $this->check_album($album,$new_song->year); + $new_song->album = self::check_album($album,$new_song->year); $new_song->f_album = $album . " - " . $new_song->year; - $new_song->title = $this->check_title($new_song->title,$new_song->file); + $new_song->title = self::check_title($new_song->title,$new_song->file); /* Since we're doing a full compare make sure we fill the extended information */ $song->fill_ext_info(); - $info = $song->compare_song_information($song,$new_song); + $info = Song::compare_song_information($song,$new_song); if ($info['change']) { debug_event('update',"$song->file difference found, updating database",'5','ampache-catalog'); @@ -1221,12 +1222,7 @@ class Catalog { } // foreach new Songs // now delete invalid entries - $this->clean_albums(); - $this->clean_artists(); - $this->clean_genres(); - $this->clean_flagged(); - $this->clean_stats(); - $this->clean_ext_info(); + self::clean($this->id); } // update_remote_catalog @@ -1305,13 +1301,7 @@ class Catalog { * This finds artists and albums that no * longer have any songs associated with them */ - $this->clean_albums(); - $this->clean_artists(); - $this->clean_playlists(); - $this->clean_flagged(); - $this->clean_genres(); - $this->clean_stats(); - $this->clean_ext_info(); + self::clean($catalog_id); /* Return dead files, so they can be listed */ if ($verbose) { @@ -1377,71 +1367,64 @@ class Catalog { /** * clean_genres * This functions cleans up unused genres - * @package Catalog - * @catagory Clean */ - function clean_genres() { + public static function clean_genres() { /* Do a complex delete to get albums where there are no songs */ $sql = "DELETE FROM genre USING genre LEFT JOIN song ON song.genre = genre.id WHERE song.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); } // clean_genres - - /*! - @function clean_albums - @discussion This function cleans out unused albums - @param $this->id Depends on the current object - */ - function clean_albums() { + /** + * clean_albums + *This function cleans out unused albums + */ + public static function clean_albums() { /* Do a complex delete to get albums where there are no songs */ $sql = "DELETE FROM album USING album LEFT JOIN song ON song.album = album.id WHERE song.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); - } //clean_albums + } // clean_albums - /*! - @function clean_flagged - @discussion This functions cleans ou unused flagged items - */ - function clean_flagged() { + /** + * clean_flagged + * This functions cleans ou unused flagged items + */ + public static function clean_flagged() { /* Do a complex delete to get flagged items where the songs are now gone */ $sql = "DELETE FROM flagged USING flagged LEFT JOIN song ON song.id = flagged.object_id WHERE song.id IS NULL AND object_type='song'"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); } // clean_flagged - - /*! - @function clean_artists - @discussion This function cleans out unused artists - @param $this->id Depends on the current object - */ - function clean_artists() { + /** + * clean_artists + * This function cleans out unused artists + */ + public static function clean_artists() { /* Do a complex delete to get artists where there are no songs */ $sql = "DELETE FROM artist USING artist LEFT JOIN song ON song.artist = artist.id WHERE song.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); } //clean_artists - /* - @function clean_playlists - @discussion cleans out dead files from playlists - @param $this->id depends on the current object - */ - function clean_playlists() { + /** + * clean_playlists + * cleans out dead files from playlists + */ + public static function clean_playlists($catalog_id) { /* Do a complex delete to get playlist songs where there are no songs */ $sql = "DELETE FROM playlist_data USING playlist_data LEFT JOIN song ON song.id = playlist_data.song WHERE song.file IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Clear TMP Playlist information as well $sql = "DELETE FROM tmp_playlist_data USING tmp_playlist_data LEFT JOIN song ON tmp_playlist_data.object_id = song.id WHERE song.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); } // clean_playlists @@ -1449,58 +1432,54 @@ class Catalog { * clean_ext_info * This function clears any ext_info that no longer has a parent */ - function clean_ext_info() { + public static function clean_ext_info($catalog_id) { - // No longer accounting for MySQL 3.23 here, so just run the query $sql = "DELETE FROM song_ext_data USING song_ext_data LEFT JOIN song ON song.id = song_ext_data.song_id WHERE song.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); } // clean_ext_info - /*! - @function clean_stats - @discussion This functions removes stats for songs/albums that no longer exist - @param $catalog_id The ID of the catalog to clean - */ - function clean_stats() { - - $version = mysql_get_server_info(); + /** + * clean_stats + * This functions removes stats for songs/albums that no longer exist + */ + public static function clean_stats($catalog_id) { // Crazy SQL Mojo to remove stats where there are no songs $sql = "DELETE FROM object_count USING object_count LEFT JOIN song ON song.id=object_count.object_id WHERE object_type='song' AND song.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Crazy SQL Mojo to remove stats where there are no albums $sql = "DELETE FROM object_count USING object_count LEFT JOIN album ON album.id=object_count.object_id WHERE object_type='album' AND album.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Crazy SQL Mojo to remove stats where ther are no artists $sql = "DELETE FROM object_count USING object_count LEFT JOIN artist ON artist.id=object_count.object_id WHERE object_type='artist' AND artist.id IS NULL"; - $db_results = mysql_query($sql, dbh()); + $db_results = Dba::query($sql); // Delete genre stat information $sql = "DELETE FROM object_count USING object_count LEFT JOIN genre ON genre.id=object_count.object_id WHERE object_type='genre' AND genre.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Delete the live_stream stat information $sql = "DELETE FROM object_count USING object_count LEFT JOIN live_stream ON live_stream.id=object_count.object_id WHERE object_type='live_stream' AND live_stream.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Delete Song Ratings information $sql = "DELETE FROM ratings USING ratings LEFT JOIN song ON song.id=ratings.object_id WHERE object_type='song' AND song.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Delete Genre Ratings Information $sql = "DELETE FROM ratings USING ratings LEFT JOIN genre ON genre.id=ratings.object_id WHERE object_type='genre' AND genre.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Delete Album Rating Information $sql = "DELETE FROM ratings USING ratings LEFT JOIN album ON album.id=ratings.object_id WHERE object_type='album' AND album.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); // Delete Artist Rating Information $sql = "DELETE FROM ratings USING ratings LEFT JOIN artist ON artist.id=ratings.object_id WHERE object_type='artist' AND artist.id IS NULL"; - $db_results = mysql_query($sql,dbh()); + $db_results = Dba::query($sql); } // clean_stats @@ -1508,25 +1487,17 @@ class Catalog { * verify_catalog * This function compares the DB's information with the ID3 tags */ - public static function verify_catalog($catalog_id) { + public function verify_catalog($catalog_id) { + + // Create the object so we have some information on it + $catalog = new Catalog($catalog_id); /* First get the filenames for the catalog */ $sql = "SELECT `id` FROM `song` WHERE `catalog`='$catalog_id'"; $db_results = Dba::query($sql); $number = Dba::num_rows($db_results); - $refresh_limit = 10; - $ajax_url = Config::get('ajax_url') . '?action=catalog&type=add_files'; - /* Can't have the & stuff in the Javascript */ - $ajax_url = str_replace("&","&",$ajax_url); - require_once Config::get('prefix') . '/templates/javascript_refresh.inc.php'; - - show_box_top(); - echo _("Updating the") . " <b>[ $this->name ]</b> " . _("Catalog") . "<br />\n"; - echo $number . " " . _("songs found checking tag information.") . "<br />\n\n"; require_once Config::get('prefix') . '/templates/show_verify_catalog.inc.php'; - echo "<script type=\"text/javascript\">doLoad();</script>"; - show_box_bottom(); flush(); /* Magical Fix so we don't run out of time */ @@ -1558,11 +1529,9 @@ class Catalog { $info = $this->update_song_from_tags($song); $album_id = $song->album; if ($info['change']) { - echo "<dl style=\"list-style-type:none;\">\n\t<li>"; - echo "<b>$song->file " . _('Updated') . "</b>\n"; - echo $info['text']; - $album = new Album($song->album); + $update_string .= $info['text'] . "<br />\n"; + $album = new Album($song->album); if (!$album->has_art) { $found = $album->find_art($options,1); if (count($found)) { @@ -1570,13 +1539,9 @@ class Catalog { $album->insert_art($image,$found['mime']); $is_found = _(' FOUND'); } - echo "<br /><b>" . _('Searching for new Album Art') . ". . .$is_found</b><br />\n"; + $update_string .= "<b>" . _('Searching for new Album Art') . ". . .$is_found</b><br />\n"; unset($found,$is_found); } - else { - echo "<br /><b>" . _('Album Art Already Found') . ". . .</b><br />\n"; - } - echo "\t</li>\n</dl>\n<hr align=\"left\" width=\"50%\" />\n"; flush(); $total_updated++; } @@ -1590,10 +1555,11 @@ class Catalog { } /* Stupid little cutesie thing */ - $this->count++; - if (!($this->count%conf('catalog_echo_count')) ) { + $count++; + if (!($count%10) ) { echo "<script type=\"text/javascript\">"; - echo "update_txt('" . $this->count . "','count_verify_" . $this->id . "');"; + echo "update_txt('" . $count . "','verify_count_" . $catalog_id . "');"; + echo "update_txt('" . htmlentities($song->file) . "','verify_dir_" . $catalog_id . "');"; echo "</script>\n"; flush(); } //echos song count @@ -1601,40 +1567,46 @@ class Catalog { } // end if file exists else { - echo "<dl>\n <li>"; - echo "<b>$song->file does not exist or is not readable</b>\n"; - echo "</li>\n</dl>\n<hr align=\"left\" width=\"50%\" />\n"; - + Error::add('general',"$song->file does not exist or is not readable"); debug_event('read-error',"$song->file does not exist or is not readable",'5','ampache-catalog'); } } //end foreach /* After we have updated all the songs with the new information clear any empty albums/artists */ - $this->clean_albums(); - $this->clean_artists(); - $this->clean_genres(); - $this->clean_flagged(); - $this->clean_stats(); - $this->clean_ext_info(); + self::clean($catalog_id); // Update the last_update - $this->update_last_update(); + self::update_last_update($catalog_id); - if ($verbose) { - echo "<script type=\"text/javascript\">"; - echo "update_txt('" . $this->count . "','count_verify_" . $this->id . "');"; - echo "</script>\n"; - flush(); - } - - echo _('Update Finished.') . _('Checked') . " $this->count. $total_updated " . _('songs updated.') . "<br /><br />"; + // One final time! + echo "<script type=\"text/javascript\">"; + echo "update_txt('" . $this->count . "','count_verify_" . $this->id . "');"; + echo "</script>\n"; + flush(); - $this->count = 0; + echo _('Update Finished.') . _('Checked') . " $count. $total_updated " . _('songs updated.') . "<br /><br />"; return true; - } //verify_catalog + } // verify_catalog + + /** + * clean + * This is a wrapper function for all of the different cleaning + * functions, it runs them in the correct order and takes a catalog_id + */ + public static function clean($catalog_id) { + + self::clean_albums($catalog_id); + self::clean_artists($catalog_id); + self::clean_genres($catalog_id); + self::clean_flagged($catalog_id); + self::clean_stats($catalog_id); + self::clean_ext_info($catalog_id); + self::clean_playlists($catalog_id); + + } // clean /** * check_artist @@ -2099,32 +2071,25 @@ class Catalog { } // merge_stats - /*! - @function delete_catalog - @discussion Deletes the catalog and everything assoicated with it - assumes $this - */ - function delete_catalog() { + /** + * delete + * Deletes the catalog and everything assoicated with it + * assumes $this + */ + public static function delete() { // First remove the songs in this catalog - $sql = "DELETE FROM song WHERE catalog = '$this->id'"; - $db_results = mysql_query($sql, dbh()); + $sql = "DELETE FROM `song` WHERE `catalog` = '$this->id'"; + $db_results = Dba::query($sql); // Next Remove the Catalog Entry it's self - $sql = "DELETE FROM catalog WHERE id = '$this->id'"; - $db_results = mysql_query($sql, dbh()); + $sql = "DELETE FROM `catalog` WHERE `id` = '$this->id'"; + $db_results = Dba::query($sql); // Run the Aritst/Album Cleaners... - $this->clean_albums(); - $this->clean_artists(); - $this->clean_playlists(); - $this->clean_genres(); - $this->clean_flagged(); - $this->clean_stats(); - $this->clean_ext_info(); - - } // delete_catalog + self::clean($this->id); + } // delete /*! @function remove_songs @@ -2180,6 +2145,6 @@ class Catalog { } // export -} //end of catalog class +} // end of catalog class ?> diff --git a/lib/class/song.class.php b/lib/class/song.class.php index ddfe4275..095198d6 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -1,7 +1,7 @@ <?php /* - Copyright (c) 2001 - 2006 Ampache.org + Copyright (c) 2001 - 2007 Ampache.org All rights reserved. This program is free software; you can redistribute it and/or @@ -20,10 +20,6 @@ */ -/*! - @header Song Class -*/ - class Song { /* Variables from DB */ @@ -100,12 +96,12 @@ class Song { * This function gathers information from the song_ext_info table and adds it to the * current object */ - function _get_ext_info() { + public function _get_ext_info() { - $sql = "SELECT comment,lyrics FROM song_ext_data WHERE song_id='" . sql_escape($this->id) . "'"; - $db_results = mysql_query($sql,dbh()); + $sql = "SELECT * FROM song_data WHERE `song_id`='" . Dba::escape($this->id) . "'"; + $db_results = Dba::query($sql); - $results = mysql_fetch_assoc($db_results); + $results = Dba::fetch_assoc($db_results); return $results; @@ -115,14 +111,15 @@ class Song { * fill_ext_info * This calls the _get_ext_info and then sets the correct vars */ - function fill_ext_info() { + public function fill_ext_info() { $info = $this->_get_ext_info(); - $this->comment = $info['comment']; - $this->lyrics = $info['lyrics']; - - return true; + foreach ($info as $key=>$value) { + if ($key != 'song_id') { + $this->$key = $value; + } + } // end foreach } // fill_ext_info @@ -289,12 +286,12 @@ class Song { * This just returns true or false depending on if this song is flagged for something * We don't care what so we limit the SELECT to 1 */ - function has_flag() { + public function has_flag() { - $sql = "SELECT id FROM flagged WHERE object_type='song' AND object_id='$this->id' LIMIT 1"; - $db_results = mysql_query($sql, dbh()); + $sql = "SELECT `id` FROM `flagged` WHERE `object_type`='song' AND `object_id`='$this->id' LIMIT 1"; + $db_results = Dba::query($sql); - if (mysql_fetch_assoc($db_results)) { + if (Dba::fetch_assoc($db_results)) { return true; } @@ -322,19 +319,16 @@ class Song { } // set_played - /*! - @function compare_song_information - @discussion this compares the new ID3 tags of a file against - the ones in the database to see if they have changed - it returns false if nothing has changes, or the true - if they have. - @param $song The origional song object - @param $new_song The new version of the song - */ - function compare_song_information($song,$new_song) { + /** + * compare_song_information + * this compares the new ID3 tags of a file against + * the ones in the database to see if they have changed + * it returns false if nothing has changes, or the true + * if they have. Static because it doesn't need this + */ + public static function compare_song_information($song,$new_song) { if ($song->title == "No Title Found") { $song->title = false; } - if (trim($song->title) != trim(stripslashes($new_song->title)) && strlen($new_song->title) > 0) { $array['change'] = true; @@ -392,41 +386,39 @@ class Song { } // compare_song_information - /*! - @function update_song - @discussion this is the main updater for a song it actually - calls a whole bunch of mini functions to update - each little part of the song... lastly it updates - the "update_time" of the song - @param $song_id The id of the song we are updating - @param $new_song A object with the new song params - */ - function update_song($song_id, $new_song) { - - $this->update_title($new_song->title,$song_id); - $this->update_bitrate($new_song->bitrate,$song_id); - $this->update_rate($new_song->rate,$song_id); - $this->update_mode($new_song->mode,$song_id); - $this->update_size($new_song->size,$song_id); - $this->update_time($new_song->time,$song_id); - $this->update_track($new_song->track,$song_id); - $this->update_artist($new_song->artist,$song_id); - $this->update_genre($new_song->genre,$song_id); - $this->update_album($new_song->album,$song_id); - $this->update_year($new_song->year,$song_id); - $this->update_comment($new_song->comment,$song_id); - $this->update_played(0,$song_id); - $this->update_utime($song_id); + /** + * update + * this is the main updater for a song it actually + * calls a whole bunch of mini functions to update + * each little part of the song... lastly it updates + * the "update_time" of the song + */ + public static function update_song($song_id, $new_song) { + + self::update_title($new_song->title,$song_id); + self::update_bitrate($new_song->bitrate,$song_id); + self::update_rate($new_song->rate,$song_id); + self::update_mode($new_song->mode,$song_id); + self::update_size($new_song->size,$song_id); + self::update_time($new_song->time,$song_id); + self::update_track($new_song->track,$song_id); + self::update_artist($new_song->artist,$song_id); + self::update_genre($new_song->genre,$song_id); + self::update_album($new_song->album,$song_id); + self::update_year($new_song->year,$song_id); + self::update_comment($new_song->comment,$song_id); + self::update_played(0,$song_id); + self::update_utime($song_id); } // update_song - /*! - @function update_year - @discussion update the year tag - */ - function update_year($new_year,$song_id=0) { + /** + * update_year + * update the year tag + */ + public function update_year($new_year,$song_id) { - $this->_update_item('year',$new_year,$song_id,'100'); + self::_update_item('year',$new_year,$song_id,'100'); } // update_year @@ -434,9 +426,9 @@ class Song { * update_comment * updates the comment field */ - function update_comment($new_comment,$song_id=0) { + public function update_comment($new_comment,$song_id) { - $this->_update_ext_item('comment',$new_comment,$song_id,'100'); + self::_update_ext_item('comment',$new_comment,$song_id,'100'); } // update_comment @@ -444,142 +436,141 @@ class Song { * update_lyrics * updates the lyrics field */ - function update_lyrics($new_lyrics,$song_id=0) { + public function update_lyrics($new_lyrics,$song_id) { - $this->_update_ext_item('lyrics',$new_lyrics,$song_id,'100'); + self::_update_ext_item('lyrics',$new_lyrics,$song_id,'100'); } // update_lyrics - /*! - @function update_title - @discussion updates the title field - */ - function update_title($new_title,$song_id=0) { + /** + * update_title + * updates the title field + */ + public function update_title($new_title,$song_id) { - $this->_update_item('title',$new_title,$song_id,'100'); + self::_update_item('title',$new_title,$song_id,'100'); } // update_title - /*! - @function update_bitrate - @discussion updates the bitrate field - */ - function update_bitrate($new_bitrate,$song_id=0) { + /** + * update_bitrate + * updates the bitrate field + */ + public function update_bitrate($new_bitrate,$song_id) { - $this->_update_item('bitrate',$new_bitrate,$song_id,'100'); + self::_update_item('bitrate',$new_bitrate,$song_id,'100'); } // update_bitrate - /*! - @function update_rate - @discussion updates the rate field - */ - function update_rate($new_rate,$song_id=0) { + /** + * update_rate + * updates the rate field + */ + public function update_rate($new_rate,$song_id) { - $this->_update_item('rate',$new_rate,$song_id,'100'); + self::_update_item('rate',$new_rate,$song_id,'100'); } // update_rate - /*! - @function update_mode - @discussion updates the mode field - */ - function update_mode($new_mode,$song_id=0) { + /** + * update_mode + * updates the mode field + */ + public function update_mode($new_mode,$song_id) { - $this->_update_item('mode',$new_mode,$song_id,'100'); + self::_update_item('mode',$new_mode,$song_id,'100'); } // update_mode - /*! - @function update_size - @discussion updates the size field - */ - function update_size($new_size,$song_id=0) { + /** + * update_size + * updates the size field + */ + public function update_size($new_size,$song_id) { - $this->_update_item('size',$new_size,$song_id,'100'); + self::_update_item('size',$new_size,$song_id,'100'); } // update_size - /*! - @function update_time - @discussion updates the time field - */ - function update_time($new_time,$song_id=0) { + /** + * update_time + * updates the time field + */ + public function update_time($new_time,$song_id) { - $this->_update_item('time',$new_time,$song_id,'100'); + self::_update_item('time',$new_time,$song_id,'100'); } // update_time - /*! - @function update_track - @discussion this updates the track field - */ - function update_track($new_track,$song_id=0) { + /** + * update_track + * this updates the track field + */ + public function update_track($new_track,$song_id) { - $this->_update_item('track',$new_track,$song_id,'100'); + self::_update_item('track',$new_track,$song_id,'100'); } // update_track - /*! - @function update_artist - @discussion updates the artist field - */ - function update_artist($new_artist,$song_id=0) { + /** + * update_artist + * updates the artist field + */ + public function update_artist($new_artist,$song_id) { - $this->_update_item('artist',$new_artist,$song_id,'100'); + self::_update_item('artist',$new_artist,$song_id,'100'); } // update_artist - /*! - @function update_genre - @discussion updates the genre field - */ - function update_genre($new_genre,$song_id=0) { + /** + * update_genre + * updates the genre field + */ + public function update_genre($new_genre,$song_id) { - $this->_update_item('genre',$new_genre,$song_id,'100'); + self::_update_item('genre',$new_genre,$song_id,'100'); } // update_genre - /*! - @function update_album - @discussion updates the album field - */ - function update_album($new_album,$song_id=0) { + /** + * update_album + * updates the album field + */ + public function update_album($new_album,$song_id) { - $this->_update_item('album',$new_album,$song_id,'100'); + self::_update_item('album',$new_album,$song_id,'100'); } // update_album - /*! - @function update_utime - @discussion sets a new update time - */ - function update_utime($song_id=0,$time=0) { + /** + * update_utime + * sets a new update time + */ + public function update_utime($song_id,$time=0) { if (!$time) { $time = time(); } - $this->_update_item('update_time',$time,$song_id,'100'); + self::_update_item('update_time',$time,$song_id,'100'); } // update_utime - /*! - @function update_played - @discussion sets the played flag - */ - function update_played($new_played,$song_id=0) { + /** + * update_played + * sets the played flag + */ + public function update_played($new_played,$song_id) { - $this->_update_item('played',$new_played,$song_id,'25'); + self::_update_item('played',$new_played,$song_id,'25'); } // update_played - - /*! - @function update_enabled - @discussion sets the enabled flag - */ - function update_enabled($new_enabled,$song_id=0) { + /** + * update_enabled + * sets the enabled flag + */ + public function update_enabled($new_enabled,$song_id) { - $this->_update_item('enabled',$new_enabled,$song_id,'100'); + self::_update_item('enabled',$new_enabled,$song_id,'100'); } // update_enabled @@ -590,21 +581,18 @@ class Song { * against $GLOBALS['user'] to make sure they are allowed to update this record * it then updates it and sets $this->{$field} to the new value */ - function _update_item($field,$value,$song_id=0,$level) { + private static function _update_item($field,$value,$song_id,$level) { /* Check them Rights! */ if (!$GLOBALS['user']->has_access($level)) { return false; } - if (!$song_id) { $song_id = $this->id; } - /* Can't update to blank */ if (!strlen(trim($value)) && $field != 'comment') { return false; } - $value = sql_escape($value); + $value = Dba::escape($value); - $sql = "UPDATE song SET $field='$value' WHERE id='$song_id'"; - $db_results = mysql_query($sql, dbh()); - $this->{$field} = $value; + $sql = "UPDATE `song` SET `$field`='$value' WHERE `id`='$song_id'"; + $db_results = Dba::query($sql); return true; @@ -615,19 +603,15 @@ class Song { * This updates a song record that is housed in the song_ext_info table * These are items that aren't used normally, and often large/informational only */ - function _update_ext_item($field,$value,$song_id,$level) { + private static function _update_ext_item($field,$value,$song_id,$level) { /* Check them rights boy! */ if (!$GLOBALS['user']->has_access($level)) { return false; } - if (!$song_id) { $song_id = $this->id; } - - $value = sql_escape($value); - - $sql = "UPDATE song_ext_data SET `$field`='$value' WHERE song_id='$song_id'"; - $db_results = mysql_query($sql,dbh()); + $value = Dba::escape($value); - $this->{$field} = $value; + $sql = "UPDATE `song_data` SET `$field`='$value' WHERE `song_id`='$song_id'"; + $db_results = Dba::query($sql); return true; |