Commit | Line | Data |
---|---|---|
bf6a5362 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.6.alpha1 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * Base class for incremental upgrades | |
30 | */ | |
31 | class CRM_Upgrade_Incremental_Base { | |
32 | const BATCH_SIZE = 5000; | |
33 | ||
34 | /** | |
35 | * Verify DB state. | |
36 | * | |
37 | * @param $errors | |
38 | * | |
39 | * @return bool | |
40 | */ | |
41 | public function verifyPreDBstate(&$errors) { | |
42 | return TRUE; | |
43 | } | |
44 | ||
45 | /** | |
46 | * Compute any messages which should be displayed before upgrade. | |
47 | * | |
48 | * Note: This function is called iteratively for each upcoming | |
49 | * revision to the database. | |
50 | * | |
51 | * @param $preUpgradeMessage | |
52 | * @param string $rev | |
53 | * a version number, e.g. '4.8.alpha1', '4.8.beta3', '4.8.0'. | |
54 | * @param null $currentVer | |
55 | */ | |
56 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
57 | } | |
58 | ||
59 | /** | |
60 | * Compute any messages which should be displayed after upgrade. | |
61 | * | |
62 | * @param string $postUpgradeMessage | |
63 | * alterable. | |
64 | * @param string $rev | |
65 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
66 | * @return void | |
67 | */ | |
68 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
69 | } | |
70 | ||
71 | ||
72 | /** | |
73 | * (Queue Task Callback) | |
74 | */ | |
75 | public static function runSql(CRM_Queue_TaskContext $ctx, $rev) { | |
76 | $upgrade = new CRM_Upgrade_Form(); | |
77 | $upgrade->processSQL($rev); | |
78 | ||
79 | return TRUE; | |
80 | } | |
81 | ||
82 | /** | |
83 | * Syntactic sugar for adding a task which (a) is in this class and (b) has | |
84 | * a high priority. | |
85 | * | |
86 | * After passing the $funcName, you can also pass parameters that will go to | |
87 | * the function. Note that all params must be serializable. | |
88 | */ | |
89 | protected function addTask($title, $funcName) { | |
90 | $queue = CRM_Queue_Service::singleton()->load(array( | |
91 | 'type' => 'Sql', | |
92 | 'name' => CRM_Upgrade_Form::QUEUE_NAME, | |
93 | )); | |
94 | ||
95 | $args = func_get_args(); | |
96 | $title = array_shift($args); | |
97 | $funcName = array_shift($args); | |
98 | $task = new CRM_Queue_Task( | |
99 | array(get_class($this), $funcName), | |
100 | $args, | |
101 | $title | |
102 | ); | |
103 | $queue->createItem($task, array('weight' => -1)); | |
104 | } | |
105 | ||
106 | } |