diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-22 02:29:05 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2006-05-22 02:29:05 +0000 |
commit | d4b700e2fe1eeb47fbea7b61c295eba16f30c41c (patch) | |
tree | e4c7f478d0b20d0cf7823953c67ba238a08b7527 | |
parent | cebb21facc2e2219f1d498def8ee19bbb4b72f7e (diff) | |
download | ampache-d4b700e2fe1eeb47fbea7b61c295eba16f30c41c.tar.gz ampache-d4b700e2fe1eeb47fbea7b61c295eba16f30c41c.tar.bz2 ampache-d4b700e2fe1eeb47fbea7b61c295eba16f30c41c.zip |
added ability to prune empty playlists
-rw-r--r-- | bin/catalog_update.php.inc | 12 | ||||
-rwxr-xr-x | docs/CHANGELOG | 1 | ||||
-rw-r--r-- | lib/playlist.lib.php | 29 | ||||
-rw-r--r-- | modules/init.php | 2 | ||||
-rw-r--r-- | playlist.php | 13 | ||||
-rw-r--r-- | templates/show_playlist_box.inc.php | 3 |
6 files changed, 57 insertions, 3 deletions
diff --git a/bin/catalog_update.php.inc b/bin/catalog_update.php.inc index d03270b9..4ad80076 100644 --- a/bin/catalog_update.php.inc +++ b/bin/catalog_update.php.inc @@ -20,13 +20,21 @@ */ - $no_session='1'; require ("../modules/init.php"); echo "[catalog_update.php.inc]\nStarting Catalog Clean/Update And Add\n\n"; -$sql = "SELECT id FROM catalog WHERE catalog_type='local'"; +if (count($_SERVER['argv']) > 1) { + for ($x = 1; $x < count($_SERVER['argv']); $x++) { + if ($where) $where .= " OR "; + $where .= "name LIKE '%" . preg_replace("/[^a-z0-9\. -]/i", "", $_SERVER['argv'][$x]) . "%'"; + } +} +if ($where) $where = "($where) AND catalog_type='local'"; +else $where = "catalog_type='local'"; +$sql = "SELECT id FROM catalog"; +if ($where) $sql .= " WHERE $where"; $db_results = mysql_query($sql, dbh()); while ($r = mysql_fetch_row($db_results)) { diff --git a/docs/CHANGELOG b/docs/CHANGELOG index 480a7606..e90977d7 100755 --- a/docs/CHANGELOG +++ b/docs/CHANGELOG @@ -4,6 +4,7 @@ -------------------------------------------------------------------------- v.3.3.2-Beta3 + - Added pruning of empty playlists (Admin Only) - Fixed error on /login.php when theme isn't set which caused a fopen failure to show up in the logs - Improved MPD class to use PHP 4.3+ socket timeout settings so diff --git a/lib/playlist.lib.php b/lib/playlist.lib.php index 253912e0..567391db 100644 --- a/lib/playlist.lib.php +++ b/lib/playlist.lib.php @@ -135,4 +135,33 @@ function get_playlists($type) { } // get_playlists +/** + * prune_empty_playlists + * This function goes through and deletes any playlists which have + * no songs in them. This can only be done by a full admin + */ +function prune_empty_playlists() { + + + $sql = "SELECT playlist.id FROM playlist LEFT JOIN playlist_data ON playlist.id=playlist_data.playlist " . + "WHERE playlist_data.id IS NULL"; + $db_results = mysql_query($sql, dbh()); + + $results = array(); + + while ($r = mysql_fetch_assoc($db_results)) { + $results[] = $r['id']; + } + + /* Delete the Playlists */ + foreach ($results as $playlist_id) { + $playlist = new Playlist($playlist_id); + $playlist->delete(); + } + + return true; + +} // prune_empty_playlists + + ?> diff --git a/modules/init.php b/modules/init.php index 7bca6a29..8ea8f64d 100644 --- a/modules/init.php +++ b/modules/init.php @@ -80,7 +80,7 @@ if (!$results['allow_stream_playback']) { /** This is the version.... fluf nothing more... **/ -$results['version'] = '3.3.2-Beta3 (Build 006)'; +$results['version'] = '3.3.2-Beta3 (Build 007)'; $results['raw_web_path'] = $results['web_path']; $results['web_path'] = $http_type . $_SERVER['HTTP_HOST'] . $results['web_path']; diff --git a/playlist.php b/playlist.php index 98a6a9b8..44c40777 100644 --- a/playlist.php +++ b/playlist.php @@ -173,6 +173,19 @@ switch ($action) { show_playlist($playlist); break; + case 'prune_empty': + /* Make sure they have permission */ + if (!$GLOBALS['user']->has_access(100)) { + access_denied(); + break; + } + + prune_empty_playlists(); + $url = conf('web_path') . '/playlist.php'; + $title = _('Empty Playlists Deleted'); + $body = ''; + show_confirmation($title,$body,$url); + break; case 'normalize_tracks': /* Make sure they have permission */ if (!$playlist->has_access()) { diff --git a/templates/show_playlist_box.inc.php b/templates/show_playlist_box.inc.php index 168e76e2..e020f441 100644 --- a/templates/show_playlist_box.inc.php +++ b/templates/show_playlist_box.inc.php @@ -42,6 +42,9 @@ $playlist_id = scrub_out($_REQUEST['playlist_id']); <?php } else { ?> <li><a href="<?php echo $web_path; ?>/playlist.php?action=show_import_playlist"><?php echo _('Import From File'); ?></a></li> <li><a href="<?php echo $web_path; ?>/playlist.php?action=new"><?php echo _('Create New Playlist'); ?></a></li> + <?php if ($GLOBALS['user']->has_access(100)) { ?> + <li><a href="<?php echo $web_path; ?>/playlist.php?action=prune_empty"><?php echo _('Delete Empty Playlists'); ?></a</li> + <?php } ?> <?php } ?> </ul> </td> |