Example #1
0
 /**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->progress = new ProgressBar($this->output);
     $this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
     Grav::instance()['config']->init();
     $destination = $this->input->getArgument('destination') ? $this->input->getArgument('destination') : null;
     $log = JsonFile::instance(Grav::instance()['locator']->findResource("log://backup.log", true, true));
     $backup = ZipBackup::backup($destination, [$this, 'output']);
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->output->writeln('');
     $this->output->writeln('');
 }
Example #2
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->output = $output;
     $output->getFormatter()->setStyle('red', new OutputFormatterStyle('red'));
     $output->getFormatter()->setStyle('cyan', new OutputFormatterStyle('cyan'));
     $output->getFormatter()->setStyle('green', new OutputFormatterStyle('green'));
     $output->getFormatter()->setStyle('magenta', new OutputFormatterStyle('magenta'));
     $this->progress = new ProgressBar($output);
     $this->progress->setFormat('Archiving <cyan>%current%</cyan> files [<green>%bar%</green>] %elapsed:6s% %memory:6s%');
     $destination = $input->getArgument('destination') ? $input->getArgument('destination') : ROOT_DIR;
     ZipBackup::backup($destination, [$this, 'output']);
     $output->writeln('');
     $output->writeln('');
 }
Example #3
0
 /**
  * Handle the backup action
  *
  * @return bool True if the action was performed.
  */
 protected function taskBackup()
 {
     $param_sep = $this->grav['config']->get('system.param_sep', ':');
     if (!$this->authorizeTask('backup', ['admin.maintenance', 'admin.super'])) {
         return;
     }
     $download = $this->grav['uri']->param('download');
     if ($download) {
         Utils::download(base64_decode(urldecode($download)), true);
     }
     $log = JsonFile::instance($this->grav['locator']->findResource("log://backup.log", true, true));
     try {
         $backup = ZipBackup::backup();
     } catch (\Exception $e) {
         $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.AN_ERROR_OCCURRED') . '. ' . $e->getMessage()];
         return true;
     }
     $download = urlencode(base64_encode($backup));
     $url = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, '/') . '/task' . $param_sep . 'backup/download' . $param_sep . $download . '/admin-nonce' . $param_sep . Utils::getNonce('admin-form');
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.YOUR_BACKUP_IS_READY_FOR_DOWNLOAD') . '. <a href="' . $url . '" class="button">' . $this->admin->translate('PLUGIN_ADMIN.DOWNLOAD_BACKUP') . '</a>', 'toastr' => ['timeOut' => 0, 'closeButton' => true]];
     return true;
 }
 /**
  * Handle the backup action
  *
  * @return bool True if the action was performed.
  */
 protected function taskBackup()
 {
     if (!$this->authoriseTask('backup', ['admin.maintenance', 'admin.super'])) {
         return;
     }
     $download = $this->grav['uri']->param('download');
     if ($download) {
         Utils::download(base64_decode(urldecode($download)), true);
     }
     $log = JsonFile::instance($this->grav['locator']->findResource("log://backup.log", true, true));
     try {
         $backup = ZipBackup::backup();
     } catch (\Exception $e) {
         $this->admin->json_response = ['status' => 'error', 'message' => 'An error occured. ' . $e->getMessage()];
         return true;
     }
     $download = urlencode(base64_encode($backup));
     $url = rtrim($this->grav['uri']->rootUrl(true), '/') . '/' . trim($this->admin->base, '/') . '/task:backup/download:' . $download;
     $log->content(['time' => time(), 'location' => $backup]);
     $log->save();
     $this->admin->json_response = ['status' => 'success', 'message' => 'Your backup is ready for download. <a href="' . $url . '" class="button">Download backup</a>', 'toastr' => ['timeOut' => 0, 'closeButton' => true]];
     return true;
 }