diff --git a/CRM/Dataprocessor/Upgrader/Base.php b/CRM/Dataprocessor/Upgrader/Base.php index 60af49405ec4fdb825a3726b3eaf714654177597..262e659c17e7501c53e9a95cb4069482b759c471 100644 --- a/CRM/Dataprocessor/Upgrader/Base.php +++ b/CRM/Dataprocessor/Upgrader/Base.php @@ -9,9 +9,9 @@ use CRM_Dataprocessor_ExtensionUtil as E; class CRM_Dataprocessor_Upgrader_Base { /** - * @var CRM_Dataprocessor_Upgrader_Base + * @var varies, subclass of ttis */ - public static $instance; + static $instance; /** * @var CRM_Queue_TaskContext @@ -19,25 +19,22 @@ class CRM_Dataprocessor_Upgrader_Base { protected $ctx; /** - * @var string - * eg 'com.example.myextension' + * @var string, eg 'com.example.myextension' */ protected $extensionName; /** - * @var string - * full path to the extension's source tree + * @var string, full path to the extension's source tree */ protected $extensionDir; /** - * @var array - * sorted numerically + * @var array(revisionNumber) sorted numerically */ private $revisions; /** - * @var bool + * @var boolean * Flag to clean up extension revision data in civicrm_setting */ private $revisionStorageIsDeprecated = FALSE; @@ -45,11 +42,12 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Obtain a reference to the active upgrade handler. */ - public static function instance() { + static public function instance() { if (!self::$instance) { + // FIXME auto-generate self::$instance = new CRM_Dataprocessor_Upgrader( 'dataprocessor', - E::path() + realpath(__DIR__ . '/../../../') ); } return self::$instance; @@ -61,25 +59,19 @@ class CRM_Dataprocessor_Upgrader_Base { * Note: Each upgrader instance should only be associated with one * task-context; otherwise, this will be non-reentrant. * - * ``` + * @code * CRM_Dataprocessor_Upgrader_Base::_queueAdapter($ctx, 'methodName', 'arg1', 'arg2'); - * ``` + * @endcode */ - public static function _queueAdapter() { + static public function _queueAdapter() { $instance = self::instance(); $args = func_get_args(); $instance->ctx = array_shift($args); $instance->queue = $instance->ctx->queue; $method = array_shift($args); - return call_user_func_array([$instance, $method], $args); + return call_user_func_array(array($instance, $method), $args); } - /** - * CRM_Dataprocessor_Upgrader_Base constructor. - * - * @param $extensionName - * @param $extensionDir - */ public function __construct($extensionName, $extensionDir) { $this->extensionName = $extensionName; $this->extensionDir = $extensionDir; @@ -90,8 +82,7 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Run a CustomData file. * - * @param string $relativePath - * the CustomData XML file path (relative to this extension's dir) + * @param string $relativePath the CustomData XML file path (relative to this extension's dir) * @return bool */ public function executeCustomDataFile($relativePath) { @@ -102,12 +93,11 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Run a CustomData file * - * @param string $xml_file - * the CustomData XML file path (absolute path) + * @param string $xml_file the CustomData XML file path (absolute path) * * @return bool */ - protected function executeCustomDataFileByAbsPath($xml_file) { + protected static function executeCustomDataFileByAbsPath($xml_file) { $import = new CRM_Utils_Migrate_Import(); $import->run($xml_file); return TRUE; @@ -116,8 +106,7 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Run a SQL file. * - * @param string $relativePath - * the SQL file path (relative to this extension's dir) + * @param string $relativePath the SQL file path (relative to this extension's dir) * * @return bool */ @@ -130,14 +119,10 @@ class CRM_Dataprocessor_Upgrader_Base { } /** - * Run the sql commands in the specified file. - * * @param string $tplFile * The SQL file path (relative to this extension's dir). * Ex: "sql/mydata.mysql.tpl". - * * @return bool - * @throws \CRM_Core_Exception */ public function executeSqlTemplate($tplFile) { // Assign multilingual variable to Smarty. @@ -156,19 +141,17 @@ class CRM_Dataprocessor_Upgrader_Base { * Run one SQL query. * * This is just a wrapper for CRM_Core_DAO::executeSql, but it - * provides syntactic sugar for queueing several tasks that + * provides syntatic sugar for queueing several tasks that * run different queries - * - * @return bool */ - public function executeSql($query, $params = []) { + public function executeSql($query, $params = array()) { // FIXME verify that we raise an exception on error CRM_Core_DAO::executeQuery($query, $params); return TRUE; } /** - * Syntactic sugar for enqueuing a task which calls a function in this class. + * Syntatic sugar for enqueuing a task which calls a function in this class. * * The task is weighted so that it is processed * as part of the currently-pending revision. @@ -180,11 +163,11 @@ class CRM_Dataprocessor_Upgrader_Base { $args = func_get_args(); $title = array_shift($args); $task = new CRM_Queue_Task( - [get_class($this), '_queueAdapter'], + array(get_class($this), '_queueAdapter'), $args, $title ); - return $this->queue->createItem($task, ['weight' => -1]); + return $this->queue->createItem($task, array('weight' => -1)); } // ******** Revision-tracking helpers ******** @@ -210,8 +193,6 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Add any pending revisions to the queue. - * - * @param CRM_Queue_Queue $queue */ public function enqueuePendingRevisions(CRM_Queue_Queue $queue) { $this->queue = $queue; @@ -219,23 +200,23 @@ class CRM_Dataprocessor_Upgrader_Base { $currentRevision = $this->getCurrentRevision(); foreach ($this->getRevisions() as $revision) { if ($revision > $currentRevision) { - $title = E::ts('Upgrade %1 to revision %2', [ + $title = ts('Upgrade %1 to revision %2', array( 1 => $this->extensionName, 2 => $revision, - ]); + )); // note: don't use addTask() because it sets weight=-1 $task = new CRM_Queue_Task( - [get_class($this), '_queueAdapter'], - ['upgrade_' . $revision], + array(get_class($this), '_queueAdapter'), + array('upgrade_' . $revision), $title ); $this->queue->createItem($task); $task = new CRM_Queue_Task( - [get_class($this), '_queueAdapter'], - ['setCurrentRevision', $revision], + array(get_class($this), '_queueAdapter'), + array('setCurrentRevision', $revision), $title ); $this->queue->createItem($task); @@ -246,12 +227,11 @@ class CRM_Dataprocessor_Upgrader_Base { /** * Get a list of revisions. * - * @return array - * revisionNumbers sorted numerically + * @return array(revisionNumbers) sorted numerically */ public function getRevisions() { if (!is_array($this->revisions)) { - $this->revisions = []; + $this->revisions = array(); $clazz = new ReflectionClass(get_class($this)); $methods = $clazz->getMethods(); @@ -276,7 +256,7 @@ class CRM_Dataprocessor_Upgrader_Base { private function getCurrentRevisionDeprecated() { $key = $this->extensionName . ':version'; - if ($revision = \Civi::settings()->get($key)) { + if ($revision = CRM_Core_BAO_Setting::getItem('Extension', $key)) { $this->revisionStorageIsDeprecated = TRUE; } return $revision; @@ -301,7 +281,7 @@ class CRM_Dataprocessor_Upgrader_Base { // ******** Hook delegates ******** /** - * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_install + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ public function onInstall() { $files = glob($this->extensionDir . '/sql/*_install.sql'); @@ -322,26 +302,26 @@ class CRM_Dataprocessor_Upgrader_Base { $this->executeCustomDataFileByAbsPath($file); } } - if (is_callable([$this, 'install'])) { + if (is_callable(array($this, 'install'))) { $this->install(); } } /** - * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_postInstall + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_postInstall */ public function onPostInstall() { $revisions = $this->getRevisions(); if (!empty($revisions)) { $this->setCurrentRevision(max($revisions)); } - if (is_callable([$this, 'postInstall'])) { + if (is_callable(array($this, 'postInstall'))) { $this->postInstall(); } } /** - * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_uninstall + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_uninstall */ public function onUninstall() { $files = glob($this->extensionDir . '/sql/*_uninstall.mysql.tpl'); @@ -350,7 +330,7 @@ class CRM_Dataprocessor_Upgrader_Base { $this->executeSqlTemplate($file); } } - if (is_callable([$this, 'uninstall'])) { + if (is_callable(array($this, 'uninstall'))) { $this->uninstall(); } $files = glob($this->extensionDir . '/sql/*_uninstall.sql'); @@ -362,21 +342,21 @@ class CRM_Dataprocessor_Upgrader_Base { } /** - * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_enable + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_enable */ public function onEnable() { // stub for possible future use - if (is_callable([$this, 'enable'])) { + if (is_callable(array($this, 'enable'))) { $this->enable(); } } /** - * @see https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_disable + * @see https://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_disable */ public function onDisable() { // stub for possible future use - if (is_callable([$this, 'disable'])) { + if (is_callable(array($this, 'disable'))) { $this->disable(); } } @@ -384,7 +364,7 @@ class CRM_Dataprocessor_Upgrader_Base { public function onUpgrade($op, CRM_Queue_Queue $queue = NULL) { switch ($op) { case 'check': - return [$this->hasPendingRevisions()]; + return array($this->hasPendingRevisions()); case 'enqueue': return $this->enqueuePendingRevisions($queue); diff --git a/info.xml b/info.xml index c1ca2b50caece84c4eb8df9f6ca3fc17b741e36f..5d1ee77a8cff8d7344ec7670d17fcadba7f38e03 100644 --- a/info.xml +++ b/info.xml @@ -28,5 +28,4 @@ <namespace>CRM/Dataprocessor</namespace> <format>23.02.1</format> </civix> - <upgrader>CRM_Dataprocessor_Upgrader</upgrader> </extension>