コード例 #1
0
ファイル: class-cron.php プロジェクト: congtrieu112/anime
 /**
  * Check Jobs worked and Cleanup logs and so on
  */
 public static function check_cleanup()
 {
     $job_object = BackWPup_Job::get_working_data();
     // check aborted jobs for longer than a tow hours, abort them courtly and send mail
     if (is_object($job_object) && !empty($job_object->logfile)) {
         $not_worked_time = microtime(TRUE) - $job_object->timestamp_last_update;
         if ($not_worked_time > 3600) {
             $job_object->log(E_USER_ERROR, __('Aborted, because no progress for one hour!', 'backwpup'), __FILE__, __LINE__);
             $job_object->end();
         }
     }
     //Compress not compressed logs
     if (function_exists('gzopen') && get_site_option('backwpup_cfg_gzlogs') && !is_object($job_object)) {
         //Compress old not compressed logs
         if ($dir = opendir(get_site_option('backwpup_cfg_logfolder'))) {
             $jobids = BackWPup_Option::get_job_ids();
             while (FALSE !== ($file = readdir($dir))) {
                 if (is_writeable(get_site_option('backwpup_cfg_logfolder') . $file) && '.html' == substr($file, -5)) {
                     $compress = new BackWPup_Create_Archive(get_site_option('backwpup_cfg_logfolder') . $file . '.gz');
                     if ($compress->add_file(get_site_option('backwpup_cfg_logfolder') . $file)) {
                         unlink(get_site_option('backwpup_cfg_logfolder') . $file);
                         //change last logfile in jobs
                         foreach ($jobids as $jobid) {
                             $job_logfile = BackWPup_Option::get($jobid, 'logfile');
                             if (!empty($job_logfile) && $job_logfile == get_site_option('backwpup_cfg_logfolder') . $file) {
                                 BackWPup_Option::update($jobid, 'logfile', get_site_option('backwpup_cfg_logfolder') . $file . '.gz');
                             }
                         }
                     }
                     unset($compress);
                 }
             }
             closedir($dir);
         }
     }
     //Jobs cleanings
     if (!is_object($job_object)) {
         //remove restart cron
         wp_clear_scheduled_hook('backwpup_cron', array('id' => 'restart'));
         //temp cleanup
         BackWPup_Job::clean_temp_folder();
     }
     //check scheduling jobs that not found will removed because there are single scheduled
     $activejobs = BackWPup_Option::get_job_ids('activetype', 'wpcron');
     if (!empty($activejobs)) {
         foreach ($activejobs as $jobid) {
             $cron_next = wp_next_scheduled('backwpup_cron', array('id' => $jobid));
             if (!$cron_next || $cron_next < time()) {
                 wp_unschedule_event($cron_next, 'backwpup_cron', array('id' => $jobid));
                 $cron_next = BackWPup_Cron::cron_next(BackWPup_Option::get($jobid, 'cron'));
                 wp_schedule_single_event($cron_next, 'backwpup_cron', array('id' => $jobid));
             }
         }
     }
 }