-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathFs.php
108 lines (93 loc) · 3 KB
/
Fs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Backup\Filesystem\Rollback;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Archive;
use Magento\Framework\Archive\Gz;
use Magento\Framework\Archive\Helper\File;
use Magento\Framework\Archive\Helper\File\Gz as HelperGz;
use Magento\Framework\Archive\Tar;
use Magento\Framework\Backup\Exception\CantLoadSnapshot;
use Magento\Framework\Backup\Exception\NotEnoughPermissions;
use Magento\Framework\Backup\Filesystem\Helper;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Phrase;
/**
* Rollback worker for rolling back via local filesystem
*/
class Fs extends AbstractRollback
{
/**
* @var Helper
*/
private $fsHelper;
/**
* Files rollback implementation via local filesystem
*
* @return void
* @throws LocalizedException
*
* @see AbstractRollback::run()
*/
public function run()
{
$snapshotPath = $this->_snapshot->getBackupPath();
if (!is_file($snapshotPath) || !is_readable($snapshotPath)) {
throw new CantLoadSnapshot(
new Phrase('Can\'t load snapshot archive')
);
}
$fsHelper = $this->getFsHelper();
$filesInfo = $fsHelper->getInfo(
$this->_snapshot->getRootDir(),
Helper::INFO_WRITABLE,
$this->_snapshot->getIgnorePaths()
);
if (!$filesInfo['writable']) {
if (!empty($filesInfo['writableMeta'])) {
throw new NotEnoughPermissions(
new Phrase(
'You need write permissions for: %1',
[implode(', ', $filesInfo['writableMeta'])]
)
);
}
throw new NotEnoughPermissions(
new Phrase("The rollback can't be executed because not all files are writable.")
);
}
$archiver = new Archive();
/**
* we need these fake initializations because all magento's files in filesystem will be deleted and autoloader
* won't be able to load classes that we need for unpacking
*/
new Tar();
new Gz();
new File('');
new HelperGz('');
new LocalizedException(new Phrase('dummy'));
if (!$this->_snapshot->keepSourceFile()) {
$fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths());
}
$archiver->unpack($snapshotPath, $this->_snapshot->getRootDir());
if ($this->_snapshot->keepSourceFile() === false) {
@unlink($snapshotPath);
}
}
/**
* Get file system helper instance
*
* @return Helper
* @deprecated 101.0.0
*/
private function getFsHelper()
{
if (!$this->fsHelper) {
$this->fsHelper = ObjectManager::getInstance()->get(Helper::class);
}
return $this->fsHelper;
}
}