First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,148 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* The extension manager handles installing, disabling enabling, and
* uninstalling extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Extension_Manager_Base implements CRM_Extension_Manager_Interface {
/**
* @var bool hether to automatically uninstall and install during 'replace'
*/
public $autoReplace;
/**
* @param bool $autoReplace
* Whether to automatically uninstall and install during 'replace'.
*/
public function __construct($autoReplace = FALSE) {
$this->autoReplace = $autoReplace;
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostInstall(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostPostInstall(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostEnable(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostDisable(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreUninstall(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostUninstall(CRM_Extension_Info $info) {
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $oldInfo
* @param CRM_Extension_Info $newInfo
*/
public function onPreReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo) {
if ($this->autoReplace) {
$this->onPreUninstall($oldInfo);
$this->onPostUninstall($oldInfo);
}
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $oldInfo
* @param CRM_Extension_Info $newInfo
*/
public function onPostReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo) {
if ($this->autoReplace) {
$this->onPreInstall($oldInfo);
$this->onPostInstall($oldInfo);
}
}
}

View file

@ -0,0 +1,122 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* The extension manager handles installing, disabling enabling, and
* uninstalling extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
interface CRM_Extension_Manager_Interface {
/**
* Perform type-specific installation logic (before marking the
* extension as installed or clearing the caches).
*
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info);
/**
* Perform type-specific installation logic (after marking the
* extension as installed but before clearing the caches).
*
* @param CRM_Extension_Info $info
*/
public function onPostInstall(CRM_Extension_Info $info);
/**
* Perform type-specific installation logic (after marking the
* extension as installed and clearing the caches).
*
* @param CRM_Extension_Info $info
*/
public function onPostPostInstall(CRM_Extension_Info $info);
/**
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info);
/**
* @param CRM_Extension_Info $info
*/
public function onPostEnable(CRM_Extension_Info $info);
/**
* Perform type-specific removal logic (before updating the extension
* row in the "civicrm_extension" table).
*
* @param CRM_Extension_Info $info
* May be generated from xml or DB (which is lossy).
* @see CRM_Extension_Manager::createInfoFromDB
*/
public function onPreDisable(CRM_Extension_Info $info);
/**
* Perform type-specific removal logic (after updating the extension
* row in the "civicrm_extension" table).
*
* @param CRM_Extension_Info $info
* May be generated from xml or DB (which is lossy).
* @see CRM_Extension_Manager::createInfoFromDB
*/
public function onPostDisable(CRM_Extension_Info $info);
/**
* Perform type-specific removal logic (before removing the extension
* row in the "civicrm_extension" table).
*
* @param CRM_Extension_Info $info
* May be generated from xml or DB (which is lossy).
* @see CRM_Extension_Manager::createInfoFromDB
*/
public function onPreUninstall(CRM_Extension_Info $info);
/**
* Perform type-specific removal logic (after removing the extension
* row in the "civicrm_extension" table).
*
* @param CRM_Extension_Info $info
* May be generated from xml or DB (which is lossy).
* @see CRM_Extension_Manager::createInfoFromDB
*/
public function onPostUninstall(CRM_Extension_Info $info);
/**
* @param CRM_Extension_Info $oldInfo
* @param CRM_Extension_Info $newInfo
*/
public function onPreReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo);
/**
* @param CRM_Extension_Info $oldInfo
* @param CRM_Extension_Info $newInfo
*/
public function onPostReplace(CRM_Extension_Info $oldInfo, CRM_Extension_Info $newInfo);
}

View file

@ -0,0 +1,110 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This class stores logic for managing CiviCRM extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Extension_Manager_Module extends CRM_Extension_Manager_Base {
/**
* @param CRM_Extension_Mapper $mapper
*/
public function __construct(CRM_Extension_Mapper $mapper) {
parent::__construct(FALSE);
$this->mapper = $mapper;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info) {
$this->callHook($info, 'install');
$this->callHook($info, 'enable');
}
/**
* @param CRM_Extension_Info $info
*/
public function onPostPostInstall(CRM_Extension_Info $info) {
$this->callHook($info, 'postInstall');
}
/**
* @param CRM_Extension_Info $info
* @param string $hookName
*/
private function callHook(CRM_Extension_Info $info, $hookName) {
try {
$file = $this->mapper->keyToPath($info->key);
}
catch (CRM_Extension_Exception $e) {
return;
}
if (!file_exists($file)) {
return;
}
include_once $file;
$fnName = "{$info->file}_civicrm_{$hookName}";
if (function_exists($fnName)) {
$fnName();
}
}
/**
* @param CRM_Extension_Info $info
*
* @return bool
*/
public function onPreUninstall(CRM_Extension_Info $info) {
$this->callHook($info, 'uninstall');
return TRUE;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPostUninstall(CRM_Extension_Info $info) {
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
$this->callHook($info, 'disable');
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$this->callHook($info, 'enable');
}
}

View file

@ -0,0 +1,282 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This class stores logic for managing CiviCRM extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Extension_Manager_Payment extends CRM_Extension_Manager_Base {
/**
* @var CRM_Extension_Mapper
*/
protected $mapper;
/**
* @param CRM_Extension_Mapper $mapper
*/
public function __construct(CRM_Extension_Mapper $mapper) {
parent::__construct(TRUE);
$this->mapper = $mapper;
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreInstall(CRM_Extension_Info $info) {
$paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
if (array_key_exists($info->key, $paymentProcessorTypes)) {
CRM_Core_Error::fatal('This payment processor type is already installed.');
}
$ppByName = $this->_getAllPaymentProcessorTypes('name');
if (array_key_exists($info->name, $ppByName)) {
CRM_Core_Error::fatal('This payment processor type already exists.');
}
$dao = new CRM_Financial_DAO_PaymentProcessorType();
$dao->is_active = 1;
$dao->class_name = trim($info->key);
$dao->title = trim($info->name) . ' (' . trim($info->key) . ')';
$dao->name = trim($info->name);
$dao->description = trim($info->description);
$dao->user_name_label = trim($info->typeInfo['userNameLabel']);
$dao->password_label = trim($info->typeInfo['passwordLabel']);
$dao->signature_label = trim($info->typeInfo['signatureLabel']);
$dao->subject_label = trim($info->typeInfo['subjectLabel']);
$dao->url_site_default = trim($info->typeInfo['urlSiteDefault']);
$dao->url_api_default = trim($info->typeInfo['urlApiDefault']);
$dao->url_recur_default = trim($info->typeInfo['urlRecurDefault']);
$dao->url_site_test_default = trim($info->typeInfo['urlSiteTestDefault']);
$dao->url_api_test_default = trim($info->typeInfo['urlApiTestDefault']);
$dao->url_recur_test_default = trim($info->typeInfo['urlRecurTestDefault']);
$dao->url_button_default = trim($info->typeInfo['urlButtonDefault']);
$dao->url_button_test_default = trim($info->typeInfo['urlButtonTestDefault']);
switch (trim($info->typeInfo['billingMode'])) {
case 'form':
$dao->billing_mode = CRM_Core_Payment::BILLING_MODE_FORM;
break;
case 'button':
$dao->billing_mode = CRM_Core_Payment::BILLING_MODE_BUTTON;
break;
case 'notify':
$dao->billing_mode = CRM_Core_Payment::BILLING_MODE_NOTIFY;
break;
default:
CRM_Core_Error::fatal('Billing mode in info file has wrong value.');
}
$dao->is_recur = trim($info->typeInfo['isRecur']);
$dao->payment_type = trim($info->typeInfo['paymentType']);
$dao->save();
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostInstall(CRM_Extension_Info $info) {
$this->_runPaymentHook($info, 'install');
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreUninstall(CRM_Extension_Info $info) {
$paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
if (!array_key_exists($info->key, $paymentProcessorTypes)) {
CRM_Core_Error::fatal('This payment processor type is not registered.');
}
$dao = new CRM_Financial_DAO_PaymentProcessor();
$dao->payment_processor_type_id = $paymentProcessorTypes[$info->key];
$dao->find();
while ($dao->fetch()) {
throw new CRM_Extension_Exception_DependencyException('payment');
}
$this->_runPaymentHook($info, 'uninstall');
return CRM_Financial_BAO_PaymentProcessorType::del($paymentProcessorTypes[$info->key]);
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
// HMM? // if ($this->type == 'payment' && $this->status != 'missing') {
$this->_runPaymentHook($info, 'disable');
$paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessorTypes[$info->key], 0);
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$paymentProcessorTypes = $this->_getAllPaymentProcessorTypes('class_name');
CRM_Financial_BAO_PaymentProcessorType::setIsActive($paymentProcessorTypes[$info->key], 1);
}
/**
* @inheritDoc
*
* @param CRM_Extension_Info $info
*/
public function onPostEnable(CRM_Extension_Info $info) {
// HMM? // if ($this->type == 'payment' && $this->status != 'missing') {
$this->_runPaymentHook($info, 'enable');
}
/**
* @param string $attr
* The attribute used to key the array.
* @return array
* ($attr => $id)
*/
private function _getAllPaymentProcessorTypes($attr) {
$ppt = array();
$dao = new CRM_Financial_DAO_PaymentProcessorType();
$dao->find();
while ($dao->fetch()) {
$ppt[$dao->$attr] = $dao->id;
}
return $ppt;
}
/**
* Run hooks in the payment processor class.
* Load requested payment processor and call the method specified.
*
* @param CRM_Extension_Info $info
* @param string $method
* The method to call in the payment processor class.
*/
private function _runPaymentHook(CRM_Extension_Info $info, $method) {
// Not concerned about performance at this stage, as these are seldom performed tasks
// (payment processor enable/disable/install/uninstall). May wish to implement some
// kind of registry/caching system if more hooks are added.
try {
$paymentClass = $this->mapper->keyToClass($info->key, 'payment');
$file = $this->mapper->classToPath($paymentClass);
if (!file_exists($file)) {
CRM_Core_Session::setStatus(ts('Failed to load file (%3) for payment processor (%1) while running "%2"', array(
1 => $info->key,
2 => $method,
3 => $file,
)), '', 'error');
return;
}
else {
require_once $file;
}
}
catch (CRM_Extension_Exception $e) {
CRM_Core_Session::setStatus(ts('Failed to determine file path for payment processor (%1) while running "%2"', array(
1 => $info->key,
2 => $method,
)), '', 'error');
return;
}
$processorDAO = CRM_Core_DAO::executeQuery(
" SELECT pp.id, ppt.class_name
FROM civicrm_extension ext
INNER JOIN civicrm_payment_processor_type ppt
ON ext.name = ppt.name
LEFT JOIN civicrm_payment_processor pp
ON ppt.id = pp.payment_processor_type_id
WHERE ext.type = 'payment'
AND ext.full_name = %1
",
array(
1 => array($info->key, 'String'),
)
);
while ($processorDAO->fetch()) {
$class_name = $processorDAO->class_name;
$processor_id = $processorDAO->id;
}
if (empty($class_name)) {
CRM_Core_Error::fatal("Unable to find payment processor in " . __CLASS__ . '::' . __METHOD__);
}
// In the case of uninstall, check for instances of PP first.
// Don't run hook if any are found.
if ($method == 'uninstall' && $processor_id > 0) {
return;
}
switch ($method) {
case 'install':
case 'uninstall':
case 'enable':
case 'disable':
// Instantiate PP - the getClass function allows us to do this when no payment processor instances exist.
$processorInstance = Civi\Payment\System::singleton()->getByClass($class_name);
// Does PP implement this method, and can we call it?
if (method_exists($processorInstance, $method) && is_callable(array(
$processorInstance,
$method,
))
) {
// If so, call it ...
$processorInstance->$method();
}
break;
default:
CRM_Core_Session::setStatus(ts("Unrecognized payment hook (%1) in %2::%3",
array(1 => $method, 2 => __CLASS__, 3 => __METHOD__)),
'', 'error');
}
}
}

View file

@ -0,0 +1,140 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This class stores logic for managing CiviCRM extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Extension_Manager_Report extends CRM_Extension_Manager_Base {
const REPORT_GROUP_NAME = 'report_template';
/**
* CRM_Extension_Manager_Report constructor.
*/
public function __construct() {
parent::__construct(TRUE);
$this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
self::REPORT_GROUP_NAME, 'id', 'name'
);
}
/**
* @param CRM_Extension_Info $info
*
* @throws Exception
*/
public function onPreInstall(CRM_Extension_Info $info) {
$customReports = $this->getCustomReportsByName();
if (array_key_exists($info->key, $customReports)) {
CRM_Core_Error::fatal('This report is already registered.');
}
if ($info->typeInfo['component'] === 'Contact') {
$compId = 'null';
}
else {
$comp = CRM_Core_Component::get($info->typeInfo['component']);
$compId = $comp->componentID;
}
if (empty($compId)) {
CRM_Core_Error::fatal("Component for which you're trying to install the extension (" . $info->typeInfo['component'] . ") is currently disabled.");
}
$weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue',
array('option_group_id' => $this->groupId)
);
$ids = array();
$params = array(
'label' => $info->label . ' (' . $info->key . ')',
'value' => $info->typeInfo['reportUrl'],
'name' => $info->key,
'weight' => $weight,
'description' => $info->label . ' (' . $info->key . ')',
'component_id' => $compId,
'option_group_id' => $this->groupId,
'is_active' => 1,
);
$optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
}
/**
* @param CRM_Extension_Info $info
*
* @return bool
*/
public function onPreUninstall(CRM_Extension_Info $info) {
// if( !array_key_exists( $info->key, $this->customReports ) ) {
// CRM_Core_Error::fatal( 'This report is not registered.' );
// }
$customReports = $this->getCustomReportsByName();
$cr = $this->getCustomReportsById();
$id = $cr[$customReports[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::del($id);
return $optionValue ? TRUE : FALSE;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
$customReports = $this->getCustomReportsByName();
$cr = $this->getCustomReportsById();
$id = $cr[$customReports[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0);
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$customReports = $this->getCustomReportsByName();
$cr = $this->getCustomReportsById();
$id = $cr[$customReports[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1);
}
/**
* @return array
*/
public function getCustomReportsByName() {
return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
}
/**
* @return array
*/
public function getCustomReportsById() {
return CRM_Core_OptionGroup::values(self::REPORT_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);
}
}

View file

@ -0,0 +1,133 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* This class stores logic for managing CiviCRM extensions.
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
class CRM_Extension_Manager_Search extends CRM_Extension_Manager_Base {
const CUSTOM_SEARCH_GROUP_NAME = 'custom_search';
/**
* CRM_Extension_Manager_Search constructor.
*/
public function __construct() {
parent::__construct(TRUE);
$this->groupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup',
self::CUSTOM_SEARCH_GROUP_NAME, 'id', 'name'
);
}
/**
* @param CRM_Extension_Info $info
*
* @return bool
* @throws Exception
*/
public function onPreInstall(CRM_Extension_Info $info) {
$customSearchesByName = $this->getCustomSearchesByName();
if (array_key_exists($info->key, $customSearchesByName)) {
CRM_Core_Error::fatal('This custom search is already registered.');
}
$weight = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue',
array('option_group_id' => $this->groupId)
);
$params = array(
'option_group_id' => $this->groupId,
'weight' => $weight,
'description' => $info->label . ' (' . $info->key . ')',
'name' => $info->key,
'value' => max($customSearchesByName) + 1,
'label' => $info->key,
'is_active' => 1,
);
$ids = array();
$optionValue = CRM_Core_BAO_OptionValue::add($params, $ids);
return $optionValue ? TRUE : FALSE;
}
/**
* @param CRM_Extension_Info $info
*
* @return bool
* @throws Exception
*/
public function onPreUninstall(CRM_Extension_Info $info) {
$customSearchesByName = $this->getCustomSearchesByName();
if (!array_key_exists($info->key, $customSearchesByName)) {
CRM_Core_Error::fatal('This custom search is not registered.');
}
$cs = $this->getCustomSearchesById();
$id = $cs[$customSearchesByName[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::del($id);
return TRUE;
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreDisable(CRM_Extension_Info $info) {
$customSearchesByName = $this->getCustomSearchesByName();
$cs = $this->getCustomSearchesById();
$id = $cs[$customSearchesByName[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 0);
}
/**
* @param CRM_Extension_Info $info
*/
public function onPreEnable(CRM_Extension_Info $info) {
$customSearchesByName = $this->getCustomSearchesByName();
$cs = $this->getCustomSearchesById();
$id = $cs[$customSearchesByName[$info->key]];
$optionValue = CRM_Core_BAO_OptionValue::setIsActive($id, 1);
}
/**
* @return array
*/
protected function getCustomSearchesByName() {
return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, TRUE, FALSE, FALSE, NULL, 'name', FALSE, TRUE);
}
/**
* @return array
*/
protected function getCustomSearchesById() {
return CRM_Core_OptionGroup::values(self::CUSTOM_SEARCH_GROUP_NAME, FALSE, FALSE, FALSE, NULL, 'id', FALSE, TRUE);
}
}