/** * 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); } } }