Merge pull request #16263 from eileenmcnaughton/ids_3
[civicrm-core.git] / CRM / Extension / Upgrades.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 * This class stores logic for managing schema upgrades in CiviCRM extensions.
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 */
18 class CRM_Extension_Upgrades {
19
20 const QUEUE_NAME = 'ext-upgrade';
21
22 /**
23 * Determine whether any extensions have pending upgrades.
24 *
25 * @return bool
26 */
27 public static function hasPending() {
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 /**
41 * Fill a queue with upgrade tasks.
42 *
43 * @return CRM_Queue_Queue
44 */
45 public static function createQueue() {
46 $queue = CRM_Queue_Service::singleton()->create([
47 'type' => 'Sql',
48 'name' => self::QUEUE_NAME,
49 'reset' => TRUE,
50 ]);
51
52 CRM_Utils_Hook::upgrade('enqueue', $queue);
53
54 return $queue;
55 }
56
57 }