Skip to content

Commit 6abf6e0

Browse files
committed
update
1 parent 5f697ad commit 6abf6e0

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@
2323
/app/Config/core.php
2424
/app/Config/database.php
2525
/vendors/*
26-
composer.lock
26+
composer.lock
27+
main.php

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "codeeshop/ps-module-ocmod",
3+
"version": "1.0.1",
34
"description": "Ocmod XML for PrestaShop modules",
45
"license": "MIT",
56
"keywords":

src/XMLModifier.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
2-
32
namespace Codeeshop\PsModuleOcmod;
43

54
class XMLModifier
65
{
76
private $modDir;
87
private $rootDir;
8+
private $bakFiles = [];
99

1010
public function __construct($rootDir, $modDir)
1111
{
@@ -131,20 +131,31 @@ public function apply()
131131

132132
public function revert()
133133
{
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);
144150
}
145151
}
146152
}
147153

148154
return true;
149155
}
156+
157+
private function getBackupFiles()
158+
{
159+
return $this->bakFiles;
160+
}
150161
}

0 commit comments

Comments
 (0)