Exemplo n.º 1
0
 /**
  * gc
  *
  * This is a wrapper function for all of the different cleaning
  * functions, it runs them in an order that resembles correctness.
  */
 public static function gc()
 {
     debug_event('catalog', 'Database cleanup started', 5);
     Song::gc();
     Album::gc();
     Artist::gc();
     Video::gc();
     Art::gc();
     Stats::gc();
     Rating::gc();
     Userflag::gc();
     Useractivity::gc();
     Playlist::gc();
     Tmp_Playlist::gc();
     Shoutbox::gc();
     Tag::gc();
     // TODO: use InnoDB with foreign keys and on delete cascade to get rid of garbage collection
     \Lib\Metadata\Repository\Metadata::gc();
     \Lib\Metadata\Repository\MetadataField::gc();
     debug_event('catalog', 'Database cleanup ended', 5);
 }
Exemplo n.º 2
0
 /**
  * clean catalog procedure
  *
  * Removes local songs that no longer exist.
  */
 public function clean_catalog_proc()
 {
     if (!Core::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);
         AmpError::add('general', T_('Catalog Root unreadable, stopping clean'));
         AmpError::display('general');
         return 0;
     }
     $dead_total = 0;
     $stats = self::get_stats($this->id);
     $this->count = 0;
     foreach (array('video', 'song') as $media_type) {
         $total = $stats[$media_type . 's'];
         // UGLY
         if ($total == 0) {
             continue;
         }
         $chunks = floor($total / 10000);
         $dead = array();
         foreach (range(0, $chunks) as $chunk) {
             $dead = array_merge($dead, $this->_clean_chunk($media_type, $chunk, 10000));
         }
         $dead_count = count($dead);
         // The AlmightyOatmeal sanity check
         // Never remove everything; it might be a dead mount
         if ($dead_count >= $total) {
             debug_event('catalog', 'All files would be removed. Doing nothing.', 1);
             AmpError::add('general', T_('All files would be removed. Doing nothing'));
             continue;
         }
         if ($dead_count) {
             $dead_total += $dead_count;
             $sql = "DELETE FROM `{$media_type}` WHERE `id` IN " . '(' . implode(',', $dead) . ')';
             $db_results = Dba::write($sql);
         }
     }
     \Lib\Metadata\Repository\Metadata::gc();
     \Lib\Metadata\Repository\MetadataField::gc();
     return $dead_total;
 }
Exemplo n.º 3
0
 /**
  * Cleans the Catalog.
  * This way is a little fishy, but if we start beets for every single file, it may take horribly long.
  * So first we get the difference between our and the beets database and then clean up the rest.
  * @return integer
  */
 public function clean_catalog_proc()
 {
     $parser = $this->getParser();
     $this->songs = $this->getAllSongfiles();
     $parser->setHandler($this, 'removeFromDeleteList');
     $parser->start($this->listCommand);
     $count = count($this->songs);
     $this->deleteSongs($this->songs);
     if (Song::isCustomMetadataEnabled()) {
         \Lib\Metadata\Repository\Metadata::gc();
         \Lib\Metadata\Repository\MetadataField::gc();
     }
     $this->updateUi('clean', $this->cleanCounter, null, true);
     return $count;
 }