Merge pull request #15938 from civicrm/5.20
[civicrm-core.git] / CRM / Core / BAO / Extension.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 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
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 /**
24 * Fetch object based on array of properties.
25 *
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.
30 *
31 * @return CRM_Core_BAO_LocationType|null
32 * object on success, null otherwise
33 */
34 public static function retrieve(&$params, &$defaults) {
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 /**
45 * Delete an extension.
46 *
47 * @param int $id
48 * Id of the extension to be deleted.
49 *
50 * @return mixed
51 */
52 public static function del($id) {
53 $extension = new CRM_Core_DAO_Extension();
54 $extension->id = $id;
55 return $extension->delete();
56 }
57
58 /**
59 * Change the schema version of an extension.
60 *
61 * @param string $fullName
62 * the fully-qualified name (eg "com.example.myextension").
63 * @param string $schemaVersion
64 *
65 * @return \CRM_Core_DAO|object
66 */
67 public static function setSchemaVersion($fullName, $schemaVersion) {
68 $sql = 'UPDATE civicrm_extension SET schema_version = %1 WHERE full_name = %2';
69 $params = [
70 1 => [$schemaVersion, 'String'],
71 2 => [$fullName, 'String'],
72 ];
73 return CRM_Core_DAO::executeQuery($sql, $params);
74 }
75
76 /**
77 * Determine the schema version of an extension.
78 *
79 * @param string $fullName
80 * the fully-qualified name (eg "com.example.myextension").
81 * @return string
82 */
83 public static function getSchemaVersion($fullName) {
84 $sql = 'SELECT schema_version FROM civicrm_extension WHERE full_name = %1';
85 $params = [
86 1 => [$fullName, 'String'],
87 ];
88 return CRM_Core_DAO::singleValueQuery($sql, $params);
89 }
90
91 }