1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of the Backup package, an RunOpenCode project. |
4
|
|
|
* |
5
|
|
|
* (c) 2015 RunOpenCode |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* This project is fork of "kbond/php-backup", for full credits info, please |
11
|
|
|
* view CREDITS file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
namespace RunOpenCode\Backup\Workflow; |
14
|
|
|
|
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
use RunOpenCode\Backup\Contract\BackupInterface; |
17
|
|
|
use RunOpenCode\Backup\Contract\EventDispatcherAwareInterface; |
18
|
|
|
use RunOpenCode\Backup\Contract\LoggerAwareInterface; |
19
|
|
|
use RunOpenCode\Backup\Event\BackupEvent; |
20
|
|
|
use RunOpenCode\Backup\Event\BackupEvents; |
21
|
|
|
use RunOpenCode\Backup\Event\EventDispatcherAwareTrait; |
22
|
|
|
use RunOpenCode\Backup\Log\LoggerAwareTrait; |
23
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class PreRotate |
27
|
|
|
* |
28
|
|
|
* Activity "PreRotation": nominate backups for rotation prior upload of backup to destination. |
29
|
|
|
* |
30
|
|
|
* @package RunOpenCode\Backup\Workflow |
31
|
|
|
*/ |
32
|
|
View Code Duplication |
class PreRotate extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
use LoggerAwareTrait; |
35
|
|
|
use EventDispatcherAwareTrait; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
4 |
|
public function execute() |
41
|
|
|
{ |
42
|
|
|
try { |
43
|
|
|
|
44
|
4 |
|
$nominations = $this->profile->getPreRotator()->nominate($this->profile->getDestination()->all()); |
45
|
|
|
|
46
|
4 |
|
$preRotateCount = $this->profile->getDestination()->count(); |
47
|
|
|
|
48
|
4 |
|
if (count($nominations) > 0) { |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var BackupInterface $nomination |
52
|
|
|
*/ |
53
|
2 |
|
foreach ($nominations as $nomination) { |
54
|
|
|
|
55
|
2 |
|
$this->profile->getDestination()->delete($nomination->getName()); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
2 |
|
$this->getEventDispatcher()->dispatch(BackupEvents::PRE_ROTATE, new BackupEvent($this, $this->profile, $this->backup, $this)); |
60
|
|
|
|
61
|
2 |
|
$this->getLogger()->info(sprintf('Pre-rotation successfully executed, %s backups rotated.', ($preRotateCount - $this->profile->getDestination()->count()))); |
62
|
|
|
|
63
|
4 |
|
} catch (\Exception $e) { |
64
|
|
|
|
65
|
2 |
|
$this->getLogger()->error(sprintf('Could not execute pre-rotation for profile "%s".', $this->profile->getName()), array( |
66
|
2 |
|
'message' => $e->getMessage(), |
67
|
2 |
|
'code' => $e->getCode(), |
68
|
2 |
|
'file' => $e->getFile(), |
69
|
2 |
|
'line' => $e->getLine(), |
70
|
2 |
|
'trace' => $e->getTrace() |
71
|
2 |
|
)); |
72
|
|
|
|
73
|
2 |
|
throw $e; |
74
|
|
|
} |
75
|
2 |
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.