Skip to content
Snippets Groups Projects
Unverified Commit 087bb1eb authored by totten's avatar totten Committed by GitHub
Browse files

Merge pull request #21340 from colemanw/upgradeFunctions

[NFC] Cleanup boilerplate code in extension upgrader classes
parents 12a29dde c5e2cc14
Branches
Tags
No related merge requests found
......@@ -6,9 +6,6 @@ use CRM_AfformAdmin_ExtensionUtil as E;
*/
class CRM_AfformAdmin_Upgrader extends CRM_AfformAdmin_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Setup navigation item on new installs.
*
......@@ -52,10 +49,10 @@ class CRM_AfformAdmin_Upgrader extends CRM_AfformAdmin_Upgrader_Base {
/**
* Update menu item
*
* @return TRUE on success
* @return bool
* @throws Exception
*/
public function upgrade_0001() {
public function upgrade_0001(): bool {
$this->ctx->log->info('Applying update 0001');
\Civi\Api4\Navigation::update(FALSE)
->addValue('icon', 'crm-i fa-list-alt')
......
......@@ -9,10 +9,9 @@ class CRM_Afform_Upgrader extends CRM_Afform_Upgrader_Base {
/**
* Update names of blocks and joins
*
* @return TRUE on success
* @throws Exception
* @return bool
*/
public function upgrade_1000() {
public function upgrade_1000(): bool {
$this->ctx->log->info('Applying update 1000');
$scanner = new CRM_Afform_AfformScanner();
$localDir = $scanner->getSiteLocalPath();
......@@ -57,7 +56,7 @@ class CRM_Afform_Upgrader extends CRM_Afform_Upgrader_Base {
* Upgrade 1000 - install civicrm_afform_submission table
* @return bool
*/
public function upgrade_1001() {
public function upgrade_1001(): bool {
$this->ctx->log->info('Applying update 1001 - install civicrm_afform_submission table.');
if (!CRM_Core_DAO::singleValueQuery("SHOW TABLES LIKE 'civicrm_afform_submission'")) {
$this->executeSqlFile('sql/auto_install.sql');
......
......@@ -6,11 +6,8 @@ use CRM_Ckeditor4_ExtensionUtil as E;
*/
class CRM_Ckeditor4_Upgrader extends CRM_Ckeditor4_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* Example: Run an external SQL script when the module is installed.
* Install extension.
*/
public function install() {
CRM_Core_BAO_OptionValue::ensureOptionValueExists([
......@@ -22,25 +19,7 @@ class CRM_Ckeditor4_Upgrader extends CRM_Ckeditor4_Upgrader_Base {
}
/**
* Example: Work with entities usually not available during the install step.
*
* This method can be used for any post-install tasks. For example, if a step
* of your installation depends on accessing an entity that is itself
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*/
// public function postInstall() {
// $customFieldId = civicrm_api3('CustomField', 'getvalue', array(
// 'return' => array("id"),
// 'name' => "customFieldCreatedViaManagedHook",
// ));
// civicrm_api3('Setting', 'create', array(
// 'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
// ));
// }
/**
* Example: Run an external SQL script when the module is uninstalled.
* Uninstall CKEditor settings.
*/
public function uninstall() {
$domains = civicrm_api3('Domain', 'get', ['options' => ['limit' => 0]])['values'];
......@@ -53,95 +32,4 @@ class CRM_Ckeditor4_Upgrader extends CRM_Ckeditor4_Upgrader_Base {
civicrm_api3('OptionValue', 'get', ['name' => 'CKEditor', 'api.option_value.delete' => ['id' => "\$value.id"]]);
}
/**
* Example: Run a simple query when a module is enabled.
*/
// public function enable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
// }
/**
* Example: Run a simple query when a module is disabled.
*/
// public function disable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
// }
/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4200() {
// $this->ctx->log->info('Applying update 4200');
// CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
// CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
// return TRUE;
// }
/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4201() {
// $this->ctx->log->info('Applying update 4201');
// // this path is relative to the extension base dir
// $this->executeSqlFile('sql/upgrade_4201.sql');
// return TRUE;
// }
/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4202() {
// $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
// $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
// $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
// $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
// return TRUE;
// }
// public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
// public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
// public function processPart3($arg5) { sleep(10); return TRUE; }
/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4203() {
// $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
// $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
// $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
// for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
// $endId = $startId + self::BATCH_SIZE - 1;
// $title = E::ts('Upgrade Batch (%1 => %2)', array(
// 1 => $startId,
// 2 => $endId,
// ));
// $sql = '
// UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
// WHERE id BETWEEN %1 and %2
// ';
// $params = array(
// 1 => array($startId, 'Integer'),
// 2 => array($endId, 'Integer'),
// );
// $this->addTask($title, 'executeSql', $sql, $params);
// }
// return TRUE;
// }
}
......@@ -6,9 +6,6 @@ use CRM_OAuth_ExtensionUtil as E;
*/
class CRM_OAuth_Upgrader extends CRM_OAuth_Upgrader_Base {
// By convention, functions that look like "function upgrade_NNNN()" are
// upgrade tasks. They are executed in order (like Drupal's hook_update_N).
/**
* @see CRM_Utils_Hook::install()
*/
......@@ -30,7 +27,7 @@ class CRM_OAuth_Upgrader extends CRM_OAuth_Upgrader_Base {
/**
* Add support for OAuthContactToken
*
* @return bool TRUE on success
* @return bool
* @throws Exception
*/
public function upgrade_0001(): bool {
......@@ -39,127 +36,4 @@ class CRM_OAuth_Upgrader extends CRM_OAuth_Upgrader_Base {
return TRUE;
}
/**
* Example: Run an external SQL script when the module is installed.
*
* public function install() {
* $this->executeSqlFile('sql/myinstall.sql');
* }
*
* /**
* Example: Work with entities usually not available during the install step.
*
* This method can be used for any post-install tasks. For example, if a step
* of your installation depends on accessing an entity that is itself
* created during the installation (e.g., a setting or a managed entity), do
* so here to avoid order of operation problems.
*/
// public function postInstall() {
// $customFieldId = civicrm_api3('CustomField', 'getvalue', array(
// 'return' => array("id"),
// 'name' => "customFieldCreatedViaManagedHook",
// ));
// civicrm_api3('Setting', 'create', array(
// 'myWeirdFieldSetting' => array('id' => $customFieldId, 'weirdness' => 1),
// ));
// }
/**
* Example: Run an external SQL script when the module is uninstalled.
*/
// public function uninstall() {
// $this->executeSqlFile('sql/myuninstall.sql');
// }
/**
* Example: Run a simple query when a module is enabled.
*/
// public function enable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
// }
/**
* Example: Run a simple query when a module is disabled.
*/
// public function disable() {
// CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
// }
/**
* Example: Run a couple simple queries.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4200() {
// $this->ctx->log->info('Applying update 4200');
// CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
// CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
// return TRUE;
// }
/**
* Example: Run an external SQL script.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4201() {
// $this->ctx->log->info('Applying update 4201');
// // this path is relative to the extension base dir
// $this->executeSqlFile('sql/upgrade_4201.sql');
// return TRUE;
// }
/**
* Example: Run a slow upgrade process by breaking it up into smaller chunk.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4202() {
// $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
// $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2);
// $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4);
// $this->addTask(E::ts('Process second step'), 'processPart3', $arg5);
// return TRUE;
// }
// public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
// public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
// public function processPart3($arg5) { sleep(10); return TRUE; }
/**
* Example: Run an upgrade with a query that touches many (potentially
* millions) of records by breaking it up into smaller chunks.
*
* @return TRUE on success
* @throws Exception
*/
// public function upgrade_4203() {
// $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
// $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
// $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
// for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
// $endId = $startId + self::BATCH_SIZE - 1;
// $title = E::ts('Upgrade Batch (%1 => %2)', array(
// 1 => $startId,
// 2 => $endId,
// ));
// $sql = '
// UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
// WHERE id BETWEEN %1 and %2
// ';
// $params = array(
// 1 => array($startId, 'Integer'),
// 2 => array($endId, 'Integer'),
// );
// $this->addTask($title, 'executeSql', $sql, $params);
// }
// return TRUE;
// }
}
......@@ -36,7 +36,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1000 - install schema
* @return bool
*/
public function upgrade_1000() {
public function upgrade_1000(): bool {
$this->ctx->log->info('Applying update 1000 - install schema.');
// For early, early adopters who installed the extension pre-beta
if (!CRM_Core_DAO::singleValueQuery("SHOW TABLES LIKE 'civicrm_search_display'")) {
......@@ -50,7 +50,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1001 - normalize search display column keys
* @return bool
*/
public function upgrade_1001() {
public function upgrade_1001(): bool {
$this->ctx->log->info('Applying update 1001 - normalize search display columns.');
$savedSearches = \Civi\Api4\SavedSearch::get(FALSE)
->addWhere('api_params', 'IS NOT NULL')
......@@ -89,7 +89,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1002 - embellish search display link data
* @return bool
*/
public function upgrade_1002() {
public function upgrade_1002(): bool {
$this->ctx->log->info('Applying update 1002 - embellish search display link data.');
$displays = \Civi\Api4\SearchDisplay::get(FALSE)
->setSelect(['id', 'settings'])
......@@ -115,7 +115,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1003 - update APIv4 join syntax in saved searches
* @return bool
*/
public function upgrade_1003() {
public function upgrade_1003(): bool {
$this->ctx->log->info('Applying 1003 - update APIv4 join syntax in saved searches.');
$savedSearches = \Civi\Api4\SavedSearch::get(FALSE)
->addSelect('id', 'api_params')
......@@ -138,7 +138,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1004 - fix menu permission.
* @return bool
*/
public function upgrade_1004() {
public function upgrade_1004(): bool {
$this->ctx->log->info('Applying update 1004 - fix menu permission.');
CRM_Core_DAO::executeQuery("UPDATE civicrm_navigation SET permission = 'administer CiviCRM data' WHERE url = 'civicrm/admin/search'");
return TRUE;
......@@ -148,7 +148,7 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
* Upgrade 1005 - add acl_bypass column.
* @return bool
*/
public function upgrade_1005() {
public function upgrade_1005(): bool {
$this->ctx->log->info('Applying update 1005 - add acl_bypass column.');
$this->addTask('Add Cancel Button Setting to the Profile', 'addColumn',
'civicrm_search_display', 'acl_bypass', "tinyint DEFAULT 0 COMMENT 'Skip permission checks and ACLs when running this display.'");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment