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\Exception\EmptySourceException; |
21
|
|
|
use RunOpenCode\Backup\Log\LoggerAwareTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class Fetch |
25
|
|
|
* |
26
|
|
|
* Activity "Fetch": fetch backups from sources. |
27
|
|
|
* |
28
|
|
|
* @package RunOpenCode\Backup\Workflow |
29
|
|
|
*/ |
30
|
|
|
class Fetch extends BaseActivity implements LoggerAwareInterface, EventDispatcherAwareInterface |
31
|
|
|
{ |
32
|
|
|
use LoggerAwareTrait; |
33
|
|
|
use EventDispatcherAwareTrait; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
4 |
|
public function execute() |
39
|
|
|
{ |
40
|
|
|
try { |
41
|
|
|
|
42
|
4 |
|
$this->backup->addFiles($this->profile->getSource()->fetch()); |
43
|
4 |
|
$this->getEventDispatcher()->dispatch(BackupEvents::FETCH, new BackupEvent($this, $this->profile, $this->backup, $this)); |
44
|
|
|
|
45
|
2 |
|
} catch (\Exception $e) { |
46
|
|
|
|
47
|
|
|
$this->getLogger()->error(sprintf('Could not fetch source files for profile "%s".', $this->profile->getName()), array( |
48
|
|
|
'message' => $e->getMessage(), |
49
|
|
|
'code' => $e->getCode(), |
50
|
|
|
'file' => $e->getFile(), |
51
|
|
|
'line' => $e->getLine(), |
52
|
|
|
'trace' => $e->getTrace() |
53
|
|
|
)); |
54
|
|
|
|
55
|
|
|
throw $e; |
56
|
|
|
} |
57
|
|
|
|
58
|
4 |
|
if (count($this->backup->getFiles()) == 0) { |
59
|
|
|
|
60
|
2 |
|
throw new EmptySourceException('Nothing to backup.'); |
61
|
|
|
|
62
|
|
|
} else { |
63
|
|
|
|
64
|
2 |
|
$this->getLogger()->info(sprintf('Source files successfully fetched, %s total files are scheduled for backup.', count($this->backup->getFiles()))); |
65
|
|
|
|
66
|
|
|
} |
67
|
2 |
|
} |
68
|
|
|
} |
69
|
|
|
|