Esempio n. 1
0
 /**
  * Test backup and extract and check files.
  *
  * @group slow
  */
 public function testBackupAndCheckFiles()
 {
     $this->manager->getEventDispatcher()->addListener(PostBackupEvent::class, function (PostBackupEvent $event) {
         $this->assertNotEmpty($event->getArchiveLocation());
         $zip = new ZipArchive();
         $zip->open($event->getArchiveLocation());
         $this->assertEquals('No error', $zip->getStatusString());
         $dir = $this->tmpDir . 'extracted';
         if (!file_exists($dir)) {
             mkdir($dir);
         }
         $this->assertTrue($zip->extractTo($dir));
         $this->dirHasFile($dir, 'bin');
         $this->dirHasFile($dir, 'res');
         $this->dirHasFile($dir, 'src');
         $this->dirHasFile($dir, 'src/Slicer');
         $this->dirHasFile($dir, 'src/Slicer/Manager/Backup');
         $this->dirHasFile($dir, 'src/Slicer/Command');
         $this->dirHasFile($dir, 'src/Slicer/Command/BackupCommand.php');
         $this->dirHasFile($dir, 'tests');
         $this->dirHasFile($dir, 'vendor');
         $this->dirHasFile($dir, 'composer.json');
         $this->dirHasFile($dir, 'composer.lock');
         $this->dirHasFile($dir, 'LICENSE');
         $this->dirHasFile($dir, 'phpunit.xml.dist');
         $this->dirHasFile($dir, 'slicer.json');
         $this->postVerified = TRUE;
     });
     $this->manager->backup(self::$backupOptions);
     $this->assertTrue($this->postVerified);
 }
Esempio n. 2
0
 /**
  * Execute backup command.
  *
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $this->backupManager = $this->getApplication()->getSlicer()->getBackupManager();
     $config = $this->backupManager->getConfig();
     $date = new DateTime();
     $dir = base_path($config->getStorage()['backup-dir']);
     $type = $config->getBackup()['file-type'];
     if ($input->hasOption('type') && '' !== trim($input->getOption('type'))) {
         $type = $input->getOption('type');
         if (!in_array($type, ['daily', 'unique', 'single'])) {
             $output->writeln('<error>Unknown type ' . $type . '. Using \'single\' by default.</error>');
         }
     }
     switch ($type) {
         case 'daily':
             $fileName = clean_slicer_path($dir . '/backup-' . $date->format('Ymd') . '.zip');
             break;
         case 'unique':
             $fileName = clean_slicer_path($dir . '/backup-' . $date->format('Ymdhms') . '.zip');
             break;
         case 'single':
         default:
             $fileName = clean_slicer_path($dir . '/backup.zip');
             break;
     }
     $baseDir = base_path();
     if ($input->hasOption('working-dir') && '' !== trim($input->getOption('working-dir'))) {
         $baseDir = $input->getOption('working-dir');
         if (!file_exists($baseDir)) {
             if (file_exists(base_path($baseDir))) {
                 $baseDir = base_path($baseDir);
             } else {
                 $output->writeln('Working Directory "' . $baseDir . '" not found');
                 return 1;
             }
         }
     }
     $status = $this->backupManager->backup(['backup-file' => $fileName, 'backup-type' => $input->hasOption('full') ? 'full' : 'restore', 'base-dir' => $baseDir, 'output' => ['debug' => $input->getOption('debug'), 'quiet' => TRUE === $input->getOption('debug') ? FALSE : TRUE, 'verbose' => $input->getOption('verbose')]]);
     if ($status instanceof Exception) {
         $output->writeln('<error>' . $status->getMessage() . '</error>');
         $status = 0;
     }
     $status = 1 === (int) $status ? 'Success' : 'Failed';
     $output->writeln('Backup Status: <info>' . $status . '</info>');
 }