Merge pull request #13689 from eileenmcnaughton/no_record_payment
[civicrm-core.git] / CRM / Core / BAO / Extension.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
6b83d5bd 6 | Copyright CiviCRM LLC (c) 2004-2019 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
6b83d5bd 31 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
32 */
33
34/**
35 * This class contains functions for managing extensions
36 */
37class CRM_Core_BAO_Extension extends CRM_Core_DAO_Extension {
38
39 /**
fe482240 40 * Fetch object based on array of properties.
6a488035 41 *
6a0b768e
TO
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.
6a488035 46 *
16b10e64
CW
47 * @return CRM_Core_BAO_LocationType|null
48 * object on success, null otherwise
6a488035 49 */
00be9182 50 public static function retrieve(&$params, &$defaults) {
6a488035
TO
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 /**
fe482240 61 * Delete an extension.
6a488035 62 *
6a0b768e
TO
63 * @param int $id
64 * Id of the extension to be deleted.
6a488035 65 *
192d36c5 66 * @return mixed
6a488035 67 */
00be9182 68 public static function del($id) {
6a488035
TO
69 $extension = new CRM_Core_DAO_Extension();
70 $extension->id = $id;
71 return $extension->delete();
72 }
73
74 /**
fe482240 75 * Change the schema version of an extension.
6a488035 76 *
5a4f6742
CW
77 * @param string $fullName
78 * the fully-qualified name (eg "com.example.myextension").
79 * @param string $schemaVersion
192d36c5 80 *
81 * @return \CRM_Core_DAO|object
6a488035 82 */
00be9182 83 public static function setSchemaVersion($fullName, $schemaVersion) {
6a488035 84 $sql = 'UPDATE civicrm_extension SET schema_version = %1 WHERE full_name = %2';
be2fb01f
CW
85 $params = [
86 1 => [$schemaVersion, 'String'],
87 2 => [$fullName, 'String'],
88 ];
6a488035
TO
89 return CRM_Core_DAO::executeQuery($sql, $params);
90 }
91
92 /**
fe482240 93 * Determine the schema version of an extension.
6a488035 94 *
5a4f6742
CW
95 * @param string $fullName
96 * the fully-qualified name (eg "com.example.myextension").
6a488035
TO
97 * @return string
98 */
00be9182 99 public static function getSchemaVersion($fullName) {
6a488035 100 $sql = 'SELECT schema_version FROM civicrm_extension WHERE full_name = %1';
be2fb01f
CW
101 $params = [
102 1 => [$fullName, 'String'],
103 ];
6a488035
TO
104 return CRM_Core_DAO::singleValueQuery($sql, $params);
105 }
106
107}