public function process_archives($detection, $type) { $archFolder = PathFinder::get(VIREX_INCOMING_PATH, $detection, $type); // setting archives folder $files = $this->scan_folders($detection, $type); foreach ($files as $fil) { $fi = $archFolder . DIRECTORY_SEPARATOR . $fil; ALogger::start_action('processing ' . $fi); try { if ($this->extract_file($fi, $detection, $type)) { // process file try { unlink($fi); // delet file } catch (Exception $e) { ALogger::error('delete error: ' . $e->getMessage(), true); // catch fatal error } $this->stats_ok++; // count ok files } else { $this->stats_errors++; // count errors } } catch (Exception $e) { ALogger::error($e->getMessage(), true); // catch fata error } ALogger::end_action(); } return $files; }
public function add_new() { ALogger::log('AUrlArchive::search archives in urls folder'); $this->stats_errors = 0; // reinit stats $this->stats_ok = 0; $files = scandir($this->baseUrl); ALogger::log('Total files found: ' . (count($files) - 2) . ' archives'); if (count($files) > 2) { foreach ($files as $file) { if ($file != '.' && $file != '..' && $file != '_lockfile' && strpos($file, '.filepart') === false) { ALogger::start_action('processing ' . $file . '..'); try { $this->last_error = ''; if ($this->process_file($this->baseUrl . $file)) { if (file_exists($this->baseUrl . $file)) { unlink($this->baseUrl . $file); } $this->stats_ok++; } else { $this->move_to_bogus($this->baseUrl . $file); $this->stats_errors++; } } catch (Exception $e) { ALogger::error($e->getMessage(), true); // log critical error } ALogger::end_action(); // logging done message } } } // showing final stats if ($this->stats_errors + $this->stats_ok > 0) { ALogger::log('Success: ' . $this->stats_ok . ' archives'); ALogger::log('Errors : ' . $this->stats_errors . ' archives'); } }
public function deleteFiles($where, $values = array()) { $nerrors = 0; $nok = 0; $stillExists = Yii::app()->db->createCommand("SELECT count(*) 'n' FROM samples_detected_sde WHERE md5_sde=:md5"); $deleteId = Yii::app()->db->createCommand("DELETE FROM samples_detected_sde WHERE id_sde=:id"); $start = 0; while ($files = Yii::app()->db->createCommand("SELECT hex(md5_sde) 'hex', md5_sde, id_sde FROM samples_detected_sde WHERE " . $where)->queryAll(true, $values)) { ALogger::log('Found ' . count($files) . ' samples to delete.'); $start += 5000; foreach ($files as $f) { ALogger::start_action('deleting ' . $f['md5_sde'] . '..'); $deleteId->execute(array('id' => $f['id_sde'])); $exists = $stillExists->bindValue(':md5', $f['md5_sde'])->queryRow(); if (!$exists['n']) { // I delete it only if is not in db anymore( it can be deleted only from monthly and still be in daily for example..) $fName = PathFinder::get(VIREX_STORAGE_PATH, 'detected', '') . substr($f['hex'], 0, 3) . '/' . substr($f['hex'], 3, 3) . '/' . substr($f['hex'], 6, 3) . '/' . $f['hex']; if (file_exists($fName)) { try { if (unlink($fName)) { $nok++; } } catch (Exception $e) { ALogger::error($e->get_message()); $nerrors++; } } else { // ALogger::error('file not found'); $nerrors++; $nok++; } } else { $nok++; } ALogger::end_action(); } } if ($nerrors + $nok > 0) { ALogger::log('Deleted: ' . $nok . ' samples'); ALogger::log('Errors : ' . $nerrors . ' samples'); ALogger::empty_line(); } }