comment fixes
[civicrm-core.git] / CRM / Upgrade / Incremental / Base.php
CommitLineData
bf6a5362
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7.alpha1 |
bf6a5362
CW
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 */
31class 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.
bf6a5362
CW
66 */
67 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
68 }
69
70
71 /**
72 * (Queue Task Callback)
73 */
74 public static function runSql(CRM_Queue_TaskContext $ctx, $rev) {
75 $upgrade = new CRM_Upgrade_Form();
76 $upgrade->processSQL($rev);
77
78 return TRUE;
79 }
80
81 /**
82 * Syntactic sugar for adding a task which (a) is in this class and (b) has
83 * a high priority.
84 *
85 * After passing the $funcName, you can also pass parameters that will go to
86 * the function. Note that all params must be serializable.
87 */
88 protected function addTask($title, $funcName) {
89 $queue = CRM_Queue_Service::singleton()->load(array(
90 'type' => 'Sql',
91 'name' => CRM_Upgrade_Form::QUEUE_NAME,
92 ));
93
94 $args = func_get_args();
95 $title = array_shift($args);
96 $funcName = array_shift($args);
97 $task = new CRM_Queue_Task(
98 array(get_class($this), $funcName),
99 $args,
100 $title
101 );
102 $queue->createItem($task, array('weight' => -1));
103 }
104
058b8a5e
CW
105 /**
106 * Remove a payment processor if not in use
107 *
87a33a95
CW
108 * @param CRM_Queue_TaskContext $ctx
109 * @param string $name
110 * @return bool
058b8a5e
CW
111 * @throws \CiviCRM_API3_Exception
112 */
87a33a95 113 public static function removePaymentProcessorType(CRM_Queue_TaskContext $ctx, $name) {
058b8a5e
CW
114 $processors = civicrm_api3('PaymentProcessor', 'getcount', array('payment_processor_type_id' => $name));
115 if (empty($processors['result'])) {
116 $result = civicrm_api3('PaymentProcessorType', 'get', array(
117 'name' => $name,
118 'return' => 'id',
119 ));
120 if (!empty($result['id'])) {
121 civicrm_api3('PaymentProcessorType', 'delete', array('id' => $result['id']));
122 }
123 }
87a33a95 124 return TRUE;
058b8a5e
CW
125 }
126
bf6a5362 127}