Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Fs.php
Go to the documentation of this file.
1 <?php
8 
20 
26 class Fs extends AbstractRollback
27 {
31  private $fsHelper;
32 
41  public function run()
42  {
43  $snapshotPath = $this->_snapshot->getBackupPath();
44 
45  if (!is_file($snapshotPath) || !is_readable($snapshotPath)) {
46  throw new CantLoadSnapshot(
47  new Phrase('Can\'t load snapshot archive')
48  );
49  }
50 
51  $fsHelper = $this->getFsHelper();
52 
53  $filesInfo = $fsHelper->getInfo(
54  $this->_snapshot->getRootDir(),
56  $this->_snapshot->getIgnorePaths()
57  );
58 
59  if (!$filesInfo['writable']) {
60  if (!empty($filesInfo['writableMeta'])) {
61  throw new NotEnoughPermissions(
62  new Phrase(
63  'You need write permissions for: %1',
64  [implode(', ', $filesInfo['writableMeta'])]
65  )
66  );
67  }
68 
69  throw new NotEnoughPermissions(
70  new Phrase("The rollback can't be executed because not all files are writable.")
71  );
72  }
73 
74  $archiver = new Archive();
75 
80  new Tar();
81  new Gz();
82  new File('');
83  new HelperGz('');
84  new LocalizedException(new Phrase('dummy'));
85 
86  if (!$this->_snapshot->keepSourceFile()) {
87  $fsHelper->rm($this->_snapshot->getRootDir(), $this->_snapshot->getIgnorePaths());
88  }
89  $archiver->unpack($snapshotPath, $this->_snapshot->getRootDir());
90 
91  if ($this->_snapshot->keepSourceFile() === false) {
92  @unlink($snapshotPath);
93  }
94  }
95 
100  private function getFsHelper()
101  {
102  if (!$this->fsHelper) {
103  $this->fsHelper = ObjectManager::getInstance()->get(Helper::class);
104  }
105 
106  return $this->fsHelper;
107  }
108 }