Merge pull request #23939 from civicrm/5.51
[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 * Retrieve DB object and copy to defaults array.
25 *
26 * @param array $params
27 * Array of criteria values.
28 * @param array $defaults
29 * Array to be populated with found values.
30 *
31 * @return self|null
32 * The DAO object, if found.
33 *
34 * @deprecated
35 */
36 public static function retrieve($params, &$defaults) {
37 return self::commonRetrieve(self::class, $params, $defaults);
38 }
39
40 /**
41 * Delete an extension.
42 *
43 * @param int $id
44 * Id of the extension to be deleted.
45 *
46 * @return mixed
47 */
48 public static function del($id) {
49 $extension = new CRM_Core_DAO_Extension();
50 $extension->id = $id;
51 return $extension->delete();
52 }
53
54 /**
55 * Change the schema version of an extension.
56 *
57 * @param string $fullName
58 * the fully-qualified name (eg "com.example.myextension").
59 * @param string $schemaVersion
60 *
61 * @return \CRM_Core_DAO|object
62 */
63 public static function setSchemaVersion($fullName, $schemaVersion) {
64 $sql = 'UPDATE civicrm_extension SET schema_version = %1 WHERE full_name = %2';
65 $params = [
66 1 => [$schemaVersion, 'String'],
67 2 => [$fullName, 'String'],
68 ];
69 return CRM_Core_DAO::executeQuery($sql, $params);
70 }
71
72 /**
73 * Determine the schema version of an extension.
74 *
75 * @param string $fullName
76 * the fully-qualified name (eg "com.example.myextension").
77 * @return string
78 */
79 public static function getSchemaVersion($fullName) {
80 $sql = 'SELECT schema_version FROM civicrm_extension WHERE full_name = %1';
81 $params = [
82 1 => [$fullName, 'String'],
83 ];
84 return CRM_Core_DAO::singleValueQuery($sql, $params);
85 }
86
87 }