Merge pull request #13689 from eileenmcnaughton/no_record_payment
[civicrm-core.git] / CRM / Core / BAO / Extension.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2019
32 */
33
34 /**
35 * This class contains functions for managing extensions
36 */
37 class CRM_Core_BAO_Extension extends CRM_Core_DAO_Extension {
38
39 /**
40 * Fetch object based on array of properties.
41 *
42 * @param array $params
43 * (reference ) an assoc array of name/value pairs.
44 * @param array $defaults
45 * (reference ) an assoc array to hold the flattened values.
46 *
47 * @return CRM_Core_BAO_LocationType|null
48 * object on success, null otherwise
49 */
50 public static function retrieve(&$params, &$defaults) {
51 $extension = new CRM_Core_DAO_Extension();
52 $extension->copyValues($params);
53 if ($extension->find(TRUE)) {
54 CRM_Core_DAO::storeValues($extension, $defaults);
55 return $extension;
56 }
57 return NULL;
58 }
59
60 /**
61 * Delete an extension.
62 *
63 * @param int $id
64 * Id of the extension to be deleted.
65 *
66 * @return mixed
67 */
68 public static function del($id) {
69 $extension = new CRM_Core_DAO_Extension();
70 $extension->id = $id;
71 return $extension->delete();
72 }
73
74 /**
75 * Change the schema version of an extension.
76 *
77 * @param string $fullName
78 * the fully-qualified name (eg "com.example.myextension").
79 * @param string $schemaVersion
80 *
81 * @return \CRM_Core_DAO|object
82 */
83 public static function setSchemaVersion($fullName, $schemaVersion) {
84 $sql = 'UPDATE civicrm_extension SET schema_version = %1 WHERE full_name = %2';
85 $params = [
86 1 => [$schemaVersion, 'String'],
87 2 => [$fullName, 'String'],
88 ];
89 return CRM_Core_DAO::executeQuery($sql, $params);
90 }
91
92 /**
93 * Determine the schema version of an extension.
94 *
95 * @param string $fullName
96 * the fully-qualified name (eg "com.example.myextension").
97 * @return string
98 */
99 public static function getSchemaVersion($fullName) {
100 $sql = 'SELECT schema_version FROM civicrm_extension WHERE full_name = %1';
101 $params = [
102 1 => [$fullName, 'String'],
103 ];
104 return CRM_Core_DAO::singleValueQuery($sql, $params);
105 }
106
107 }