summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/class/album.class.php50
-rw-r--r--lib/class/artist.class.php36
-rw-r--r--lib/class/rating.class.php62
-rw-r--r--lib/class/song.class.php64
-rw-r--r--lib/class/tag.class.php51
-rw-r--r--lib/debug.lib.php4
-rw-r--r--lib/init.php2
7 files changed, 149 insertions, 120 deletions
diff --git a/lib/class/album.class.php b/lib/class/album.class.php
index 049331ff..780fa384 100644
--- a/lib/class/album.class.php
+++ b/lib/class/album.class.php
@@ -95,31 +95,37 @@ class Album extends database_object {
*/
public static function build_cache($ids,$extra=false) {
- $idlist = '(' . implode(',', $ids) . ')';
+ if ($ids) {
+ $idlist = '(' . implode(',', $ids) . ')';
- $sql = "SELECT * FROM `album` WHERE `id` IN $idlist";
- $db_results = Dba::query($sql);
+ $sql = "SELECT * FROM `album` WHERE `id` IN $idlist";
+ $db_results = Dba::query($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('album',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('album',$row['id'],$row);
+ }
- // If we're extra'ing cache the extra info as well
- if ($extra) {
- $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
- ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`".
- "FROM `song` " .
- "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
- "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
- "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`";
- $db_results = Dba::read($sql);
-
- while ($row = Dba::fetch_assoc($db_results)) {
- $row['has_art'] = make_bool($row['has_art']);
- $row['has_thumb'] = make_bool($row['has_thumb']);
- parent::add_to_cache('album_extra',$row['album'],$row);
- } // while rows
- } // if extra
+ // If we're extra'ing cache the extra info as well
+ if ($extra) {
+ $sql = "SELECT COUNT(DISTINCT(song.artist)) as artist_count,COUNT(song.id) AS song_count,artist.name AS artist_name" .
+ ",artist.prefix AS artist_prefix,album_data.art AS has_art,album_data.thumb AS has_thumb, artist.id AS artist_id,`song`.`album`".
+ "FROM `song` " .
+ "INNER JOIN `artist` ON `artist`.`id`=`song`.`artist` " .
+ "LEFT JOIN `album_data` ON `album_data`.`album_id` = `song`.`album` " .
+ "WHERE `song`.`album` IN $idlist GROUP BY `song`.`album`";
+ $db_results = Dba::read($sql);
+
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $row['has_art'] = make_bool($row['has_art']);
+ $row['has_thumb'] = make_bool($row['has_thumb']);
+ parent::add_to_cache('album_extra',$row['album'],$row);
+ } // while rows
+ } // if extra
+
+ return true;
+ } else {
+ return false;
+ }
} // build_cache
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php
index 1b72d7df..ae742ded 100644
--- a/lib/class/artist.class.php
+++ b/lib/class/artist.class.php
@@ -78,26 +78,32 @@ class Artist extends database_object {
* this attempts to build a cache of the data from the passed albums all in one query
*/
public static function build_cache($ids,$extra=false) {
- $idlist = '(' . implode(',', $ids) . ')';
+ if($ids) {
+ $idlist = '(' . implode(',', $ids) . ')';
- $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist";
- $db_results = Dba::query($sql);
+ $sql = "SELECT * FROM `artist` WHERE `id` IN $idlist";
+ $db_results = Dba::query($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('artist',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('artist',$row['id'],$row);
+ }
- // If we need to also pull the extra information, this is normally only used when we are doing the human display
- if ($extra) {
- $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
- "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";
- $db_results = Dba::query($sql);
+ // If we need to also pull the extra information, this is normally only used when we are doing the human display
+ if ($extra) {
+ $sql = "SELECT `song`.`artist`, COUNT(`song`.`id`) AS `song_count`, COUNT(DISTINCT `song`.`album`) AS `album_count`, SUM(`song`.`time`) AS `time` FROM `song` " .
+ "WHERE `song`.`artist` IN $idlist GROUP BY `song`.`artist`";
+ $db_results = Dba::query($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('artist_extra',$row['artist'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('artist_extra',$row['artist'],$row);
+ }
+
+ } // end if extra
- } // end if extra
+ return true;
+ } else {
+ return false;
+ }
} // build_cache
diff --git a/lib/class/rating.class.php b/lib/class/rating.class.php
index 5d2f9bf2..d1b34822 100644
--- a/lib/class/rating.class.php
+++ b/lib/class/rating.class.php
@@ -65,41 +65,45 @@ class Rating extends database_object {
*/
public static function build_cache($type, $ids) {
- $user_id = Dba::escape($GLOBALS['user']->id);
+ if ($ids) {
+ $user_id = Dba::escape($GLOBALS['user']->id);
- $idlist = '(' . implode(',', $ids) . ')';
- $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
- "AND `object_type`='$type'";
- $db_results = Dba::read($sql);
+ $idlist = '(' . implode(',', $ids) . ')';
+ $sql = "SELECT `rating`, `object_id`,`rating`.`rating` FROM `rating` WHERE `user`='$user_id' AND `object_id` IN $idlist " .
+ "AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $user[$row['object_id']] = $row['rating'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $user[$row['object_id']] = $row['rating'];
+ }
- $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `rating`,`object_id` FROM `rating` WHERE `object_id` IN $idlist AND `object_type`='$type'";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $rating[$row['object_id']]['rating'] += $row['rating'];
- $rating[$row['object_id']]['total']++;
- }
-
- foreach ($ids as $id) {
- parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
-
- // Do the bit of math required to store this
- if (!isset($rating[$id])) {
- $entry = array('average'=>'0','percise'=>'0');
- }
- else {
- $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
- $entry = array('average'=>floor($average),'percise'=>$average);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $rating[$row['object_id']]['rating'] += $row['rating'];
+ $rating[$row['object_id']]['total']++;
+ }
+
+ foreach ($ids as $id) {
+ parent::add_to_cache('rating_' . $type . '_user',$id,intval($user[$id]));
+
+ // Do the bit of math required to store this
+ if (!isset($rating[$id])) {
+ $entry = array('average'=>'0','percise'=>'0');
+ }
+ else {
+ $average = round($rating[$id]['rating']/$rating[$id]['total'],1);
+ $entry = array('average'=>floor($average),'percise'=>$average);
+ }
- parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
- }
+ parent::add_to_cache('rating_' . $type . '_all',$id,$entry);
+ }
- return true;
+ return true;
+ } else {
+ return false;
+ }
} // build_cache
diff --git a/lib/class/song.class.php b/lib/class/song.class.php
index b73ab1e8..b03c1123 100644
--- a/lib/class/song.class.php
+++ b/lib/class/song.class.php
@@ -78,42 +78,46 @@ class Song extends database_object {
*/
public static function build_cache($song_ids) {
- $idlist = '(' . implode(',', $song_ids) . ')';
+ if ($ids) {
+ $idlist = '(' . implode(',', $song_ids) . ')';
- // Song data cache
- $sql = "SELECT song.id,file,catalog,album,year,artist,".
- "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,".
- "addition_time FROM `song` " .
- "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " .
- "WHERE `song`.`id` IN $idlist";
- $db_results = Dba::read($sql);
+ // Song data cache
+ $sql = "SELECT song.id,file,catalog,album,year,artist,".
+ "title,bitrate,rate,mode,size,time,track,played,song.enabled,update_time,tag_map.tag_id,".
+ "addition_time FROM `song` " .
+ "LEFT JOIN `tag_map` ON `tag_map`.`object_id`=`song`.`id` AND `tag_map`.`object_type`='song' " .
+ "WHERE `song`.`id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('song',$row['id'],$row);
- $artists[$row['artist']] = $row['artist'];
- $albums[$row['album']] = $row['album'];
- $tags[$row['tag_id']] = $row['tag_id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('song',$row['id'],$row);
+ $artists[$row['artist']] = $row['artist'];
+ $albums[$row['album']] = $row['album'];
+ $tags[$row['tag_id']] = $row['tag_id'];
+ }
- Artist::build_cache($artists);
- Album::build_cache($albums);
- Tag::build_cache($tags);
- Tag::build_map_cache('song',$song_ids);
-
- // If we're rating this then cache them as well
- if (Config::get('ratings')) {
- Rating::build_cache('song',$song_ids);
- }
+ Artist::build_cache($artists);
+ Album::build_cache($albums);
+ Tag::build_cache($tags);
+ Tag::build_map_cache('song',$song_ids);
+
+ // If we're rating this then cache them as well
+ if (Config::get('ratings')) {
+ Rating::build_cache('song',$song_ids);
+ }
- // Build a cache for the song's extended table
- $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist";
- $db_results = Dba::read($sql);
+ // Build a cache for the song's extended table
+ $sql = "SELECT * FROM `song_data` WHERE `song_id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('song_data',$row['song_id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('song_data',$row['song_id'],$row);
+ }
- return true;
+ return true;
+ } else {
+ return false;
+ }
} // build_cache
diff --git a/lib/class/tag.class.php b/lib/class/tag.class.php
index 22f4ea4a..ff02041d 100644
--- a/lib/class/tag.class.php
+++ b/lib/class/tag.class.php
@@ -77,16 +77,20 @@ class Tag extends database_object {
*/
public static function build_cache($ids) {
- $idlist = '(' . implode(',',$ids) . ')';
+ if ($ids) {
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist";
- $db_results = Dba::query($sql);
+ $sql = "SELECT * FROM `tag` WHERE `id` IN $idlist";
+ $db_results = Dba::query($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('tag',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('tag',$row['id'],$row);
+ }
- return true;
+ return true;
+ } else {
+ return false;
+ }
} // build_cache
@@ -96,25 +100,28 @@ class Tag extends database_object {
*/
public static function build_map_cache($type,$ids) {
- $type = self::validate_type($type);
- $idlist = '(' . implode(',',$ids) . ')';
+ if ($ids) {
+ $type = self::validate_type($type);
+ $idlist = '(' . implode(',',$ids) . ')';
- $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " .
- "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
- "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " .
- "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC";
- $db_results = Dba::query($sql);
+ $sql = "SELECT COUNT(`tag_map`.`id`) AS `count`,`tag`.`id`,`tag_map`.`object_id` FROM `tag_map` " .
+ "INNER JOIN `tag` ON `tag`.`id`=`tag_map`.`tag_id` " .
+ "WHERE `tag_map`.`object_type`='$type' AND `tag_map`.`object_id` IN $idlist " .
+ "GROUP BY `tag_map`.`object_id` ORDER BY `count` DESC";
+ $db_results = Dba::query($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $tags[$row['object_id']][] = $row;
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $tags[$row['object_id']][] = $row;
+ }
-
- foreach ($tags as $id=>$entry) {
- parent::add_to_cache('tag_map_' . $type,$id,$entry);
- }
+ foreach ($tags as $id=>$entry) {
+ parent::add_to_cache('tag_map_' . $type,$id,$entry);
+ }
- return true;
+ return true;
+ } else {
+ return false;
+ }
} // build_map_cache
diff --git a/lib/debug.lib.php b/lib/debug.lib.php
index 3310f3bd..680446bf 100644
--- a/lib/debug.lib.php
+++ b/lib/debug.lib.php
@@ -193,9 +193,9 @@ function check_putenv() {
/* Check memory */
$current = ini_get('memory_limit');
$current = substr($current_memory,0,strlen($current_memory)-1);
- $new_limit = ($current+1) . "M";
+ $new_limit = ($current+16) . "M";
- /* Bump it by one meg */
+ /* Bump it by 16 megs (for getid3)*/
if (!ini_set(memory_limit,$new_limit)) {
return false;
}
diff --git a/lib/init.php b/lib/init.php
index e65c4c40..8bcf8a0f 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -267,5 +267,7 @@ $GLOBALS['xmlrpc_internalencoding'] = Config::get('site_charset');
// If don't use Debug, no error report
if (Config::get('debug') == 'false' || Config::get('debug') == NULL) {
error_reporting(0);
+} else {
+ error_reporting(E_ALL);
}
?>