CRM-14871: Supply api call extension.upgrade for admins who manage extensions outside...
authorFrank J. Gómez <frank@ginkgostreet.com>
Tue, 17 Jun 2014 16:47:57 +0000 (12:47 -0400)
committerTim Otten <totten@civicrm.org>
Tue, 8 Jul 2014 07:40:39 +0000 (00:40 -0700)
api/v3/Extension.php

index 2e9d56857f6bd5ee7a43bf345991df5774f079cc..8ea07d1a6dadf9b30da72323ad270277fc941ebe 100644 (file)
@@ -68,6 +68,36 @@ function civicrm_api3_extension_install($params) {
   return civicrm_api3_create_success();
 }
 
+/**
+ * Upgrade an extension - runs upgrade_N hooks and system.flush
+ *
+ * @return array API result
+ * @static void
+ * @access public
+ *
+ */
+function civicrm_api3_extension_upgrade() {
+  CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
+  $queue = CRM_Extension_Upgrades::createQueue();
+  $runner = new CRM_Queue_Runner(array(
+    'title' => 'Extension Upgrades',
+    'queue' => $queue,
+    'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
+  ));
+
+  try {
+    $result = $runner->runAll();
+  } catch (CRM_Extension_Exception $e) {
+    return civicrm_api3_create_error($e->getMessage());
+  }
+
+  if ($result === TRUE) {
+    return civicrm_api3_create_success();
+  } else {
+    return $result;
+  }
+}
+
 /**
  * Enable an extension
  *