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 RunOpenCode\Backup\Contract\EventDispatcherAwareInterface; |
16
|
|
|
use RunOpenCode\Backup\Contract\LoggerAwareInterface; |
17
|
|
|
use RunOpenCode\Backup\Event\BackupEvent; |
18
|
|
|
use RunOpenCode\Backup\Event\BackupEvents; |
19
|
|
|
use RunOpenCode\Backup\Event\EventDispatcherAwareTrait; |
20
|
|
|
use RunOpenCode\Backup\Log\LoggerAwareTrait; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class Name |
24
|
|
|
* |
25
|
|
|
* Activity "Name": provide name for backup. |
26
|
|
|
* |
27
|
|
|
* @package RunOpenCode\Backup\Workflow |
28
|
|
|
*/ |
29
|
|
|
class Name extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface |
30
|
|
|
{ |
31
|
|
|
use LoggerAwareTrait; |
32
|
|
|
use EventDispatcherAwareTrait; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
2 |
View Code Duplication |
public function execute() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
try { |
40
|
|
|
|
41
|
2 |
|
$this->backup->setName($this->profile->getNamer()->getName()); |
42
|
2 |
|
$this->getEventDispatcher()->dispatch(BackupEvents::NAME, new BackupEvent($this, $this->profile, $this->backup, $this)); |
43
|
|
|
|
44
|
1 |
|
} catch (\Exception $e) { |
45
|
|
|
|
46
|
|
|
$this->getLogger()->error(sprintf('Could not set name of new backup for profile "%s".', $this->profile->getName()), array( |
47
|
|
|
'message' => $e->getMessage(), |
48
|
|
|
'code' => $e->getCode(), |
49
|
|
|
'file' => $e->getFile(), |
50
|
|
|
'line' => $e->getLine(), |
51
|
|
|
'trace' => $e->getTrace() |
52
|
|
|
)); |
53
|
|
|
|
54
|
|
|
throw $e; |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
$this->getLogger()->info(sprintf('Naming successfully completed, backup name: "%s".', $this->backup->getName())); |
58
|
2 |
|
} |
59
|
|
|
} |
60
|
|
|
|
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.