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 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
19 | * This class contains functions for managing extensions | |
20 | */ | |
21 | class CRM_Core_BAO_Extension extends CRM_Core_DAO_Extension { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Fetch object based on array of properties. |
6a488035 | 25 | * |
6a0b768e TO |
26 | * @param array $params |
27 | * (reference ) an assoc array of name/value pairs. | |
28 | * @param array $defaults | |
29 | * (reference ) an assoc array to hold the flattened values. | |
6a488035 | 30 | * |
16b10e64 CW |
31 | * @return CRM_Core_BAO_LocationType|null |
32 | * object on success, null otherwise | |
6a488035 | 33 | */ |
00be9182 | 34 | public static function retrieve(&$params, &$defaults) { |
6a488035 TO |
35 | $extension = new CRM_Core_DAO_Extension(); |
36 | $extension->copyValues($params); | |
37 | if ($extension->find(TRUE)) { | |
38 | CRM_Core_DAO::storeValues($extension, $defaults); | |
39 | return $extension; | |
40 | } | |
41 | return NULL; | |
42 | } | |
43 | ||
44 | /** | |
fe482240 | 45 | * Delete an extension. |
6a488035 | 46 | * |
6a0b768e TO |
47 | * @param int $id |
48 | * Id of the extension to be deleted. | |
6a488035 | 49 | * |
192d36c5 | 50 | * @return mixed |
6a488035 | 51 | */ |
00be9182 | 52 | public static function del($id) { |
6a488035 TO |
53 | $extension = new CRM_Core_DAO_Extension(); |
54 | $extension->id = $id; | |
55 | return $extension->delete(); | |
56 | } | |
57 | ||
58 | /** | |
fe482240 | 59 | * Change the schema version of an extension. |
6a488035 | 60 | * |
5a4f6742 CW |
61 | * @param string $fullName |
62 | * the fully-qualified name (eg "com.example.myextension"). | |
63 | * @param string $schemaVersion | |
192d36c5 | 64 | * |
65 | * @return \CRM_Core_DAO|object | |
6a488035 | 66 | */ |
00be9182 | 67 | public static function setSchemaVersion($fullName, $schemaVersion) { |
6a488035 | 68 | $sql = 'UPDATE civicrm_extension SET schema_version = %1 WHERE full_name = %2'; |
be2fb01f CW |
69 | $params = [ |
70 | 1 => [$schemaVersion, 'String'], | |
71 | 2 => [$fullName, 'String'], | |
72 | ]; | |
6a488035 TO |
73 | return CRM_Core_DAO::executeQuery($sql, $params); |
74 | } | |
75 | ||
76 | /** | |
fe482240 | 77 | * Determine the schema version of an extension. |
6a488035 | 78 | * |
5a4f6742 CW |
79 | * @param string $fullName |
80 | * the fully-qualified name (eg "com.example.myextension"). | |
6a488035 TO |
81 | * @return string |
82 | */ | |
00be9182 | 83 | public static function getSchemaVersion($fullName) { |
6a488035 | 84 | $sql = 'SELECT schema_version FROM civicrm_extension WHERE full_name = %1'; |
be2fb01f CW |
85 | $params = [ |
86 | 1 => [$fullName, 'String'], | |
87 | ]; | |
6a488035 TO |
88 | return CRM_Core_DAO::singleValueQuery($sql, $params); |
89 | } | |
90 | ||
91 | } |