Example #1
0
 /**
  * Set the cleanup configuration.
  *
  * @param  \phpbu\App\Configuration\Backup $backup
  * @param  array                           $json
  * @throws \phpbu\App\Exception
  */
 protected function setCleanup(Configuration\Backup $backup, array $json)
 {
     if (isset($json['cleanup'])) {
         if (!isset($json['cleanup']['type'])) {
             throw new Exception('invalid cleanup configuration: type missing');
         }
         $type = $json['cleanup']['type'];
         $skip = Arr::getValue($json['cleanup'], 'skipOnFailure', true);
         $options = $this->getOptions($json['cleanup']);
         $backup->setCleanup(new Configuration\Backup\Cleanup($type, $skip, $options));
     }
 }
Example #2
0
 /**
  * Tests PrinterCli::backupStart
  */
 public function testBackupFailed()
 {
     $source = new Configuration\Backup\Source('mysqldump');
     $backup = new Configuration\Backup('dummy', false);
     $backup->setSource($source);
     $printer = new PrinterCli(false, false, true);
     ob_start();
     $printer->onBackupStart($this->getEventMock('Backup\\Start', $backup));
     $printer->onBackupFailed($this->getEventMock('Backup\\Failed', $backup));
     $output = ob_get_clean();
     $this->assertTrue(strpos($output, 'failed') !== false);
 }
Example #3
0
 /**
  * Execute the cleanup.
  *
  * @param  \phpbu\App\Configuration\Backup $backup
  * @param  \phpbu\App\Backup\Target        $target
  * @param  \phpbu\App\Backup\Collector     $collector
  * @throws \Exception
  */
 protected function executeCleanup(Configuration\Backup $backup, Target $target, Collector $collector)
 {
     $cleanup = $backup->getCleanup();
     if (!empty($cleanup)) {
         try {
             $this->result->cleanupStart($cleanup);
             if ($this->failure && $cleanup->skipOnFailure) {
                 $this->result->cleanupSkipped($cleanup);
             } else {
                 $cleaner = $this->factory->createCleaner($cleanup->type, $cleanup->options);
                 $cleaner->cleanup($target, $collector, $this->result);
                 $this->result->cleanupEnd($cleanup);
             }
         } catch (Backup\Cleaner\Exception $e) {
             $this->failure = true;
             $this->result->addError($e);
             $this->result->cleanupFailed($cleanup);
         }
     }
 }
Example #4
0
 /**
  * Backup start event.
  *
  * @param \phpbu\App\Configuration\Backup $backup
  */
 public function backupStart(Configuration\Backup $backup)
 {
     $this->backupActive = new Result\Backup($backup->getName());
     $this->backups[] = $this->backupActive;
     $event = new Event\Backup\Start($backup);
     $this->eventDispatcher->dispatch(Event\Backup\Start::NAME, $event);
 }
Example #5
0
 /**
  * Set the cleanup configuration.
  *
  * @param  \phpbu\App\Configuration\Backup $backup
  * @param  \DOMElement                     $node
  * @throws \phpbu\App\Exception
  */
 protected function setCleanup(Configuration\Backup $backup, DOMElement $node)
 {
     /** @var \DOMNodeList $cleanupNodes */
     $cleanupNodes = $node->getElementsByTagName('cleanup');
     if ($cleanupNodes->length > 0) {
         /** @var \DOMElement $cleanupNode */
         $cleanupNode = $cleanupNodes->item(0);
         $type = $cleanupNode->getAttribute('type');
         if (!$type) {
             throw new Exception('invalid cleanup configuration: attribute type missing');
         }
         $skip = Str::toBoolean($cleanupNode->getAttribute('skipOnFailure'), true);
         $options = $this->getOptions($cleanupNode);
         $backup->setCleanup(new Configuration\Backup\Cleanup($type, $skip, $options));
     }
 }