getRevisions(); $currentRevision = $this->getCurrentRevision(); if (empty($revisions)) { return FALSE; } if (empty($currentRevision)) { return TRUE; } return ($currentRevision < max($revisions)); } /** * Add any pending revisions to the queue. */ public function enqueuePendingRevisions() { $currentRevision = $this->getCurrentRevision(); foreach ($this->getRevisions() as $revision) { if ($revision > $currentRevision) { $title = ts('Upgrade %1 to revision %2', [ 1 => $this->getExtensionKey(), 2 => $revision, ]); // note: don't use addTask() because it sets weight=-1 $this->appendTask($title, 'upgrade_' . $revision); $this->appendTask($title, 'setCurrentRevision', $revision); } } } /** * Get a list of revisions. * * @return array * revisionNumbers sorted numerically */ public function getRevisions() { if (!is_array($this->revisions)) { $this->revisions = []; $clazz = new \ReflectionClass(get_class($this)); $methods = $clazz->getMethods(); foreach ($methods as $method) { if (preg_match('/^upgrade_(.*)/', $method->name, $matches)) { $this->revisions[] = $matches[1]; } } sort($this->revisions, SORT_NUMERIC); } return $this->revisions; } public function getCurrentRevision() { $revision = CRM_Core_BAO_Extension::getSchemaVersion($this->getExtensionKey()); if (!$revision) { $revision = $this->getCurrentRevisionDeprecated(); } return $revision; } private function getCurrentRevisionDeprecated() { $key = $this->getExtensionKey() . ':version'; if ($revision = \Civi::settings()->get($key)) { $this->revisionStorageIsDeprecated = TRUE; } return $revision; } public function setCurrentRevision($revision) { CRM_Core_BAO_Extension::setSchemaVersion($this->getExtensionKey(), $revision); // clean up legacy schema version store (CRM-19252) $this->deleteDeprecatedRevision(); return TRUE; } private function deleteDeprecatedRevision() { if ($this->revisionStorageIsDeprecated) { $setting = new \CRM_Core_BAO_Setting(); $setting->name = $this->getExtensionKey() . ':version'; $setting->delete(); CRM_Core_Error::debug_log_message("Migrated extension schema revision ID for {$this->getExtensionKey()} from civicrm_setting (deprecated) to civicrm_extension.\n"); } } }