diff options
author | Paul Arthur <paul.arthur@flowerysong.com> | 2013-05-02 15:13:23 -0400 |
---|---|---|
committer | Paul Arthur <paul.arthur@flowerysong.com> | 2013-05-30 14:34:08 -0400 |
commit | 53aff101bf61807c9341a09b5df54e3211573c38 (patch) | |
tree | 6b277fb556d7a670541b9f117f176626dd5c8f89 /lib/class | |
parent | 2fa6899f94a18c7ed676ced06427ce8c0cbf4dbe (diff) | |
download | ampache-53aff101bf61807c9341a09b5df54e3211573c38.tar.gz ampache-53aff101bf61807c9341a09b5df54e3211573c38.tar.bz2 ampache-53aff101bf61807c9341a09b5df54e3211573c38.zip |
Work on remote clean
Diffstat (limited to 'lib/class')
-rw-r--r-- | lib/class/catalog.class.php | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/lib/class/catalog.class.php b/lib/class/catalog.class.php index 764e78c3..73e8b479 100644 --- a/lib/class/catalog.class.php +++ b/lib/class/catalog.class.php @@ -1136,54 +1136,54 @@ class Catalog extends database_object { * * Removes remote songs that no longer exist. */ - public function clean_remote_catalog() { - //FIXME: Implement + private function clean_remote_catalog() { $remote_handle = $this->connect(); if (!$remote_handle) { + debug_event('remote-clean', 'Remote login failed', 1, 'ampache-catalog'); return false; } - $sql = 'SELECT `id`, `url` FROM `song` WHERE `catalog` = ?'; + $dead = 0; + + $sql = 'SELECT `id`, `file` FROM `song` WHERE `catalog` = ?'; $db_results = Dba::read($sql, array($this->id)); while ($row = Dba::fetch_assoc($db_results)) { + debug_event('remote-clean', 'Starting work on ' . $row['file'] . '(' . $row['id'] . ')', 5, 'ampache-catalog'); try { - $song = $remote_handle->send_command('url_to_song', array('url' => $row['url'])); + $song = $remote_handle->send_command('url_to_song', array('url' => $row['file'])); } catch (Exception $e) { // FIXME: What to do, what to do } - - debug_event('catalog', json_encode($song), 5); + + if (count($song) == 1) { + debug_event('remote-clean', 'keeping song', 5, 'ampache-catalog'); + } + else { + debug_event('remote-clean', 'removing song', 5, 'ampache-catalog'); + $dead++; + Dba::write('DELETE FROM `song` WHERE `id` = ?', array($row['id'])); + } } - return true; + + return $dead; } /** - * clean_catalog - * Cleans the catalog of files that no longer exist. + * clean_local_catalog + * + * Removes local songs that no longer exist. */ - public function clean_catalog() { - - // We don't want to run out of time - set_time_limit(0); - - debug_event('clean', 'Starting on ' . $this->name, 5); - - require_once Config::get('prefix') . '/templates/show_clean_catalog.inc.php'; - ob_flush(); - flush(); - - // Do a quick check to make sure that the root of the catalog is - // readable. This will minimize the loss of catalog data if - // mount points fail - if ($this->catalog_type == 'local' && !is_readable($this->path)) { + private function clean_local_catalog() { + if (!is_readable($this->path)) { + // First sanity check; no point in proceeding with an unreadable + // catalog root. debug_event('catalog', 'Catalog path:' . $this->path . ' unreadable, clean failed', 1); Error::add('general', T_('Catalog Root unreadable, stopping clean')); Error::display('general'); - return false; + return 0; } - $dead_total = 0; $stats = self::get_stats($this->id); foreach(array('video', 'song') as $media_type) { @@ -1211,9 +1211,35 @@ class Catalog extends database_object { '(' . implode(',',$dead) . ')'; $db_results = Dba::write($sql); } - debug_event('clean', "$media_type finished, $dead_count removed from " . - $this->name, 5); } + return $dead_total; + } + + /** + * clean_catalog + * + * Cleans the catalog of files that no longer exist. + */ + public function clean_catalog() { + + // We don't want to run out of time + set_time_limit(0); + + debug_event('clean', 'Starting on ' . $this->name, 5); + + require_once Config::get('prefix') . '/templates/show_clean_catalog.inc.php'; + ob_flush(); + flush(); + + if ($this->catalog_type == 'remote') { + $dead_total = $this->clean_remote_catalog(); + } + else { + $dead_total = $this->clean_local_catalog(); + } + + debug_event('clean', 'clean finished, ' . $dead_count . + ' removed from '. $this->name, 5); // Remove any orphaned artists/albums/etc. self::gc(); |