From 37a348127fc68a8e3e8858873bc4df47d40a1760 Mon Sep 17 00:00:00 2001 From: Karl 'vollmerk' Vollmer Date: Sun, 8 Mar 2009 13:28:43 +0000 Subject: fixed catalog functions and corrected negative value caching --- docs/CHANGELOG | 3 +++ lib/class/catalog.class.php | 14 ++++++++------ lib/class/database_object.abstract.php | 10 +++++----- lib/class/flag.class.php | 13 +++++++++---- lib/class/song.class.php | 8 ++++---- lib/class/tag.class.php | 10 ++++++---- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/docs/CHANGELOG b/docs/CHANGELOG index a6a7dfff..e0801714 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,9 @@ -------------------------------------------------------------------------- v.3-5-Alpha2 + - Fixed caching of objects with no return value + - Fixed updating of songs that should not be updated during catalog + verify - Added default_user_level config option that allows you to define the user level when use_auth is false. Also allows manual login of admin users when use_auth is false. diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 59f93d64..0a48efea 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1057,7 +1057,6 @@ class Catalog extends database_object { $rename_pattern = $catalog->rename_pattern; } - debug_event('tag-read','Reading tags from ' . $media->file,'5','ampache-catalog'); $vainfo = new vainfo($media->file,'','','',$sort_pattern,$rename_pattern); @@ -1113,7 +1112,7 @@ class Catalog extends database_object { $new_song->size = $results['size']; $new_song->time = $results['time']; $new_song->mime = $results['mime']; - $new_song->track = $results['track']; + $new_song->track = intval($results['track']); $artist = $results['artist']; $album = $results['album']; $disk = $results['disk']; @@ -1142,7 +1141,7 @@ class Catalog extends database_object { if ($info['change']) { debug_event('update',"$song->file difference found, updating database",'5','ampache-catalog'); $song->update_song($song->id,$new_song); - // Redfine our reference + // Refine our reference $song = $new_song; } else { @@ -1755,15 +1754,20 @@ class Catalog extends database_object { $songs = array(); /* First get the filenames for the catalog */ - $sql = "SELECT `id`,`file`,'song' AS `type` FROM `song` WHERE `song`.`catalog`='$catalog_id' "; + $sql = "SELECT `id`,`file`,`artist`,`album`,'song' AS `type` FROM `song` WHERE `song`.`catalog`='$catalog_id' "; $db_results = Dba::read($sql); while ($row = Dba::fetch_assoc($db_results)) { $cache[] = $row['id']; + $artists[] = $row['artist']; + $albums[] = $row['album']; $songs[] = $row; } Song::build_cache($cache); Flag::build_map_cache($cache,'song'); + Tag::build_map_cache('album',$albums); + Tag::build_map_cache('artist',$artists); + Tag::build_map_cache('song',$cache); $cache = array(); $videos = array(); @@ -1801,7 +1805,6 @@ class Catalog extends database_object { if (is_readable($results['file'])) { - /* Create the object from the existing database information */ $media = new $type($results['id']); @@ -1999,7 +2002,6 @@ class Catalog extends database_object { // Remove the prefix so we can sort it correctly $prefix_pattern = '/^(' . implode('\\s|',explode('|',Config::get('catalog_prefix_pattern'))) . '\\s)(.*)/i'; - debug_event('prefix',$prefix_pattern,'5'); preg_match($prefix_pattern,$album,$matches); if (count($matches)) { diff --git a/lib/class/database_object.abstract.php b/lib/class/database_object.abstract.php index ed83d198..e26b22df 100644 --- a/lib/class/database_object.abstract.php +++ b/lib/class/database_object.abstract.php @@ -63,7 +63,7 @@ abstract class database_object { public static function is_cached($index,$id) { // Make sure we've got some parents here before we dive below - if (!isset(self::$object_cache) || !isset(self::$object_cache[$index])) { return false; } + if (!isset(self::$object_cache[$index])) { return false; } return isset(self::$object_cache[$index][$id]); @@ -76,8 +76,7 @@ abstract class database_object { public static function get_from_cache($index,$id) { // Check if the object is set - if (isset(self::$object_cache) - && isset(self::$object_cache[$index]) + if (isset(self::$object_cache[$index]) && isset(self::$object_cache[$index][$id]) ) { @@ -95,8 +94,9 @@ abstract class database_object { */ public static function add_to_cache($index,$id,$data) { - self::$object_cache[$index][$id] = $data; - + $value = is_null($data) ? false : $data; + self::$object_cache[$index][$id] = $value; + } // add_to_cache } // end database_object diff --git a/lib/class/flag.class.php b/lib/class/flag.class.php index 148d5aa8..501f6415 100644 --- a/lib/class/flag.class.php +++ b/lib/class/flag.class.php @@ -90,11 +90,16 @@ class Flag extends database_object { $sql = "SELECT * FROM `flagged` " . "WHERE `flagged`.`object_type`='$type' AND `flagged`.`object_id` IN $idlist"; $db_results = Dba::read($sql); - + while ($row = Dba::fetch_assoc($db_results)) { - parent::add_to_cache('flagged_' . $type,$row['object_id'],$row); + $results[$row['object_id']] = $row; } - + + // Itterate through the passed ids as we need to cache 'nulls' + foreach ($ids as $id) { + parent::add_to_cache('flagged_' . $type,$id,$results[$id]); + } + return true; } // build_map_cache @@ -109,7 +114,7 @@ class Flag extends database_object { $data = parent::get_from_cache('flagged_' . $type,$id); return $data['date']; } - + // Ok we have to query this $type = Dba::escape($type); diff --git a/lib/class/song.class.php b/lib/class/song.class.php index 77584011..029d45a4 100644 --- a/lib/class/song.class.php +++ b/lib/class/song.class.php @@ -322,25 +322,25 @@ class Song extends database_object implements media { unset($song->catalog,$song->played,$song->enabled,$song->addition_time,$song->update_time,$song->type); $string_array = array('title','comment','lyrics'); + $skip_array = array('id','tag_id','mime'); // Pull out all the currently set vars $fields = get_object_vars($song); // Foreach them foreach ($fields as $key=>$value) { - if ($key == 'id') { continue; } + if (in_array($key,$skip_array)) { continue; } // If it's a stringie thing if (in_array($key,$string_array)) { if (trim(stripslashes($song->$key)) != trim(stripslashes($new_song->$key))) { $array['change'] = true; - $array['element'][$key] = 'OLD: ' . $song->$key . ' <---> ' . $new_song->$key; + $array['element'][$key] = 'OLD: ' . $song->$key . ' --> ' . $new_song->$key; } } // in array of stringies - else { if ($song->$key != $new_song->$key) { $array['change'] = true; - $array['element'][$key] = '' . $song->$key . ' <---> ' . $new_song->$key; + $array['element'][$key] = 'OLD:' . $song->$key . ' --> ' . $new_song->$key; } } // end else diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php index 05c5e47b..2bc829d7 100644 --- a/lib/class/tag.class.php +++ b/lib/class/tag.class.php @@ -155,7 +155,7 @@ class Tag extends database_object { $type = self::validate_type($type); $idlist = '(' . implode(',',$ids) . ')'; - $sql = "SELECT `tag_map`.`tag_id`,`tag_map`.`object_id`,`tag_map`.`user` FROM `tag_map` " . + $sql = "SELECT `tag_map`.`id`,`tag_map`.`tag_id`,`tag_map`.`object_id`,`tag_map`.`user` FROM `tag_map` " . "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist "; $db_results = Dba::query($sql); @@ -164,11 +164,13 @@ class Tag extends database_object { while ($row = Dba::fetch_assoc($db_results)) { $tags[$row['object_id']][$row['tag_id']]['users'][] = $row['user']; $tags[$row['object_id']][$row['tag_id']]['count']++; + $tag_map[$row['object_id']] = array('id'=>$row['id'],'tag_id'=>$row['tag_id'],'user'=>$row['user'],'object_type'=>$type,'object_id'=>$row['object_id']); } // Run through our origional ids as we want to cache NULL results foreach ($ids as $id) { parent::add_to_cache('tag_top_' . $type,$id,$tags[$id]); + parent::add_to_cache('tag_map_' . $type,$id,$tag_map[$id]); } return true; @@ -180,7 +182,7 @@ class Tag extends database_object { * This is a wrapper function, it figures out what we need to add, be it a tag * and map, or just the mapping */ - public static function add($type,$id,$value,$user='') { + public static function add($type,$id,$value,$user=false) { // Validate the tag type if (!self::validate_type($type)) { return false; } @@ -191,7 +193,7 @@ class Tag extends database_object { if (!strlen($cleaned_value)) { return false; } - $uid = ($user == '') ? intval($user) : intval($GLOBALS['user']->id); + $uid = ($user === false) ? intval($user) : intval($GLOBALS['user']->id); // Check and see if the tag exists, if not create it, we need the tag id from this if (!$tag_id = self::tag_exists($cleaned_value)) { @@ -289,7 +291,7 @@ class Tag extends database_object { public static function tag_map_exists($type,$object_id,$tag_id,$user) { if (!self::validate_type($type)) { return false; } - + if (parent::is_cached('tag_map_' . $type,$object_id)) { $data = parent::get_from_cache('tag_map_' . $type,$object_id); return $data['id']; -- cgit