Example #1
0
 protected function __construct()
 {
     if (false !== get_transient('_my-wp-backup-activated')) {
         delete_transient('_my-wp-backup-activated');
         wp_redirect(Admin::get_page_url(''));
     }
     self::$info = get_file_data(__FILE__, array('name' => 'Plugin Name', 'pluginUri' => 'Plugin URI', 'supportUri' => 'Support URI', 'version' => 'Version', 'description' => 'Description', 'author' => 'Author', 'authorUri' => 'Author URI', 'textDomain' => 'Text Domain', 'domainPath' => 'Domain Path', 'slug' => 'Slug', 'license' => 'License', 'licenseUri' => 'License URI'));
     Admin::get_instance();
     $options = get_site_option('my-wp-backup-options', Admin::$options);
     self::$info['baseDir'] = plugin_dir_path(__FILE__);
     self::$info['baseDirUrl'] = plugin_dir_url(__FILE__);
     self::$info['backup_dir'] = trailingslashit(ABSPATH) . trailingslashit(ltrim($options['backup_dir'], '/'));
     self::$info['root_dir'] = trailingslashit(ABSPATH);
     if (defined('WP_CLI') && WP_CLI) {
         \WP_CLI::add_command('job', new Cli\Job());
         \WP_CLI::add_command('backup', new Cli\Backup());
     }
     add_action('wp_backup_run_job', array(Job::get_instance(), 'cron_run'));
     add_action('wp_backup_restore_backup', array(Backup::get_instance(), 'cron_run'));
     $version = get_site_option(self::KEY_VERSION);
     if (!$version || self::$info['version'] !== $version) {
         if ($this->update_options()) {
             update_site_option(self::KEY_VERSION, self::$info['version']);
         }
     }
 }
Example #2
0
 public function table_data()
 {
     $this->all = array_map(function ($value) {
         return $value;
     }, \MyWPBackup\Admin\Backup::get_instance()->all());
     $data = $this->all;
     return $data;
 }
Example #3
0
 public function init()
 {
     wp_cache_add_non_persistent_groups('my-wp-backup');
     add_action('admin_post_MyWPBackup_settings', array($this, 'post_settings'));
     add_action('admin_post_MyWPBackup_import', array($this, 'post_import'));
     add_action(is_multisite() ? 'network_admin_notices' : 'admin_notices', array($this, 'admin_notice'));
     global $current_user;
     $user_id = $current_user->ID;
     if (is_multisite() && is_network_admin() || !is_multisite() && current_user_can('manage_options')) {
         if ('1' === filter_input(INPUT_GET, 'mwpb_notice_close', FILTER_SANITIZE_NUMBER_INT)) {
             add_user_meta($user_id, 'mwpb-notice-1', 'true', true);
         }
     }
     Job::get_instance();
     Backup::get_instance();
 }
Example #4
0
 /**
  * Delete a backup.
  * @synopsis <uniqid> --job=<id> [--confirm]
  *
  * @param $args
  * @param $assoc
  *
  * @return bool
  */
 function delete($args, $assoc)
 {
     if (isset($assoc['confirm'])) {
         $uniqid = $args[0];
         $id = $assoc['job'];
         $backup = \MyWPBackup\Admin\Backup::get_instance()->get($id, $uniqid);
         if (!isset($backup['duration'])) {
             echo __('No such backup exists.', 'my-wp-backup') . "\n";
             return false;
         }
         \MyWPBackup\Admin\Backup::get_instance()->delete($id, $uniqid);
         echo sprintf(__('Deleted backup with unique id %s.', 'my-wp-backup'), $uniqid) . "\n";
     } else {
         echo 'Please add --confirm to really delete the backup.' . "\n";
     }
     return true;
 }
