-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall.php
66 lines (55 loc) · 1.99 KB
/
uninstall.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
<?php
declare(strict_types=1);
$addon = rex_addon::get('demo_fullpage');
// Delete Backup-Files
$setupconfig = (array) $addon->getProperty('setup');
$backupPath = rex_addon::get('backup')->getDataPath();
if (isset($setupconfig['dbimport']) && is_array($setupconfig['dbimport']) && $setupconfig['dbimport'] !== []) {
foreach ($setupconfig['dbimport'] as $import) {
rex_file::delete($backupPath . $import);
}
}
if (isset($setupconfig['fileimport']) && is_array($setupconfig['fileimport']) && $setupconfig['fileimport'] !== []) {
foreach ($setupconfig['fileimport'] as $import) {
rex_file::delete($backupPath.$import);
}
}
// delete media-files
rex_dir::deleteFiles(rex_path::media(), false);
rex_file::put(rex_path::media('.redaxo'), "// Ordner für abgelegte Dateien von redaxo\n");
// update config
// remove additional config from base config
$config = array_diff_recursive(
rex_file::getConfig($addon->getPath('package.yml')),
rex_file::getConfig($addon->getPath('package.setup.yml')),
);
rex_file::putConfig($addon->getPath('package.yml'), $config);
// Computes the difference of two arrays recursively
// https://gist.github.com/t3chnik/6b3b14d3859d810c02f4
/**
* Array Recursive Diff.
* @param array<mixed> $aArray1
* @param array<mixed> $aArray2
* @return array<mixed>
*/
function array_diff_recursive($aArray1, $aArray2): array
{
$aReturn = [];
foreach ($aArray1 as $mKey => $mValue) {
if (array_key_exists($mKey, $aArray2)) {
if (is_array($mValue)) {
if (is_array($aArray2[$mKey])) {
$aRecursiveDiff = array_diff_recursive($mValue, $aArray2[$mKey]);
if ([] !== $aRecursiveDiff) {
$aReturn[$mKey] = $aRecursiveDiff;
}
}
} elseif ($mValue !== $aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
} else {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}