sebastianfeldmann /
phpbu
| 1 | <?php |
||
| 2 | namespace phpbu\App\Backup\Sync; |
||
| 3 | |||
| 4 | use phpbu\App\Backup\Collector; |
||
| 5 | use phpbu\App\Backup\Target; |
||
| 6 | use phpbu\App\Configuration\Backup\Cleanup; |
||
| 7 | use phpbu\App\Factory; |
||
| 8 | use phpbu\App\Result; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * Clearable trait |
||
| 12 | * |
||
| 13 | * @package phpbu |
||
| 14 | * @subpackage Sync |
||
| 15 | * @author Sebastian Feldmann <[email protected]> |
||
| 16 | * @author Vitaly Baev <[email protected]> |
||
| 17 | * @copyright Sebastian Feldmann <[email protected]> |
||
| 18 | * @license https://opensource.org/licenses/MIT The MIT License (MIT) |
||
| 19 | * @link http://phpbu.de/ |
||
| 20 | * @since Class available since Release 5.1.0 |
||
| 21 | */ |
||
| 22 | trait Cleanable |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Cleaner configuration. |
||
| 26 | * |
||
| 27 | * @var \phpbu\App\Configuration\Backup\Cleanup |
||
| 28 | */ |
||
| 29 | protected $cleanupConfig; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * The cleaner instance executing the actual cleaning process. |
||
| 33 | * |
||
| 34 | * @var \phpbu\App\Backup\Cleaner |
||
| 35 | */ |
||
| 36 | protected $cleaner; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Simulation indicator. |
||
| 40 | * |
||
| 41 | * @var bool |
||
| 42 | */ |
||
| 43 | protected $isSimulation = false; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Check sync clean configuration entities and set up a proper cleaner |
||
| 47 | * |
||
| 48 | * @param array $options |
||
| 49 | * @throws \phpbu\App\Exception |
||
| 50 | */ |
||
| 51 | 46 | public function setUpCleanable(array $options) |
|
| 52 | { |
||
| 53 | 46 | $config = []; |
|
| 54 | 46 | foreach ($options as $key => $value) { |
|
| 55 | 46 | if (strpos($key, "cleanup.") === 0) { |
|
| 56 | 46 | $config[str_replace('cleanup.', '', $key)] = $value; |
|
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | 46 | if (isset($config['type'])) { |
|
| 61 | 7 | $this->cleanupConfig = new Cleanup($config['type'], false, $config); |
|
| 62 | 7 | $this->cleaner = (new Factory())->createCleaner( |
|
| 63 | 7 | $this->cleanupConfig->type, |
|
| 64 | 7 | $this->cleanupConfig->options |
|
| 65 | ); |
||
| 66 | } |
||
| 67 | 46 | } |
|
| 68 | |||
| 69 | /** |
||
| 70 | * Creates collector for remote cleanup. |
||
| 71 | * |
||
| 72 | * @param \phpbu\App\Backup\Target $target |
||
| 73 | * @return \phpbu\App\Backup\Collector |
||
| 74 | */ |
||
| 75 | abstract protected function createCollector(Target $target): Collector; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Execute the remote clean up if needed. |
||
| 79 | * |
||
| 80 | * @param \phpbu\App\Backup\Target $target |
||
| 81 | * @param \phpbu\App\Result $result |
||
| 82 | */ |
||
| 83 | 15 | public function cleanup(Target $target, Result $result) |
|
| 84 | { |
||
| 85 | 15 | if (!$this->cleaner) { |
|
| 86 | 8 | return; |
|
| 87 | } |
||
| 88 | |||
| 89 | 7 | $collector = $this->createCollector($target); |
|
| 90 | 7 | $result->debug(sprintf('remote cleanup: %s ', $this->cleanupConfig->type)); |
|
| 91 | 7 | $this->cleaner->cleanup($target, $collector, $result); |
|
| 92 | 7 | } |
|
| 93 | |||
| 94 | /** |
||
| 95 | * Simulate remote cleanup. |
||
| 96 | * |
||
| 97 | * @param Target $target |
||
| 98 | * @param Result $result |
||
| 99 | */ |
||
| 100 | 10 | public function simulateRemoteCleanup(Target $target, Result $result) |
|
|
0 ignored issues
–
show
|
|||
| 101 | { |
||
| 102 | 10 | if ($this->cleaner) { |
|
| 103 | $result->debug(sprintf('remote cleanup: %s ', $this->cleanupConfig->type)); |
||
| 104 | } |
||
| 105 | 10 | } |
|
| 106 | } |
||
| 107 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.