function set_server_config_notices() { $notices = Notices::get_instance(); $messages = array(); if (!is_dir(Path::get_path())) { $messages[] = sprintf(__('The backups directory can\'t be created because your %s directory isn\'t writable. Please create the folder manually.', 'backupwordpress'), '<code>' . esc_html(dirname(Path::get_path())) . '</code>'); } if (is_dir(Path::get_path()) && !wp_is_writable(Path::get_path())) { $messages[] = __('The backups directory isn\'t writable. Please fix the permissions.', 'backupwordpress'); } if (Backup_Utilities::is_safe_mode_on()) { $messages[] = sprintf(__('%1$s is running in %2$s, please contact your host and ask them to disable it. BackUpWordPress may not work correctly whilst %3$s is on.', 'backupwordpress'), '<code>PHP</code>', sprintf('<a href="%1$s">%2$s</a>', __('http://php.net/manual/en/features.safe-mode.php', 'backupwordpress'), __('Safe Mode', 'backupwordpress')), '<code>' . __('Safe Mode', 'backupwordpress') . '</code>'); } if (defined('HMBKP_PATH') && HMBKP_PATH) { // Suppress open_basedir warning https://bugs.php.net/bug.php?id=53041 if (!path_in_php_open_basedir(HMBKP_PATH)) { $messages[] = sprintf(__('Your server has an %1$s restriction in effect and your custom backups directory (%2$s) is not within the allowed path(s): (%3$s).', 'backupwordpress'), '<code>open_basedir</code>', '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(@ini_get('open_basedir')) . '</code>'); } elseif (!file_exists(HMBKP_PATH)) { $messages[] = sprintf(__('Your custom path does not exist', 'backupwordpress')); } else { if (!is_dir(HMBKP_PATH)) { $messages[] = sprintf(__('Your custom backups directory %1$s doesn\'t exist and can\'t be created, your backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>'); } if (is_dir(HMBKP_PATH) && !wp_is_writable(HMBKP_PATH)) { $messages[] = sprintf(__('Your custom backups directory %1$s isn\'t writable, new backups will be saved to %2$s instead.', 'backupwordpress'), '<code>' . esc_html(HMBKP_PATH) . '</code>', '<code>' . esc_html(Path::get_path()) . '</code>'); } } } if (!is_readable(Path::get_root())) { $messages[] = sprintf(__('Your site root path %s isn\'t readable.', 'backupwordpress'), '<code>' . Path::get_root() . '</code>'); } if (!Requirement_Mysqldump_Command_Path::test() && !Requirement_PDO::test()) { $messages[] = sprintf(__('Your database cannot be backed up because your server doesn\'t support %1$s or %2$s. Please contact your host and ask them to enable them.', 'backupwordpress'), '<code>mysqldump</code>', '<code>PDO</code>'); } if (count($messages) > 0) { $notices->set_notices('server_config', $messages, false); } }
/** * Dismiss an error and then redirect back to the backups page */ function dismiss_error() { Path::get_instance()->cleanup(); Notices::get_instance()->clear_all_notices(); wp_safe_redirect(wp_get_referer(), 303); die; }
function display_error_and_offer_to_email_it() { check_ajax_referer('hmbkp_nonce', 'nonce'); if (empty($_POST['hmbkp_error'])) { die; } $errors = explode("\n", wp_strip_all_tags(stripslashes($_POST['hmbkp_error']))); Notices::get_instance()->set_notices('backup_errors', $errors); wp_send_json_success(wp_get_referer()); }
/** * Run the backup * */ public function run() { // Don't run if this schedule is already running if ($this->status->is_started()) { return; } // Setup our Site Backup Object $backup = new Backup($this->get_backup_filename(), $this->get_database_dump_filename()); $backup->set_type($this->get_type()); $backup->set_excludes($this->get_excludes()); $backup->set_status($this->status); $this->do_action('hmbkp_backup_started', $backup); $this->status->start($this->get_backup_filename(), __('Starting backup...', 'backupwordpress')); $this->status->set_status(__('Deleting old backups...', 'backupwordpress')); // Delete old backups now in-case we fatal error during the backup process $this->delete_old_backups(); $backup->run(); $errors = array_merge($backup->errors, $backup->warnings); $notices = array(); foreach ($errors as $key => $error) { $key = str_replace(array(__NAMESPACE__ . '\\', '_File_Backup_Engine', '_Database_Backup_Engine'), array('', '', ''), $key); $notices[] = $key . ': ' . implode(', ', $error); } Notices::get_instance()->set_notices('backup_errors', $notices); $this->status->set_status(__('Deleting old backups...', 'backupwordpress')); // Delete old backups again $this->delete_old_backups(); $this->do_action('hmbkp_backup_complete', $backup); $this->status->finish(); $this->update_average_schedule_run_time($this->status->get_start_time(), time()); }
private function reset_notices() { $reflection = new \ReflectionClass(Notices::get_instance()); $instance = $reflection->getProperty('instance'); $instance->setAccessible(true); $instance->setValue(null, null); $instance->setAccessible(false); $this->notices = Notices::get_instance(); }