Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * This class stores logic for managing schema upgrades in CiviCRM extensions. | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
17 | */ |
18 | class CRM_Extension_Upgrades { | |
19 | ||
20 | const QUEUE_NAME = 'ext-upgrade'; | |
21 | ||
22 | /** | |
fe482240 | 23 | * Determine whether any extensions have pending upgrades. |
6a488035 TO |
24 | * |
25 | * @return bool | |
26 | */ | |
00be9182 | 27 | public static function hasPending() { |
6a488035 TO |
28 | $checks = CRM_Utils_Hook::upgrade('check'); |
29 | if (is_array($checks)) { | |
30 | foreach ($checks as $check) { | |
31 | if ($check) { | |
32 | return TRUE; | |
33 | } | |
34 | } | |
35 | } | |
36 | ||
37 | return FALSE; | |
38 | } | |
39 | ||
40 | /** | |
fe482240 | 41 | * Fill a queue with upgrade tasks. |
6a488035 TO |
42 | * |
43 | * @return CRM_Queue_Queue | |
44 | */ | |
00be9182 | 45 | public static function createQueue() { |
be2fb01f | 46 | $queue = CRM_Queue_Service::singleton()->create([ |
6a488035 TO |
47 | 'type' => 'Sql', |
48 | 'name' => self::QUEUE_NAME, | |
49 | 'reset' => TRUE, | |
be2fb01f | 50 | ]); |
6a488035 TO |
51 | |
52 | CRM_Utils_Hook::upgrade('enqueue', $queue); | |
53 | ||
54 | return $queue; | |
55 | } | |
56 | ||
57 | } |