4 * Collection of upgrade steps
6 class CRM_Wci_Upgrader
extends CRM_Wci_Upgrader_Base
{
8 // By convention, functions that look like "function upgrade_NNNN()" are
9 // upgrade tasks. They are executed in order (like Drupal's hook_update_N).
12 * Example: Run an external SQL script when the module is installed
14 public function install() {
15 $this->executeSqlFile('sql/install.sql');
19 * Example: Run an external SQL script when the module is uninstalled
21 public function uninstall() {
22 $this->executeSqlFile('sql/uninstall.sql');
26 * Example: Run a simple query when a module is enabled
28 public function enable() {
29 CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
33 * Example: Run a simple query when a module is disabled
35 public function disable() {
36 CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
40 * Example: Run a couple simple queries
42 * @return TRUE on success
45 public function upgrade_4200() {
46 $this->ctx->log->info('Applying update 4200');
47 CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"');
48 CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)');
54 * Example: Run an external SQL script
56 * @return TRUE on success
58 public function upgrade_4201() {
59 $this->ctx->log->info('Applying update 4201');
60 // this path is relative to the extension base dir
61 $this->executeSqlFile('sql/upgrade_4201.sql');
67 * Example: Run a slow upgrade process by breaking it up into smaller chunk
69 * @return TRUE on success
71 public function upgrade_4202() {
72 $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
74 $this->addTask(ts('Process first step'), 'processPart1', $arg1, $arg2);
75 $this->addTask(ts('Process second step'), 'processPart2', $arg3, $arg4);
76 $this->addTask(ts('Process second step'), 'processPart3', $arg5);
79 public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
80 public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
81 public function processPart3($arg5) { sleep(10); return TRUE; }
86 * Example: Run an upgrade with a query that touches many (potentially
87 * millions) of records by breaking it up into smaller chunks.
89 * @return TRUE on success
91 public function upgrade_4203() {
92 $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
94 $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
95 $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
96 for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
97 $endId = $startId + self::BATCH_SIZE - 1;
98 $title = ts('Upgrade Batch (%1 => %2)', array(
103 UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
104 WHERE id BETWEEN %1 and %2
107 1 => array($startId, 'Integer'),
108 2 => array($endId, 'Integer'),
110 $this->addTask($title, 'executeSql', $sql, $params);