/** * Perform a manual backup * * Handles ajax requests as well as standard GET requests */ function request_do_backup() { if (empty($_REQUEST['hmbkp_schedule_id'])) { die; } if (defined('DOING_AJAX') && DOING_AJAX) { check_ajax_referer('hmbkp_run_schedule', 'hmbkp_run_schedule_nonce'); } else { check_admin_referer('hmbkp_run_schedule', 'hmbkp_run_schedule_nonce'); } Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client session_write_close(); $schedule_id = sanitize_text_field(urldecode($_REQUEST['hmbkp_schedule_id'])); $task = new \HM\Backdrop\Task('\\HM\\BackUpWordPress\\run_schedule_async', $schedule_id); /** * Backdrop doesn't cleanup tasks which fatal before they can finish * so we manually cancel the task if it's already scheduled. */ if ($task->is_scheduled()) { $task->cancel(); } $task->schedule(); die; }
/** * Perform a manual backup * * Handles ajax requests as well as standard GET requests */ function hmbkp_request_do_backup() { if (empty($_POST['hmbkp_schedule_id'])) { die; } if (defined('DOING_AJAX') && DOING_AJAX) { check_ajax_referer('hmbkp_run_schedule', 'hmbkp_run_schedule_nonce'); } else { check_admin_referer('hmbkp_run_schedule', 'hmbkp_run_schedule_nonce'); } HM\BackUpWordPress\Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client session_write_close(); $schedule_id = sanitize_text_field(urldecode($_POST['hmbkp_schedule_id'])); $task = new \HM\Backdrop\Task('hmbkp_run_schedule_async', $schedule_id); $task->schedule(); die; }
/** * Get the total filesize for a given file or directory * * If $file is a file then just return the result of `filesize()`. * If $file is a directory then schedule a recursive filesize scan. * * @param \SplFileInfo $file The file or directory you want to know the size of * @param bool $skip_excluded_files Skip excluded files when calculating a directories total size * * @return int The total of the file or directory */ public function filesize(\SplFileInfo $file, $skip_excluded_files = false) { // Skip missing or unreadable files if (!file_exists($file->getPathname()) || !$file->getRealpath() || !$file->isReadable()) { return false; } // If it's a file then just pass back the filesize if ($file->isFile() && $file->isReadable()) { return $file->getSize(); } // If it's a directory then pull it from the cached filesize array if ($file->isDir()) { // If we haven't calculated the site size yet then kick it off in a thread $directory_sizes = get_transient('hmbkp_directory_filesizes'); if (!is_array($directory_sizes)) { if (!$this->is_site_size_being_calculated()) { // Mark the filesize as being calculated set_transient('hmbkp_directory_filesizes_running', true, HOUR_IN_SECONDS); // Schedule a Backdrop task to trigger a recalculation $task = new \HM\Backdrop\Task(array($this, 'recursive_filesize_scanner')); $task->schedule(); } return; } if ($this->backup->get_root() === $file->getPathname()) { return $directory_sizes[$file->getPathname()]; } $current_pathname = trailingslashit($file->getPathname()); $root = trailingslashit($this->backup->get_root()); foreach ($directory_sizes as $path => $size) { // Remove any files that aren't part of the current tree if (false === strpos($path, $current_pathname)) { unset($directory_sizes[$path]); } } if ($skip_excluded_files) { $excludes = $this->backup->exclude_string('regex'); foreach ($directory_sizes as $path => $size) { // Skip excluded files if we have excludes if ($excludes && preg_match('(' . $excludes . ')', str_ireplace($root, '', Backup::conform_dir($path)))) { unset($directory_sizes[$path]); } } } // Directory size is now just a sum of all files across all sub directories return array_sum($directory_sizes); } }
function run_schedule() { $schedule_id = $this->check_schedule(); HM\BackUpWordPress\Path::get_instance()->cleanup(); // Fixes an issue on servers which only allow a single session per client session_write_close(); $task = new \HM\Backdrop\Task('hmbkp_run_schedule_async', $schedule_id); $task->schedule(); $schedule = new HM\BackUpWordPress\Scheduled_Backup(sanitize_text_field(urldecode($schedule_id))); $information['scheduleStatus'] = $schedule->get_status(); $information['file_size_text'] = $this->hmbkp_get_site_size_text($schedule); $information['started_ago'] = human_time_diff($schedule->get_schedule_running_start_time()); return array('result' => 'SUCCESS'); }
public function after_submission_init($entry, $form) { // Check if solve integration is enabled if (!isset($form['gfsolve']['isEnabled']) || !$form['gfsolve']['isEnabled']) { return; } $task = new \HM\Backdrop\Task(array($this, 'after_submission'), $entry, $form); $task->schedule(); // $this->after_submission( $entry, $form ); }
/** * Schedule task if it's needed. * * @since 1.0 * @access public */ public function maybe_schedule_task() { // Check if this is Backdrop request if (did_action('wp_ajax_nopriv_hm_backdrop_run')) { return; } // Check if queue exists $exists = WP_Temporary::get('simple_email_queue_exist'); if (!$exists) { return; } // Check how much emails are already sent in this interval $sent = WP_Temporary::get('simple_email_queue_sent'); if (!$sent) { $sent = 0; } // If number of sent is smaller than maximum number, schedule task if ($sent < $this->max()) { $task = new \HM\Backdrop\Task(array($this, 'process_queue')); $task->schedule(); } }