Example #1
0
 /**
  * Process the daily routine clean part : remove useless files
  *
  * @return void
  * @access private
  */
 protected function _dailyRoutineClean()
 {
     //clean all files older than 4h in both uploads directories
     $yesterday = time() - 14400;
     //4h
     try {
         foreach (new DirectoryIterator(PATH_UPLOAD_FS) as $file) {
             if ($file->isFile() && $file->getFilename() != ".htaccess" && $file->getMTime() < $yesterday) {
                 @unlink($file->getPathname());
             }
         }
     } catch (Exception $e) {
     }
     try {
         foreach (new DirectoryIterator(PATH_UPLOAD_VAULT_FS) as $file) {
             if ($file->isFile() && $file->getFilename() != ".htaccess" && $file->getMTime() < $yesterday) {
                 @unlink($file->getPathname());
             }
         }
     } catch (Exception $e) {
     }
     //clean all files older than 30 days in cache directory
     $month = time() - 2592000;
     //30 days
     try {
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_CACHE_FS), RecursiveIteratorIterator::SELF_FIRST) as $file) {
             if ($file->isFile() && $file->getFilename() != ".htaccess" && $file->getMTime() < $month) {
                 @unlink($file->getPathname());
             }
         }
     } catch (Exception $e) {
     }
     //clean tmp dir
     try {
         //files first
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_TMP_FS), RecursiveIteratorIterator::SELF_FIRST) as $file) {
             if ($file->isFile()) {
                 @unlink($file->getPathname());
             }
         }
         //then directories
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(PATH_TMP_FS), RecursiveIteratorIterator::SELF_FIRST) as $file) {
             if ($file->isDir() && $file->getFilename() != "." && $file->getFilename() != "..") {
                 @rmdir($file->getPathname());
             }
         }
     } catch (Exception $e) {
     }
     //rotate error log file
     try {
         $source = PATH_MAIN_FS . '/' . CMS_grandFather::ERROR_LOG;
         $dest = PATH_LOGS_FS . '/' . CMS_grandFather::ERROR_LOG . '-' . date('Y-m-d') . '.gz';
         if (is_file($source) && !is_file($dest) && CMS_file::gzipfile($source, $dest, 3)) {
             //erase error log file
             @unlink($source);
         }
     } catch (Exception $e) {
     }
 }