Ejemplo n.º 1
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'))));
         }
     }
 }