diff options
author | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-17 00:54:55 +0000 |
---|---|---|
committer | Karl 'vollmerk' Vollmer <vollmer@ampache.org> | 2007-12-17 00:54:55 +0000 |
commit | a5d4acd8469d571c39f004431836f13d0ef1a5b6 (patch) | |
tree | 8b2a6f9b71e883333826b6837905a43b1533a234 /bin | |
parent | 81a854f7ea737ecdb05ebfb5d09209508f34b745 (diff) | |
download | ampache-a5d4acd8469d571c39f004431836f13d0ef1a5b6.tar.gz ampache-a5d4acd8469d571c39f004431836f13d0ef1a5b6.tar.bz2 ampache-a5d4acd8469d571c39f004431836f13d0ef1a5b6.zip |
fixed delete disabled and sort_files bin scripts
Diffstat (limited to 'bin')
-rw-r--r-- | bin/delete_disabled.inc | 20 | ||||
-rw-r--r-- | bin/sort_files.inc | 49 |
2 files changed, 22 insertions, 47 deletions
diff --git a/bin/delete_disabled.inc b/bin/delete_disabled.inc index bec402ea..f975cbc2 100644 --- a/bin/delete_disabled.inc +++ b/bin/delete_disabled.inc @@ -1,7 +1,7 @@ <?php /* - Copyright 2001 - 2006 Ampache.org + Copyright 2001 - 2007 Ampache.org All Rights Reserved This program is free software; you can redistribute it and/or @@ -34,19 +34,21 @@ $path = dirname(__FILE__); $prefix = realpath($path . '/../'); require_once $prefix . '/lib/init.php'; -/* Get a list of filenames */ -$sql = "SELECT id,file FROM song WHERE enabled='0'"; -$db_results = mysql_query($sql,dbh()); +if ($debug) { echo "DEBUG ENABLED WILL NOT DELETE FILES!\n"; } -while ($r = mysql_fetch_assoc($db_results)) { +/* Get a list of filenames */ +$sql = "SELECT `id`,`file` FROM song WHERE enabled='0'"; +$db_results = Dba::query($sql); +while ($row = Dba::fetch_assoc($db_results)) { if ($debug) { - echo "Deleting: " . $r['file'] . "\n"; + echo "Would Delete: " . $row['file'] . "\n"; } else { - unlink($r['file']); - $sql = "DELETE FROM song WHERE id='" . sql_escape($r['id']) . "'"; - $del_results = mysql_query($sql,dbh()); + echo "Deleting: " . $row['file'] . "\n"; + unlink($row['file']); + $sql = "DELETE FROM `song` WHERE `id`='" . Dba::escape($row['id']) . "'"; + $del_results = Dba::query($sql); } } // end while diff --git a/bin/sort_files.inc b/bin/sort_files.inc index cb01e7f1..3a1d71cc 100644 --- a/bin/sort_files.inc +++ b/bin/sort_files.inc @@ -32,7 +32,7 @@ */ /* Don't do anything just tell me what you would do */ -//$test_mode = true; +$test_mode = true; /* m(__)m */ $alphabet_prefix = true; @@ -42,14 +42,16 @@ $path = dirname(__FILE__); $prefix = realpath($path . '/../'); require_once $prefix . '/lib/init.php'; +ob_end_clean(); + /* First Clean the catalog to we don't try to write anything we shouldn't */ $sql = "SELECT id FROM catalog WHERE catalog_type='local'"; -$db_results = mysql_query($sql, dbh()); +$db_results = Dba::query($sql); $catalogs = array(); -while ($r = mysql_fetch_row($db_results)) { +while ($r = Dba::fetch_row($db_results)) { $catalog = new Catalog($r['0']); $songs = $catalog->get_catalog_files(); @@ -59,7 +61,7 @@ while ($r = mysql_fetch_row($db_results)) { /* Foreach through each file and find it a home! */ foreach ($songs as $song) { /* Find this poor song a home */ - $song->format_song(); + $song->format(); $song->format_pattern(); $directory = sort_find_home($song,$catalog->sort_pattern,$catalog->path); $filename = $song->f_file; @@ -78,8 +80,6 @@ while ($r = mysql_fetch_row($db_results)) { sort_move_file($song,$fullpath); } - - } // end foreach song } // end foreach catalogs @@ -87,35 +87,6 @@ while ($r = mysql_fetch_row($db_results)) { /************** FUNCTIONS *****************/ /** - * sort_find_filename - * This gets the filename that this file should have, it takes the rename pattern of the catalog - * along with the song object. Nothing Special Here - */ -function sort_find_filename($song,$rename_pattern) { - - $extension = ltrim(substr($song->file,strlen($song->file)-4,4),"."); - - /* Create the filename that this file should have */ - $album = sort_clean_name($song->f_album_full); - $artist = sort_clean_name($song->f_artist_full); - $genre = sort_clean_name($song->f_genre); - $track = sort_clean_name($song->track); - $title = sort_clean_name($song->title); - $year = sort_clean_name($song->year); - - /* Start replacing stuff */ - $replace_array = array('%a','%A','%t','%T','%y','%g'); - $content_array = array($artist,$album,$title,$track,$year,$genre); - - $rename_pattern = str_replace($replace_array,$content_array,$rename_pattern); - - $rename_pattern = preg_replace("[\-\:\!]","_",$rename_pattern); - - return $rename_pattern . "." . $extension; - -} // sort_find_filename - -/** * sort_find_home * Get the directory for this file from the catalog and the song info using the sort_pattern * takes into account various artists and the alphabet_prefix @@ -135,6 +106,7 @@ function sort_find_home($song,$sort_pattern,$base) { /* Do the various check */ $album_object = new Album($song->album); + $album_object->format(); if ($album_object->artist_count != '1') { $artist = "Various"; } @@ -267,8 +239,9 @@ function sort_move_file($song,$fullname) { /* Now that we've got the correct directory structure let's try to copy it */ if ($GLOBALS['test_mode']) { echo "\tCopying $file to $directory\n"; - $sql = "UPDATE song SET file='" . sql_escape($fullname) . "' WHERE id='" . sql_escape($song->id) . "'"; + $sql = "UPDATE song SET file='" . Dba::escape($fullname) . "' WHERE id='" . Dba::escape($song->id) . "'"; echo "\tSQL: $sql\n"; + flush(); } else { @@ -311,8 +284,8 @@ function sort_move_file($song,$fullname) { if (!$results) { echo "Error: Unable to delete " . $song->file . "\n"; } /* Update the catalog */ - $sql = "UPDATE song SET file='" . sql_escape($fullname) . "' WHERE id='" . sql_escape($song->id) . "'"; - $db_results = mysql_query($sql, dbh()); + $sql = "UPDATE song SET file='" . Dba::escape($fullname) . "' WHERE id='" . Dba::escape($song->id) . "'"; + $db_results = Dba::query($sql); } // end else |