Enabled upgrader and set the latest changes to it.
[com.zyxware.civiwci.git] / CRM / Wci / Upgrader.php
1 <?php
2
3 /**
4 * Collection of upgrade steps
5 */
6 class CRM_Wci_Upgrader extends CRM_Wci_Upgrader_Base {
7
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).
10
11 /**
12 * Example: Run an external SQL script when the module is installed
13 */
14 public function install() {
15 $this->executeSqlFile('sql/install.sql');
16 }
17
18 /**
19 * Example: Run an external SQL script when the module is uninstalled
20 */
21 public function uninstall() {
22 $this->executeSqlFile('sql/uninstall.sql');
23 }
24
25 /**
26 * Example: Run a simple query when a module is enabled
27 *
28 public function enable() {
29 CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 1 WHERE bar = "whiz"');
30 }
31
32 /**
33 * Example: Run a simple query when a module is disabled
34 *
35 public function disable() {
36 CRM_Core_DAO::executeQuery('UPDATE foo SET is_active = 0 WHERE bar = "whiz"');
37 } // */
38
39 /**
40 * Example: Run a couple simple queries
41 *
42 * @return TRUE on success
43 * @throws Exception
44 */
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"
51 AFTER `hide_pbcap`
52 ');
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`
58 ');
59
60 return TRUE;
61 }
62
63
64 /**
65 * Example: Run an external SQL script
66 *
67 * @return TRUE on success
68 * @throws Exception
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');
73 return TRUE;
74 } // */
75
76
77 /**
78 * Example: Run a slow upgrade process by breaking it up into smaller chunk
79 *
80 * @return TRUE on success
81 * @throws Exception
82 public function upgrade_4202() {
83 $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
84
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);
88 return TRUE;
89 }
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; }
93 // */
94
95
96 /**
97 * Example: Run an upgrade with a query that touches many (potentially
98 * millions) of records by breaking it up into smaller chunks.
99 *
100 * @return TRUE on success
101 * @throws Exception
102 public function upgrade_4203() {
103 $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
104
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(
110 1 => $startId,
111 2 => $endId,
112 ));
113 $sql = '
114 UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
115 WHERE id BETWEEN %1 and %2
116 ';
117 $params = array(
118 1 => array($startId, 'Integer'),
119 2 => array($endId, 'Integer'),
120 );
121 $this->addTask($title, 'executeSql', $sql, $params);
122 }
123 return TRUE;
124 } // */
125
126 }