forked from heybige/cscart_cli_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphp_flip_addon.php
87 lines (67 loc) · 2.02 KB
/
php_flip_addon.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
<?php
ini_set('memory_limit', '512M');
require_once 'cli_lib.php';
use Tygh\Addons\SchemesManager;
use Tygh\Bootstrap;
use Tygh\Registry;
use Tygh\Debugger;
if ( empty($argv[1]) ) {
echo "php {$argv[0]} [addon]\n";
exit;
}
// Check for multiple addons, or convert string to array
if ( strpos($argv[1],":") !== false )
$addons = explode(":",$argv[1]);
else
$addons = array($argv[1]);
echo "php_flip_addon: " . serialize($addons) . "\n";
$STACK = new SplStack();
foreach($addons as $addon) {
if ( !is_dir( Registry::get('config.dir.addons') . $addon) ) {
echo Registry::get('config.dir.addons') . $addon . " does not exist - skipping..\n";
continue;
}
uninstall($STACK,$addon);
}
foreach($STACK as $item) {
$addon = $STACK->pop();
fn_install_addon($addon,true,false);
fn_update_addon_status($addon,'A',true,false);
echo "INSTALL: {$addon}\n";
}
echo "DONE\n";
exit;
function uninstall(&$STACK,$addon) {
$INSTALLED = array();
$STACK->rewind();
foreach($STACK as $item)
$INSTALLED[] = $item;
// Check dependencies for this $addon - recurse if necessary
$dependencies = SchemesManager::getUninstallDependencies($addon);
if (!empty($dependencies)) {
foreach($dependencies as $shortcode => $name) {
// print "$addon depends on $shortcode\n";
if ( !in_array($shortcode,$INSTALLED) )
uninstall($STACK,$shortcode);
else
echo "warning: $addon already uninstalled\n";
}
}
if ( !IsSet($INSTALLED) || !in_array($addon,$INSTALLED) ) {
$result = fn_uninstall_addon($addon,true);
if ( empty($result) ) {
echo "could not uninstall '$addon' - aborting...\n\n";
echo "Re-installing previously uninstalled addons to restore system to good state\n";
foreach($STACK as $item) {
$addon = $STACK->pop();
fn_install_addon($addon,true,false);
fn_update_addon_status($addon,'A',true,false);
print "INSTALL: {$addon}\n";
}
exit;
}
echo "UNINSTALL: $addon\n";
$STACK->push($addon);
}
}
?>