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_1000() {
46 $this->ctx
->log
->info('Applying update 1000');
47 CRM_Core_DAO
::executeQuery('
48 ALTER TABLE `civicrm_wci_widget`
49 ADD `show_pb_perc` TINYINT(4) NOT NULL DEFAULT "1"
50 COMMENT "show pb in percentage or amount"
53 CRM_Core_DAO
::executeQuery('
54 ALTER TABLE `civicrm_wci_widget`
55 ADD `color_progress_bar_bg` VARCHAR(10) COLLATE utf8_unicode_ci NOT NULL
56 COMMENT "Progress bar background color."
57 AFTER `color_progress_bar`
65 * Example: Run an external SQL script
67 * @return TRUE on success
69 public function upgrade_4201() {
70 $this->ctx->log->info('Applying update 4201');
71 // this path is relative to the extension base dir
72 $this->executeSqlFile('sql/upgrade_4201.sql');
78 * Example: Run a slow upgrade process by breaking it up into smaller chunk
80 * @return TRUE on success
82 public function upgrade_4202() {
83 $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
85 $this->addTask(ts('Process first step'), 'processPart1', $arg1, $arg2);
86 $this->addTask(ts('Process second step'), 'processPart2', $arg3, $arg4);
87 $this->addTask(ts('Process second step'), 'processPart3', $arg5);
90 public function processPart1($arg1, $arg2) { sleep(10); return TRUE; }
91 public function processPart2($arg3, $arg4) { sleep(10); return TRUE; }
92 public function processPart3($arg5) { sleep(10); return TRUE; }
97 * Example: Run an upgrade with a query that touches many (potentially
98 * millions) of records by breaking it up into smaller chunks.
100 * @return TRUE on success
102 public function upgrade_4203() {
103 $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
105 $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM civicrm_contribution');
106 $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM civicrm_contribution');
107 for ($startId = $minId; $startId <= $maxId; $startId += self::BATCH_SIZE) {
108 $endId = $startId + self::BATCH_SIZE - 1;
109 $title = ts('Upgrade Batch (%1 => %2)', array(
114 UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
115 WHERE id BETWEEN %1 and %2
118 1 => array($startId, 'Integer'),
119 2 => array($endId, 'Integer'),
121 $this->addTask($title, 'executeSql', $sql, $params);