|
1 | 1 | <?php |
2 | | - |
3 | 2 | namespace Codeeshop\PsModuleOcmod; |
4 | 3 |
|
5 | 4 | class XMLModifier |
6 | 5 | { |
7 | 6 | private $modDir; |
8 | 7 | private $rootDir; |
| 8 | + private $bakFiles = []; |
9 | 9 |
|
10 | 10 | public function __construct($rootDir, $modDir) |
11 | 11 | { |
@@ -131,20 +131,31 @@ public function apply() |
131 | 131 |
|
132 | 132 | public function revert() |
133 | 133 | { |
134 | | - foreach (glob($this->modDir . '*/*/*.ocmod.xml') as $file) { |
135 | | - $xml = simplexml_load_file($file); |
136 | | - foreach ($xml->file as $f) { |
137 | | - $relPath = (string) $f['path']; |
138 | | - $fullPath = $this->rootDir . '/' . $relPath; |
139 | | - $backupPath = $fullPath . '.bak'; |
140 | | - |
141 | | - if (file_exists($backupPath)) { |
142 | | - copy($backupPath, $fullPath); |
143 | | - unlink($backupPath); |
| 134 | + $directory = $this->rootDir; |
| 135 | + $this->bakFiles = []; |
| 136 | + |
| 137 | + $iterator = new \RecursiveIteratorIterator( |
| 138 | + new \RecursiveDirectoryIterator($directory, \FilesystemIterator::SKIP_DOTS) |
| 139 | + ); |
| 140 | + |
| 141 | + foreach ($iterator as $file) { |
| 142 | + if ($file->isFile() && $file->getExtension() === 'bak') { |
| 143 | + $this->bakFiles[] = $bakFile = $file->getPathname(); |
| 144 | + |
| 145 | + $old_file = rtrim($bakFile, '.bak'); |
| 146 | + if (file_exists($bakFile)) { |
| 147 | + copy($bakFile, $old_file); |
| 148 | + unlink($bakFile); |
| 149 | + print_r($bakFile, $old_file); |
144 | 150 | } |
145 | 151 | } |
146 | 152 | } |
147 | 153 |
|
148 | 154 | return true; |
149 | 155 | } |
| 156 | + |
| 157 | + private function getBackupFiles() |
| 158 | + { |
| 159 | + return $this->bakFiles; |
| 160 | + } |
150 | 161 | } |
0 commit comments