Permalink
Browse files

Allow CoreUpdate to run code (incl. SQL queries) in update packages

  • Loading branch information...
1 parent 31e392c commit 916cb7a36f33eeb7815c9e7701e0d738ea7f6e58 @haraldpdl haraldpdl committed Aug 1, 2011
@@ -367,7 +367,7 @@ public static function getDef($key) {
*
* @param string $procedure The name of the database query to execute
* @param array $data Parameters passed to the database query
- * @param string $ns The namespace the database query is stored in
+ * @param string $type The namespace type the database query is stored in [ Core, Site, CoreUpdate (@since v3.0.2), Application (default) ]
* @return mixed The result of the database query
*/
public static function callDB($procedure, $data = null, $type = 'Application') {
@@ -394,6 +394,13 @@ public static function callDB($procedure, $data = null, $type = 'Application') {
break;
+ case 'CoreUpdate':
+
+ $ns = 'osCommerce\\OM\\Work\\CoreUpdate\\' . $call[0];
+ $procedure = $call[1];
+
+ break;
+
case 'Application':
default:
@@ -20,6 +20,7 @@ class applyPackage {
public static function execute() {
$phar_can_open = true;
+ $meta = array();
$pro_hart = array();
try {
@@ -111,14 +112,12 @@ public static function execute() {
}
}
}
-
- self::log('##### UPDATE TO ' . self::$_to_version . ' COMPLETED');
} catch ( \Exception $e ) {
$phar_can_open = false;
self::log('##### ERROR: ' . $e->getMessage());
- self::log('##### REVERTING');
+ self::log('##### REVERTING STARTED');
foreach ( array_reverse($pro_hart, true) as $mess ) {
if ( $mess['type'] == 'directory' ) {
@@ -138,13 +137,37 @@ public static function execute() {
self::log('Reverted: ' . str_replace('/.CU_', '/', $mess['path']));
}
- self::log('##### REVERTING COMPLETED');
+ self::log('##### REVERTING COMPLETE');
self::log('##### UPDATE TO ' . self::$_to_version . ' FAILED');
trigger_error($e->getMessage());
trigger_error('Please review the update log at: ' . OSCOM::BASE_DIRECTORY . 'Work/Logs/update-' . self::$_to_version . '.txt');
}
+ if ( $phar_can_open === true ) {
+ if ( isset($meta['run']) && method_exists('osCommerce\\OM\\Work\\CoreUpdate\\' . $meta['run'] . '\\Controller', 'runAfter') ) {
+ $results = call_user_func(array('osCommerce\\OM\\Work\\CoreUpdate\\' . $meta['run'] . '\\Controller', 'runAfter'));
+
+ if ( !empty($results) ) {
+ self::log('##### RAN AFTER');
+
+ foreach ( $results as $r ) {
+ self::log($r);
+ }
+ }
+
+ self::log('##### CLEANUP');
+
+ if ( self::rmdir_r(OSCOM::BASE_DIRECTORY . 'Work/CoreUpdate/' . $meta['run']) ) {
+ self::log('Deleted: osCommerce/OM/Work/CoreUpdate/' . $meta['run']);
+ } else {
+ self::log('*** Could Not Delete: osCommerce/OM/Work/CoreUpdate/' . $meta['run']);
+ }
+ }
+
+ self::log('##### UPDATE TO ' . self::$_to_version . ' COMPLETE');
+ }
+
return $phar_can_open;
}

0 comments on commit 916cb7a

Please sign in to comment.