1
|
|
|
<?php |
2
|
|
|
namespace phpbu\App\Backup\Sync; |
3
|
|
|
|
4
|
|
|
use phpbu\App\Backup\Cleaner; |
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 Clearable |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var Cleaner |
26
|
|
|
*/ |
27
|
|
|
protected $cleanupConfig; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Cleaner |
31
|
|
|
*/ |
32
|
|
|
protected $cleaner; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Check sync clean configuration entities and set up a proper cleaner |
36
|
|
|
* |
37
|
|
|
* @param array $options |
38
|
|
|
* @throws \phpbu\App\Exception |
39
|
|
|
*/ |
40
|
16 |
|
public function setUpClearable(array $options) |
41
|
|
|
{ |
42
|
16 |
|
$config = []; |
43
|
16 |
|
foreach ($options as $key => $value) { |
44
|
16 |
|
if (strpos($key, "cleanup.") === 0) { |
45
|
16 |
|
$config[str_replace('cleanup.', '', $key)] = $value; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
16 |
|
if (isset($config['type'])) { |
50
|
|
|
$skip = isset($config['skipOnFailure']) ? (bool) $config['skipOnFailure'] : true; |
51
|
|
|
// creating cleanup config |
52
|
|
|
$this->cleanupConfig = new Cleanup($config['type'], $skip, $config); |
|
|
|
|
53
|
|
|
// creating cleaner |
54
|
|
|
$this->cleaner = (new Factory())->createCleaner($this->cleanupConfig->type, $this->cleanupConfig->options); |
55
|
|
|
} |
56
|
16 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Execute the remote clean up if needed |
60
|
|
|
* |
61
|
|
|
* @param \phpbu\App\Backup\Target $target |
62
|
|
|
* @param \phpbu\App\Result $result |
63
|
|
|
* @throws \phpbu\App\Exception |
64
|
|
|
*/ |
65
|
1 |
|
public function cleanup(Target $target, Result $result) |
66
|
|
|
{ |
67
|
1 |
|
if (!$this->cleaner) { |
68
|
1 |
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (!method_exists($this, 'createCollector')) { |
72
|
|
|
throw new \phpbu\App\Exception('"createCollector" method must be implemented in Sync class that uses Clearable'); |
73
|
|
|
} |
74
|
|
|
$collector = $this->createCollector($target); |
|
|
|
|
75
|
|
|
$this->cleaner->cleanup($target, $collector, $result); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Simulate remote cleanup. |
80
|
|
|
* |
81
|
|
|
* @param Target $target |
82
|
|
|
* @param Result $result |
83
|
|
|
*/ |
84
|
6 |
|
public function simulateRemoteCleanup(Target $target, Result $result) |
85
|
|
|
{ |
86
|
6 |
|
if ($this->cleaner) { |
87
|
|
|
$result->debug(" sync cleanup: {$this->cleanupConfig->type}" . PHP_EOL); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..