Example #5
0
 public function ajax_restore_backup()
 {
     if (isset($_GET['job_id']) && isset($_GET['backup_uniqid'])) {
         $id = absint($_GET['job_id']);
         $uniqid = sanitize_key($_GET['backup_uniqid']);
         $key = isset($_GET['key']) ? absint($_GET['key']) : 0;
         try {
             $backup = Backup::get($id, $uniqid);
             $job = new JobModel($backup, true);
             $file = $job->read_logfile($uniqid);
             if (0 !== $key) {
                 $file->seek($key);
             }
             $response = array();
             while (!$file->eof()) {
                 $line = $file->fgets();
                 if (!empty($line)) {
                     array_push($response, json_decode($line));
                 }
             }
             wp_send_json(array('key' => $file->key(), 'lines' => $response));
         } catch (\Exception $e) {
             error_log($e);
             wp_send_json(array('key' => 0, 'lines' => array(__('Log file missing..', 'my-wp-backup'))));
         }
     }
 }
Example #6
0
        ?>
			    <a class="button button-cancel" href="<?php 
        echo esc_attr(Admin::get_page_url('backup'));
        ?>
"><?php 
        esc_html_e('No, Return me to backup list', 'my-wp-backup');
        ?>
</a>
		    </form>

	    <?php 
    } elseif ('restore' === $action) {
        ?>

		    <?php 
        $backup = \MyWPBackup\Admin\Backup::get_instance()->get($id, $uniqid);
        ?>
		    <form action="<?php 
        echo esc_attr(admin_url('admin-post.php'));
        ?>
" method="POST" accept-charset="utf-8">
			    <?php 
        wp_nonce_field('my-wp-backup-restore-backup');
        ?>
			    <input type="hidden" name="job_id" value="<?php 
        echo esc_attr($id);
        ?>
">
			    <input type="hidden" name="backup_uniqid" value="<?php 
        echo esc_attr($uniqid);
        ?>
Example #7
0
File: Job.php Project: akochnov/fts
 public function column_last_run($item)
 {
     $backup = Backup::get_instance()->last_from_job($item['id']);
     return $backup ? human_time_diff($backup['timestamp'], time()) . ' ago' : 'None';
 }
Example #8
0
 public function finish()
 {
     $this->end = microtime(true);
     if (is_null($this->backup)) {
         $item = array('job' => $this->toArray(), 'type' => $this->type, 'uniqid' => $this->uniqid, 'timestamp' => time(), 'duration' => $this->end - $this->start, 'size' => $this->archive->size, 'destinations' => $this->destinations, 'archives' => array_map('basename', $this->archive->get_archives()));
         if ('full' !== $this->type) {
             $item['last'] = $this->last['uniqid'];
         }
         /** @var \SPLFileObject $fp */
         $backup = Admin\Backup::get_instance();
         $backup->add($item);
         if ('1' === $this['delete_local'] && !empty($this['destination'])) {
             $this->log(__('Deleting archives from local folder', 'my-wp-backup'));
             foreach ($this->archive->get_archives() as $filepath) {
                 $this->log(sprintf(__('Deleting %s...', 'my-wp-backup'), $filepath), 'debug');
                 if (unlink($filepath)) {
                     $this->log(__('Ok.', 'my-wp-backup'), 'debug');
                 } else {
                     $this->log(sprintf(__('Failed to delete %s', 'my-wp-backup'), $filepath), 'error');
                 }
             }
         }
     }
 }
Example #9
0
		<a class="button button-primary" href="<?php 
echo esc_attr(\MyWPBackup\Admin\Admin::get_page_url('jobs'));
?>
"><?php 
esc_html_e('Perform a backup', 'my-wp-backup');
?>
</a>
		<a class="button" href="<?php 
echo esc_attr(\MyWPBackup\Admin\Admin::get_page_url('backup'));
?>
"><?php 
esc_html_e('Restore from a backup', 'my-wp-backup');
?>
</a>
		<?php 
$last = \MyWPBackup\Admin\Backup::get_instance()->last();
?>
		<?php 
if ($last) {
    ?>
			<p><em><?php 
    esc_html_e('Last backup was created', 'my-wp-backup');
    ?>
</em>: <?php 
    echo esc_html(sprintf(__('%s ago.', 'my-wp-backup'), human_time_diff($last['timestamp'], time())));
    ?>
</p>
		<?php 
} else {
    ?>
			<p><em><?php