예제 #1
0
 /**
  * Gets the queued or active job on top of the stack
  *  - set status to active
  *
  * @param $job_name
  *
  * @return bool|WPBackItUp_Job
  */
 public static function get_current_job($job_name)
 {
     $logger = new WPBackItUp_Logger(false, null, 'debug_job');
     $logger->log_info(__METHOD__, 'Begin - Job Name: ' . $job_name);
     //Get backup on top
     $args = array('posts_per_page' => 1, 'post_type' => $job_name, 'post_status' => array(self::QUEUED, self::ACTIVE), 'orderby' => 'post_date', 'order' => 'ASC');
     $jobs = get_posts($args);
     $logger->log($jobs);
     if (is_array($jobs) && count($jobs) > 0) {
         $logger->log_info(__METHOD__, 'Job found:' . count($jobs));
         $backup_job = new WPBackItUp_Job_v2($jobs[0]);
         if (self::QUEUED == $backup_job->job_status) {
             $backup_job->set_job_status_active();
         }
         return $backup_job;
     }
     $logger->log_info(__METHOD__, 'No jobs found.');
     $logger->log_info(__METHOD__, 'End');
     return false;
 }
 /**
  * Return the restore status and try run tasks
  */
 public function ajax_get_restore_status()
 {
     //@session_start();
     @session_write_close();
     // Check permissions
     if (!self::is_authorized()) {
         exit('Access denied.');
     }
     $event_logger = new WPBackItUp_Logger(false, null, 'debug_events');
     $event_logger->log_info(__METHOD__, 'User Permissions: ' . current_user_can('manage_options'));
     //Check permissions
     if (current_user_can('manage_options')) {
         global $restore_job, $process_id;
         $process_id = uniqid();
         $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'Begin');
         $this->backup_type = 'manual';
         //Is there a restore job available and is it already running
         $restore_job = WPBackItUp_Job_v2::get_current_job('restore');
         if (false !== $restore_job && $restore_job->get_lock('restore-lock')) {
             $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'Job Lock Acquired.');
             //Try Run Next Backup Tasks
             $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'Try Run restore task');
             include_once WPBACKITUP__PLUGIN_PATH . '/lib/includes/job_restore.php';
             $restore_job->release_lock();
             $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'End Try Run Backup Task');
         } else {
             $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'Job Lock NOT Acquired.');
         }
         //return status
         $log = WPBACKITUP__PLUGIN_PATH . '/logs/restore_status.log';
         if (file_exists($log)) {
             //Probably should use the database instead now.
             readfile($log);
             $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'Status sent to browser.');
         }
     }
     $event_logger->log_info(__METHOD__ . '(' . $process_id . ')', 'End');
     exit(0);
 }
예제 #3
0
    //Make sure backup folder is secured
    $file_system = new WPBackItUp_FileSystem();
    //Make sure backup folder is secured
    $backup_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__BACKUP_FOLDER;
    $file_system->secure_folder($backup_dir);
    //--Check restore folder folders
    $restore_dir = WPBACKITUP__CONTENT_PATH . '/' . WPBACKITUP__RESTORE_FOLDER;
    $file_system->secure_folder($restore_dir);
    //Make sure logs folder is secured
    $logs_dir = WPBACKITUP__PLUGIN_PATH . '/logs/';
    $file_system->secure_folder($logs_dir);
    $logger->log('**END SECURE FOLDERS**');
    $logger->log('**CLEANUP OLD JOBS**');
    $backup_job_purge_count = WPBackItUp_Job_v2::purge_completed_jobs('backup');
    $logger->log('Backup job records purged:' . $backup_job_purge_count);
    $cleanup_job_purge_count = WPBackItUp_Job_v2::purge_completed_jobs('cleanup');
    $logger->log('Cleanup job records purged:' . $cleanup_job_purge_count);
    $logger->log('**END CLEANUP OLD JOBS**');
    $cleanup_job->set_task_complete();
}
end_job(null, true);
//*** END SCHEDULED TASKS ***//
/******************/
/*** Functions ***/
/******************/
function get_job_name($timestamp)
{
    $fileUTCDateTime = $timestamp;
    //current_time( 'timestamp' );
    $localDateTime = date_i18n('Y-m-d-His', $fileUTCDateTime);
    $job_name = 'cleanup_' . $localDateTime;
예제 #4
0
 if (false !== $current_user) {
     $user_full_name = $current_user->first_name . ' ' . $current_user->last_name;
 }
 //Not going to use the restore Point SQL because IF the import failed then DB may be intact
 if (!$wp_restore->restore_database()) {
     fatal_error($task, '212', 'Database NOT restored.');
     //Do we want to recover the DB ?
 }
 end_status($task);
 $logger->log('**END RESTORE DATABASE**');
 $logger->log('*UPDATE DATABASE VALUES*');
 //update the session cookie
 wp_set_auth_cookie($user_id, true);
 //Cancel any jobs that were in the restored DB
 WPBackItUp_Job_v2::cancel_all_jobs('backup');
 WPBackItUp_Job_v2::cancel_all_jobs('cleanup');
 start_status('update_user');
 //Restored DB so current user may not be there.
 //If current user id doesnt exist then create it
 //if exists update to current properties
 if (!$wp_restore->update_credentials($user_id, $user_full_name, $current_user_login, $current_user_pass_hash, $current_user_email, $table_prefix)) {
     warning('215', 'Cant update user credentials.');
 }
 end_status('update_user');
 start_status('update_site_info');
 if (!$wp_restore->update_siteurl($table_prefix, $current_siteurl)) {
     warning('213', 'Cant update site url.');
 }
 if (!$wp_restore->update_homeurl($table_prefix, $current_homeurl)) {
     warning('214', 'Cant update home url.');
 }