#29750 on save redirect to lising page
[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_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)');
49 return TRUE;
50 } // */
51
52
53 /**
54 * Example: Run an external SQL script
55 *
56 * @return TRUE on success
57 * @throws Exception
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');
62 return TRUE;
63 } // */
64
65
66 /**
67 * Example: Run a slow upgrade process by breaking it up into smaller chunk
68 *
69 * @return TRUE on success
70 * @throws Exception
71 public function upgrade_4202() {
72 $this->ctx->log->info('Planning update 4202'); // PEAR Log interface
73
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);
77 return TRUE;
78 }
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; }
82 // */
83
84
85 /**
86 * Example: Run an upgrade with a query that touches many (potentially
87 * millions) of records by breaking it up into smaller chunks.
88 *
89 * @return TRUE on success
90 * @throws Exception
91 public function upgrade_4203() {
92 $this->ctx->log->info('Planning update 4203'); // PEAR Log interface
93
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(
99 1 => $startId,
100 2 => $endId,
101 ));
102 $sql = '
103 UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker)
104 WHERE id BETWEEN %1 and %2
105 ';
106 $params = array(
107 1 => array($startId, 'Integer'),
108 2 => array($endId, 'Integer'),
109 );
110 $this->addTask($title, 'executeSql', $sql, $params);
111 }
112 return TRUE;
113 } // */
114
115 }