From de598564ea6643adb2e71106d77964faee700c25 Mon Sep 17 00:00:00 2001
From: Paul Rooney
' . ts('(bottom of page)');
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Form/Search.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Form/Search.php
index ac4404ca6de..0c2ce4dbf53 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Form/Search.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Form/Search.php
@@ -200,9 +200,9 @@ public function buildQuickForm() {
'id' => $this->_ssID,
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
];
- $this->assign_by_ref('savedSearch', $savedSearchValues);
- $this->assign('ssID', $this->_ssID);
}
+ $this->assign('savedSearch', $savedSearchValues ?? NULL);
+ $this->assign('ssID', $this->_ssID);
$this->addTaskMenu($tasks);
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Import/Parser/Participant.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Import/Parser/Participant.php
index a60fba680ba..26679da9364 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Import/Parser/Participant.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Event/Import/Parser/Participant.php
@@ -295,7 +295,7 @@ public function import($onDuplicate, &$values) {
else {
$eventTitle = $params['event_title'];
$params['participant_role_id'] = CRM_Core_DAO::singleValueQuery('SELECT default_role_id FROM civicrm_event WHERE title = %1', [
- 1 => [$eventTitle, 'String']
+ 1 => [$eventTitle, 'String'],
]);
}
}
@@ -551,7 +551,7 @@ protected function formatValues(&$values, $params) {
return civicrm_api3_create_error("Event ID is not valid: $value");
}
$svq = CRM_Core_DAO::singleValueQuery('SELECT id FROM civicrm_event WHERE id = %1', [
- 1 => [$value, 'Integer']
+ 1 => [$value, 'Integer'],
]);
if (!$svq) {
return civicrm_api3_create_error("Invalid Event ID: There is no event record with event_id = $value.");
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Export/BAO/Export.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Export/BAO/Export.php
index 3f0f57a3fc2..c713eb8ade4 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Export/BAO/Export.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Export/BAO/Export.php
@@ -247,7 +247,6 @@ public static function invoke() {
if ($parserClass[0] == 'CRM' &&
count($parserClass) >= 3
) {
- require_once str_replace('_', DIRECTORY_SEPARATOR, $parserName) . ".php";
// ensure the functions exists
if (method_exists($parserName, 'errorFileName') &&
method_exists($parserName, 'saveFileName')
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Browser.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Browser.php
index 62d1b25bf99..42fe8fa5747 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Browser.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Browser.php
@@ -40,6 +40,25 @@ class CRM_Extension_Browser {
// timeout for when the connection or the server is slow
const CHECK_TIMEOUT = 5;
+ /**
+ * @var GuzzleHttp\Client
+ */
+ protected $guzzleClient;
+
+ /**
+ * @return \GuzzleHttp\Client
+ */
+ public function getGuzzleClient(): \GuzzleHttp\Client {
+ return $this->guzzleClient ?? new \GuzzleHttp\Client();
+ }
+
+ /**
+ * @param \GuzzleHttp\Client $guzzleClient
+ */
+ public function setGuzzleClient(\GuzzleHttp\Client $guzzleClient) {
+ $this->guzzleClient = $guzzleClient;
+ }
+
/**
* @param string $repoUrl
* URL of the remote repository.
@@ -219,31 +238,23 @@ private function grabCachedJson() {
* @throws \CRM_Extension_Exception
*/
private function grabRemoteJson() {
-
- ini_set('default_socket_timeout', self::CHECK_TIMEOUT);
set_error_handler(array('CRM_Extension_Browser', 'downloadError'));
- if (!ini_get('allow_url_fopen')) {
- ini_set('allow_url_fopen', 1);
- }
-
if (FALSE === $this->getRepositoryUrl()) {
// don't check if the user has configured civi not to check an external
// url for extensions. See CRM-10575.
- return [];
+ return '';
}
$filename = $this->cacheDir . DIRECTORY_SEPARATOR . self::CACHE_JSON_FILE . '.' . md5($this->getRepositoryUrl());
$url = $this->getRepositoryUrl() . $this->indexPath;
- $status = CRM_Utils_HttpClient::singleton()->fetch($url, $filename);
-
- ini_restore('allow_url_fopen');
- ini_restore('default_socket_timeout');
+ $client = $this->getGuzzleClient();
+ $response = $client->request('GET', $url, ['sink' => $filename, 'timeout' => \Civi::settings()->get('http_timeout')]);
restore_error_handler();
- if ($status !== CRM_Utils_HttpClient::STATUS_OK) {
- throw new CRM_Extension_Exception(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests. Contact your site administrator for assistance.', [1 => $this->getRepositoryUrl()]), 'connection_error');
+ if ($response->getStatusCode() !== 200) {
+ throw new CRM_Extension_Exception(ts('The CiviCRM public extensions directory at %1 could not be contacted - please check your webserver can make external HTTP requests', [1 => $this->getRepositoryUrl()]), 'connection_error');
}
// Don't call grabCachedJson here, that would risk infinite recursion
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Downloader.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Downloader.php
index db85f4248ce..4b472267af6 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Downloader.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Extension/Downloader.php
@@ -16,6 +16,26 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
class CRM_Extension_Downloader {
+
+ /**
+ * @var GuzzleHttp\Client
+ */
+ protected $guzzleClient;
+
+ /**
+ * @return \GuzzleHttp\Client
+ */
+ public function getGuzzleClient(): \GuzzleHttp\Client {
+ return $this->guzzleClient ?? new \GuzzleHttp\Client();
+ }
+
+ /**
+ * @param \GuzzleHttp\Client $guzzleClient
+ */
+ public function setGuzzleClient(\GuzzleHttp\Client $guzzleClient) {
+ $this->guzzleClient = $guzzleClient;
+ }
+
/**
* @var CRM_Extension_Container_Basic
* The place where downloaded extensions are ultimately stored
@@ -136,14 +156,12 @@ public function download($key, $downloadUrl) {
* Whether the download was successful.
*/
public function fetch($remoteFile, $localFile) {
- $result = CRM_Utils_HttpClient::singleton()->fetch($remoteFile, $localFile);
- switch ($result) {
- case CRM_Utils_HttpClient::STATUS_OK:
- return TRUE;
-
- default:
- return FALSE;
+ $client = $this->getGuzzleClient();
+ $response = $client->request('GET', $remoteFile, ['sink' => $localFile, 'timeout' => \Civi::settings()->get('http_timeout')]);
+ if ($response->getStatusCode() === 200) {
+ return TRUE;
}
+ return FALSE;
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php
index b7320514ac0..07198cb1493 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialAccount.php
@@ -14,26 +14,23 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAccount implements \Civi\Test\HookInterface {
+class CRM_Financial_BAO_FinancialAccount extends CRM_Financial_DAO_FinancialAccount implements \Civi\Core\HookInterface {
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Financial_BAO_FinancialAccount
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults = []) {
- $financialAccount = new CRM_Financial_DAO_FinancialAccount();
- $financialAccount->copyValues($params);
- if ($financialAccount->find(TRUE)) {
- CRM_Core_DAO::storeValues($financialAccount, $defaults);
- return $financialAccount;
- }
- return NULL;
+ public static function retrieve($params, &$defaults = []) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialItem.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialItem.php
index 15879bd854d..a5a0182cace 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialItem.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialItem.php
@@ -17,23 +17,20 @@
class CRM_Financial_BAO_FinancialItem extends CRM_Financial_DAO_FinancialItem {
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Financial_DAO_FinancialItem
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $financialItem = new CRM_Financial_DAO_FinancialItem();
- $financialItem->copyValues($params);
- if ($financialItem->find(TRUE)) {
- CRM_Core_DAO::storeValues($financialItem, $defaults);
- return $financialItem;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialType.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialType.php
index 2b3d81f5ece..fa9c0e9ee29 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialType.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/FinancialType.php
@@ -17,7 +17,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType implements \Civi\Test\HookInterface {
+class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType implements \Civi\Core\HookInterface {
/**
* Static cache holder of available financial types for this session
@@ -32,23 +32,20 @@ class CRM_Financial_BAO_FinancialType extends CRM_Financial_DAO_FinancialType im
public static $_statusACLFt = [];
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Financial_DAO_FinancialType
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $financialType = new CRM_Financial_DAO_FinancialType();
- $financialType->copyValues($params);
- if ($financialType->find(TRUE)) {
- CRM_Core_DAO::storeValues($financialType, $defaults);
- return $financialType;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
@@ -299,7 +296,7 @@ public static function getAvailableFinancialTypes(&$financialTypes = NULL, $acti
*/
public static function getAvailableMembershipTypes(&$membershipTypes = NULL, $action = CRM_Core_Action::VIEW) {
if (empty($membershipTypes)) {
- $membershipTypes = CRM_Member_PseudoConstant::membershipType();
+ $membershipTypes = CRM_Member_BAO_Membership::buildOptions('membership_type_id');
}
if (!self::isACLFinancialTypeStatus()) {
return $membershipTypes;
@@ -346,27 +343,21 @@ public static function addACLClausesToWhereClauses(&$whereClauses) {
* @param string $component
* the type of component
*
+ * @deprecated
+ *
* @return string $clauses
*/
public static function buildPermissionedClause(string $component): string {
- $clauses = [];
- // @todo the relevant addSelectWhere clause should be called.
- if (!self::isACLFinancialTypeStatus()) {
- return '';
- }
+ CRM_Core_Error::deprecatedFunctionWarning('no alternative');
+ // There are no non-test usages of this function (including in a universe
+ // search).
if ($component === 'contribution') {
$clauses = CRM_Contribute_BAO_Contribution::getSelectWhereClause();
}
if ($component === 'membership') {
- self::getAvailableMembershipTypes($types, CRM_Core_Action::VIEW);
- $types = array_keys($types);
- if (empty($types)) {
- $types = [0];
- }
- $clauses[] = ' civicrm_membership.membership_type_id IN (' . implode(',', $types) . ')';
-
+ $clauses = CRM_Member_BAO_Membership::getSelectWhereClause();
}
- return implode(' AND ', $clauses);
+ return 'AND ' . implode(' AND ', $clauses);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php
index f455c5e7fcd..d7e0ac6f6ed 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessor.php
@@ -18,7 +18,7 @@
/**
* This class contains payment processor related functions.
*/
-class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor implements \Civi\Test\HookInterface {
+class CRM_Financial_BAO_PaymentProcessor extends CRM_Financial_DAO_PaymentProcessor implements \Civi\Core\HookInterface {
/**
* Static holder for the default payment processor
* @var object
@@ -127,26 +127,20 @@ public static function buildOptions($fieldName, $context = NULL, $props = []) {
}
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Financial_DAO_PaymentProcessor|null
- * object on success, null otherwise
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $paymentProcessor = new CRM_Financial_DAO_PaymentProcessor();
- $paymentProcessor->copyValues($params);
- if ($paymentProcessor->find(TRUE)) {
- CRM_Core_DAO::storeValues($paymentProcessor, $defaults);
- return $paymentProcessor;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessorType.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessorType.php
index 62f4cd44a0c..83f0a4491f6 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessorType.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/BAO/PaymentProcessorType.php
@@ -14,7 +14,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentProcessorType implements \Civi\Test\HookInterface {
+class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentProcessorType implements \Civi\Core\HookInterface {
/**
* Static holder for the default payment processor.
@@ -23,24 +23,20 @@ class CRM_Financial_BAO_PaymentProcessorType extends CRM_Financial_DAO_PaymentPr
public static $_defaultPaymentProcessorType = NULL;
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
+ *
+ * @return self|null
+ * The DAO object, if found.
*
- * @return CRM_Core_BAO_LocationType|null
- * object on success, null otherwise
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $paymentProcessorType = new CRM_Financial_DAO_PaymentProcessorType();
- $paymentProcessorType->copyValues($params);
- if ($paymentProcessorType->find(TRUE)) {
- CRM_Core_DAO::storeValues($paymentProcessorType, $defaults);
- return $paymentProcessorType;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Form/FrontEndPaymentFormTrait.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Form/FrontEndPaymentFormTrait.php
index 4ae5d30baca..1012464b68d 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Form/FrontEndPaymentFormTrait.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Form/FrontEndPaymentFormTrait.php
@@ -185,7 +185,7 @@ protected function addPaymentProcessorFieldsToForm() {
$optAttributes = [];
foreach ($paymentProcessors as $ppKey => $ppval) {
if ($ppKey > 0) {
- $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower($this->_paymentProcessors[$ppKey]['payment_processor_type']);
+ $optAttributes[$ppKey]['class'] = 'payment_processor_' . strtolower(CRM_Utils_String::munge($this->_paymentProcessors[$ppKey]['payment_processor_type'], '-'));
}
else {
$optAttributes[$ppKey]['class'] = 'payment_processor_paylater';
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Page/AJAX.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Page/AJAX.php
index 1218a53bf4d..66d65ee1dce 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Page/AJAX.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Financial/Page/AJAX.php
@@ -357,10 +357,10 @@ public static function getFinancialTransactionsList() {
$row[$financialItem->id][$columnKey] = $row[$financialItem->id][$columnKey] . $checkNumber;
}
}
- elseif ($columnKey == 'amount' && $financialItem->$columnKey) {
- $row[$financialItem->id][$columnKey] = CRM_Utils_Money::format($financialItem->$columnKey, $financialItem->currency);
+ elseif ($columnKey === 'amount' && $financialItem->$columnKey) {
+ $row[$financialItem->id][$columnKey] = Civi::format()->money($financialItem->$columnKey, $financialItem->currency);
}
- elseif ($columnKey == 'transaction_date' && $financialItem->$columnKey) {
+ elseif ($columnKey === 'transaction_date' && $financialItem->$columnKey) {
$row[$financialItem->id][$columnKey] = CRM_Utils_Date::customFormat($financialItem->$columnKey);
}
elseif ($columnKey == 'receive_date' && $financialItem->$columnKey) {
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Friend/BAO/Friend.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Friend/BAO/Friend.php
index 216242af2e8..8e92204caa2 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Friend/BAO/Friend.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Friend/BAO/Friend.php
@@ -45,23 +45,20 @@ public static function add(&$params) {
}
/**
- * Given the list of params in the params array, fetch the object
- * and store the values in the values array
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * Input parameters to find object.
- * @param array $values
- * Output values of the object.
+ * Array of criteria values.
+ * @param array $defaults
+ * Array to be populated with found values.
+ *
+ * @return self|null
+ * The DAO object, if found.
*
- * @return array
- * values
+ * @deprecated
*/
- public static function retrieve(&$params, &$values) {
- $friend = new CRM_Friend_DAO_Friend();
- $friend->copyValues($params);
- $friend->find(TRUE);
- CRM_Core_DAO::storeValues($friend, $values);
- return $values;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Logging/ReportDetail.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Logging/ReportDetail.php
index 36404cf1d54..e026f3d4adb 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Logging/ReportDetail.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Logging/ReportDetail.php
@@ -477,7 +477,7 @@ public function getLimit($rowCount = self::ROW_COUNT_LIMIT) {
* @return string
*/
private function convertForeignKeyValuesToLabels(string $fkClassName, string $field, int $keyval): string {
- if (property_exists($fkClassName, '_labelField')) {
+ if ($fkClassName::$_labelField) {
$labelValue = CRM_Core_DAO::getFieldValue($fkClassName, $keyval, $fkClassName::$_labelField);
// Not sure if this should use ts - there's not a lot of context (`%1 (id: %2)`) - and also the similar field labels above don't use ts.
return "{$labelValue} (id: {$keyval})";
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Mailing.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Mailing.php
index 158d6f0e37d..83ddc6dad59 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Mailing.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Mailing.php
@@ -14,6 +14,9 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
+
+use Civi\API\Exception\UnauthorizedException;
+
require_once 'Mail/mime.php';
/**
@@ -79,20 +82,6 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
*/
private $_domain = NULL;
- /**
- * @deprecated
- *
- * @param int $mailingID
- *
- * @return int
- */
- public static function getRecipientsCount($mailingID) {
- //rebuild the recipients
- self::getRecipients($mailingID);
-
- return civicrm_api3('MailingRecipients', 'getcount', ['mailing_id' => $mailingID]);
- }
-
/**
* This function retrieve recipients of selected mailing groups.
*
@@ -140,7 +129,7 @@ public static function getRecipients($mailingID) {
return;
}
- list($location_filter, $order_by) = self::getLocationFilterAndOrderBy($mailingObj->email_selection_method, $mailingObj->location_type_id);
+ [$location_filter, $order_by] = self::getLocationFilterAndOrderBy($mailingObj->email_selection_method, $mailingObj->location_type_id);
// get all the saved searches AND hierarchical groups
// and load them in the cache
@@ -297,7 +286,7 @@ public static function getRecipients($mailingID) {
->execute();
}
- list($aclFrom, $aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause();
+ [$aclFrom, $aclWhere] = CRM_Contact_BAO_Contact_Permission::cacheClause();
// clear all the mailing recipients before populating
CRM_Core_DAO::executeQuery(' DELETE FROM civicrm_mailing_recipients WHERE mailing_id = %1 ', [
@@ -427,6 +416,73 @@ public static function getLocationFilterAndOrderBy($email_selection_method, $loc
return [$location_filter, $orderBy];
}
+ /**
+ * Process parameters to ensure workflow permissions are respected.
+ *
+ * 'schedule mailings' and 'approve mailings' can update certain fields,
+ * but can't create.
+ *
+ * @param array $params
+ *
+ * @return array
+ * @throws \Civi\API\Exception\UnauthorizedException
+ */
+ protected static function processWorkflowPermissions(array $params): array {
+ if (empty($params['id']) && !CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings')) {
+ throw new UnauthorizedException("Cannot create new mailing. Required permission: 'access CiviMail' or 'create mailings'");
+ }
+
+ $safeParams = [];
+ $fieldPerms = CRM_Mailing_BAO_Mailing::getWorkflowFieldPerms();
+ foreach (array_keys($params) as $field) {
+ if (CRM_Core_Permission::check($fieldPerms[$field])) {
+ $safeParams[$field] = $params[$field];
+ }
+ }
+ return $safeParams;
+ }
+
+ /**
+ * Do Submit actions.
+ *
+ * When submitting (as opposed to creating or updating) a mailing it should
+ * be scheduled.
+ *
+ * This function creates the initial job and the recipient list.
+ *
+ * @param array $params
+ * @param \CRM_Mailing_DAO_Mailing $mailing
+ *
+ * @return array
+ */
+ protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing $mailing): array {
+ // Create parent job if not yet created.
+ // Condition on the existence of a scheduled date.
+ if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) {
+ $job = new CRM_Mailing_BAO_MailingJob();
+ $job->mailing_id = $mailing->id;
+ // If we are creating a new Completed mailing (e.g. import from another system) set the job to completed.
+ // Keeping former behaviour when an id is present is precautionary and may warrant reconsideration later.
+ $job->status = ((empty($params['is_completed']) || !empty($params['id'])) ? 'Scheduled' : 'Complete');
+ $job->is_test = 0;
+
+ if (!$job->find(TRUE)) {
+ // Don't schedule job until we populate the recipients.
+ $job->scheduled_date = NULL;
+ $job->save();
+ }
+ // Schedule the job now that it has recipients.
+ $job->scheduled_date = $params['scheduled_date'];
+ $job->save();
+ }
+
+ // Populate the recipients.
+ if (empty($params['_skip_evil_bao_auto_recipients_'])) {
+ self::getRecipients($mailing->id);
+ }
+ return $params;
+ }
+
/**
* Returns the regex patterns that are used for preparing the text and html templates.
*
@@ -558,7 +614,7 @@ private function getPreparedTemplates() {
preg_match_all($patterns[$key], $email, $matches, PREG_PATTERN_ORDER);
foreach ($matches[0] as $idx => $token) {
$preg_token = '/' . preg_quote($token, '/') . '/im';
- list($split_template[], $email) = preg_split($preg_token, $email, 2);
+ [$split_template[], $email] = preg_split($preg_token, $email, 2);
array_push($tokens, $this->getDataFunc($token));
}
if ($email) {
@@ -874,7 +930,7 @@ public static function getVerpAndUrls($job_id, $event_queue_id, $hash, $email) {
$bao->from_name = $bao->from_email = $bao->subject = '';
// use $bao's instance method to get verp and urls
- list($verp, $urls, $_) = $bao->getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email);
+ [$verp, $urls, $_] = $bao->getVerpAndUrlsAndHeaders($job_id, $event_queue_id, $hash, $email);
return [$verp, $urls];
}
@@ -1007,7 +1063,7 @@ public function compose(
$this->_domain = CRM_Core_BAO_Domain::getDomain();
}
- list($verp, $urls, $headers) = $this->getVerpAndUrlsAndHeaders(
+ [$verp, $urls, $headers] = $this->getVerpAndUrlsAndHeaders(
$job_id,
$event_queue_id,
$hash,
@@ -1035,7 +1091,7 @@ public function compose(
}
else {
$params = [['contact_id', '=', $contactId, 0, 0]];
- list($contact) = CRM_Contact_BAO_Query::apiQuery($params);
+ [$contact] = CRM_Contact_BAO_Query::apiQuery($params);
// $contact is an array of [ contactID => contactDetails ]
// also call the hook to get contact details
@@ -1391,6 +1447,7 @@ public function &getGroupNames() {
*
*
* @return CRM_Mailing_DAO_Mailing
+ * @throws \Civi\API\Exception\UnauthorizedException
*/
public static function add(&$params, $ids = []) {
$id = $params['id'] ?? $ids['mailing_id'] ?? NULL;
@@ -1398,13 +1455,11 @@ public static function add(&$params, $ids = []) {
if (empty($params['id']) && !empty($ids)) {
CRM_Core_Error::deprecatedWarning('Parameter $ids is no longer used by Mailing::add. Use the api or just pass $params');
}
-
- if ($id) {
- CRM_Utils_Hook::pre('edit', 'Mailing', $id, $params);
- }
- else {
- CRM_Utils_Hook::pre('create', 'Mailing', NULL, $params);
+ if (!empty($params['check_permissions']) && CRM_Mailing_Info::workflowEnabled()) {
+ $params = self::processWorkflowPermissions($params);
}
+ $action = $id ? 'create' : 'edit';
+ CRM_Utils_Hook::pre($action, 'Mailing', $id, $params);
$mailing = new static();
if ($id) {
@@ -1431,12 +1486,7 @@ public static function add(&$params, $ids = []) {
$result->modified_date = $mailing->modified_date;
}
- if ($id) {
- CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
- }
- else {
- CRM_Utils_Hook::post('create', 'Mailing', $mailing->id, $mailing);
- }
+ CRM_Utils_Hook::post($action, 'Mailing', $mailing->id, $mailing);
return $result;
}
@@ -1455,7 +1505,6 @@ public static function add(&$params, $ids = []) {
*
* - _skip_evil_bao_auto_recipients_: bool
* - _skip_evil_bao_auto_schedule_: bool
- * - _evil_bao_validator_: string|callable
*
*
*
@@ -1470,7 +1519,7 @@ public static function add(&$params, $ids = []) {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public static function create(&$params) {
+ public static function create(array $params) {
// CRM-#1843
// If it is a mass sms, set url_tracking to false
@@ -1589,42 +1638,14 @@ public static function create(&$params) {
// check and attach and files as needed
CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id);
- // If we're going to autosend, then check validity before saving.
- if (empty($params['is_completed']) && !empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && !empty($params['_evil_bao_validator_'])) {
- $cb = Civi\Core\Resolver::singleton()
- ->get($params['_evil_bao_validator_']);
- $errors = call_user_func($cb, $mailing);
- if (!empty($errors)) {
- $fields = implode(',', array_keys($errors));
- throw new CRM_Core_Exception("Mailing cannot be sent. There are missing or invalid fields ($fields).", 'cannot-send', $errors);
- }
- }
-
$transaction->commit();
- // Create parent job if not yet created.
- // Condition on the existence of a scheduled date.
- if (!empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) {
- $job = new CRM_Mailing_BAO_MailingJob();
- $job->mailing_id = $mailing->id;
- // If we are creating a new Completed mailing (e.g. import from another system) set the job to completed.
- // Keeping former behaviour when an id is present is precautionary and may warrant reconsideration later.
- $job->status = ((empty($params['is_completed']) || !empty($params['id'])) ? 'Scheduled' : 'Complete');
- $job->is_test = 0;
-
- if (!$job->find(TRUE)) {
- // Don't schedule job until we populate the recipients.
- $job->scheduled_date = NULL;
- $job->save();
- }
- // Schedule the job now that it has recipients.
- $job->scheduled_date = $params['scheduled_date'];
- $job->save();
- }
-
- // Populate the recipients.
- if (empty($params['_skip_evil_bao_auto_recipients_'])) {
- self::getRecipients($mailing->id);
+ // These actions are really 'submit' not create actions.
+ // In v4 of the api they are not available via CRUD. At some
+ // point we will create a 'submit' function which will do the crud+submit
+ // but for now only CRUD is available via v4 api.
+ if (($params['version'] ?? '') !== 4) {
+ $params = self::doSubmitActions($params, $mailing);
}
return $mailing;
@@ -1633,12 +1654,22 @@ public static function create(&$params) {
/**
* @deprecated
* This is used by CiviMail but will be made redundant by FlexMailer.
- * @param CRM_Mailing_DAO_Mailing $mailing
+ * @param CRM_Mailing_DAO_Mailing|array $mailing
* The mailing which may or may not be sendable.
* @return array
* List of error messages.
*/
public static function checkSendable($mailing) {
+ if (is_array($mailing)) {
+ $params = $mailing;
+ $mailing = new \CRM_Mailing_BAO_Mailing();
+ $mailing->id = $params['id'] ?? NULL;
+ if ($mailing->id) {
+ $mailing->find(TRUE);
+ }
+ $mailing->copyValues($params);
+ }
+
$errors = [];
foreach (['subject', 'name', 'from_name', 'from_email'] as $field) {
if (empty($mailing->{$field})) {
@@ -1997,16 +2028,7 @@ public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
$report['jobs'][] = $row;
}
- $newTableSize = CRM_Mailing_BAO_Recipients::mailingSize($mailing_id);
-
- // we need to do this for backward compatibility, since old mailings did not
- // use the mailing_recipients table
- if ($newTableSize > 0) {
- $report['event_totals']['queue'] = $newTableSize;
- }
- else {
- $report['event_totals']['queue'] = self::getRecipientsCount($mailing_id);
- }
+ $report['event_totals']['queue'] = CRM_Mailing_BAO_Recipients::mailingSize($mailing_id);
if (!empty($report['event_totals']['queue'])) {
$report['event_totals']['delivered_rate'] = (100.0 * $report['event_totals']['delivered']) / $report['event_totals']['queue'];
@@ -2848,7 +2870,7 @@ public static function getContactMailingSelector(&$params) {
CRM_Core_Action::VIEW => [
'name' => ts('View'),
'url' => 'civicrm/mailing/view',
- 'qs' => "reset=1&id=%%mkey%%",
+ 'qs' => "reset=1&id=%%mkey%%&cid=%%cid%%&cs=%%cs%%",
'title' => ts('View Mailing'),
'class' => 'crm-popup',
],
@@ -2872,6 +2894,7 @@ public static function getContactMailingSelector(&$params) {
'mid' => $values['mailing_id'],
'cid' => $params['contact_id'],
'mkey' => $mailingKey,
+ 'cs' => CRM_Contact_BAO_Contact_Utils::generateChecksum($params['contact_id'], NULL, 'inf'),
],
ts('more'),
FALSE,
@@ -2979,8 +3002,16 @@ public static function getWorkflowFieldPerms() {
*/
public static function mailingGroupEntityTables() {
return [
- CRM_Contact_BAO_Group::getTableName() => 'Group',
- CRM_Mailing_BAO_Mailing::getTableName() => 'Mailing',
+ [
+ 'id' => CRM_Contact_BAO_Group::getTableName(),
+ 'name' => 'Group',
+ 'label' => ts('Group'),
+ ],
+ [
+ 'id' => CRM_Mailing_BAO_Mailing::getTableName(),
+ 'name' => 'Mailing',
+ 'label' => ts('Mailing'),
+ ],
];
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/MailingComponent.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/MailingComponent.php
index 006bb3aec85..96d3c8e6240 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/MailingComponent.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/MailingComponent.php
@@ -17,23 +17,20 @@
class CRM_Mailing_BAO_MailingComponent extends CRM_Mailing_DAO_MailingComponent {
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
+ *
+ * @return self|null
+ * The DAO object, if found.
*
- * @return CRM_Core_BAO_LocationType.
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $component = new CRM_Mailing_DAO_MailingComponent();
- $component->copyValues($params);
- if ($component->find(TRUE)) {
- CRM_Core_DAO::storeValues($component, $defaults);
- return $component;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Spool.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Spool.php
index dc88a6fc7a4..b4f3a83bfe4 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Spool.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/BAO/Spool.php
@@ -57,8 +57,7 @@ public function send($recipient, $headers, $body, $job_id = NULL) {
$params['body_html'] = htmlspecialchars($headerStr) . "\n\n" . $body;
$params['subject'] = $headers['Subject'];
$params['name'] = $headers['Subject'];
- $ids = [];
- $mailing = CRM_Mailing_BAO_Mailing::create($params, $ids);
+ $mailing = CRM_Mailing_BAO_Mailing::create($params);
if (empty($mailing) || is_a($mailing, 'CRM_Core_Error')) {
return PEAR::raiseError('Unable to create spooled mailing.');
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/DAO/Mailing.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/DAO/Mailing.php
index eef22e75d75..219a8c99050 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/DAO/Mailing.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/DAO/Mailing.php
@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Mailing/Mailing.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:9815b093c77eedc9aa2c97c338a0e75d)
+ * (GenCodeChecksum:d9992e7d40fdab9d29f2a093e34aa1cb)
*/
/**
@@ -737,7 +737,7 @@ public static function &fields() {
'pseudoconstant' => [
'callback' => 'CRM_Mailing_BAO_Mailing::getTemplateTypeNames',
],
- 'add' => NULL,
+ 'add' => '4.7.16',
],
'template_options' => [
'name' => 'template_options',
@@ -749,7 +749,8 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
- 'add' => NULL,
+ 'serialize' => self::SERIALIZE_JSON,
+ 'add' => '4.7.16',
],
'subject' => [
'name' => 'subject',
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Bounce.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Bounce.php
index cc78d62638f..ba521a47a7f 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Bounce.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Bounce.php
@@ -84,15 +84,13 @@ public static function create(&$params) {
* ID of the mailing.
* @param int $job_id
* Optional ID of a job to filter on.
- * @param bool $is_distinct
- * Group by queue ID?.
*
* @param string|null $toDate
*
* @return int
* Number of rows in result set
*/
- public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE, $toDate = NULL) {
+ public static function getTotalCount($mailing_id, $job_id = NULL, $toDate = NULL) {
$dao = new CRM_Core_DAO();
$bounce = self::getTableName();
@@ -119,10 +117,6 @@ public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct =
$query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
- if ($is_distinct) {
- $query .= " GROUP BY $queue.id ";
- }
-
// query was missing
$dao->query($query);
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Delivered.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Delivered.php
index 481a8e7cd2f..86fa110bd04 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Delivered.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Delivered.php
@@ -61,14 +61,12 @@ public static function &create(&$params) {
* ID of the mailing.
* @param int $job_id
* Optional ID of a job to filter on.
- * @param bool $is_distinct
- * Group by queue ID?.
* @param string $toDate
*
* @return int
* Number of rows in result set
*/
- public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct = FALSE, $toDate = NULL) {
+ public static function getTotalCount($mailing_id, $job_id = NULL, $toDate = NULL) {
$dao = new CRM_Core_DAO();
$delivered = self::getTableName();
@@ -100,10 +98,6 @@ public static function getTotalCount($mailing_id, $job_id = NULL, $is_distinct =
$query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
- if ($is_distinct) {
- $query .= " GROUP BY $queue.id ";
- }
-
// query was missing
$dao->query($query);
@@ -177,10 +171,6 @@ public static function &getRows(
$query .= " AND $job.id = " . CRM_Utils_Type::escape($job_id, 'Integer');
}
- if ($is_distinct) {
- $query .= " GROUP BY $queue.id, $delivered.id";
- }
-
$orderBy = "sort_name ASC, {$delivered}.time_stamp DESC";
if ($sort) {
if (is_string($sort)) {
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Unsubscribe.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Unsubscribe.php
index ecc2b5e3da0..7c393cfec79 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Unsubscribe.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Event/BAO/Unsubscribe.php
@@ -223,7 +223,13 @@ public static function unsub_from_mailing($job_id, $queue_id, $hash, $return = F
CRM_Contact_BAO_GroupContactCache::check(array_merge($groupIds, $baseGroupIds));
}
- $groupsSQL = "
+ /* https://lab.civicrm.org/dev/core/-/issues/3031
+ * When 2 separate tables are referenced in an OR clause the index will be used on one & not the other. At the sql
+ * level we usually deal with this by using UNION to join the 2 queries together - the patch is doing the same thing at
+ * the php level & probably as a result performs better than the original not-that-bad OR clause did & likely similarly to
+ * how a UNION would work.
+ */
+ $groupsCachedSQL = "
SELECT grp.id as group_id,
grp.title as title,
grp.frontend_title as frontend_title,
@@ -231,35 +237,58 @@ public static function unsub_from_mailing($job_id, $queue_id, $hash, $return = F
grp.description as description,
grp.saved_search_id as saved_search_id
FROM civicrm_group grp
- LEFT JOIN civicrm_group_contact gc
- ON gc.group_id = grp.id
- LEFT JOIN civicrm_group_contact_cache gcc
+ LEFT JOIN civicrm_group_contact_cache gcc
ON gcc.group_id = grp.id
WHERE grp.is_hidden = 0
$groupIdClause
AND ((grp.saved_search_id is not null AND gcc.contact_id = %1)
- OR (gc.contact_id = %1
+ $baseGroupClause
+ ) GROUP BY grp.id";
+
+ $groupsAddedSQL = "
+ SELECT grp.id as group_id,
+ grp.title as title,
+ grp.frontend_title as frontend_title,
+ grp.frontend_description as frontend_description,
+ grp.description as description,
+ grp.saved_search_id as saved_search_id
+ FROM civicrm_group grp
+ LEFT JOIN civicrm_group_contact gc
+ ON gc.group_id = grp.id
+ WHERE grp.is_hidden = 0
+ $groupIdClause
+ AND ((gc.contact_id = %1
AND gc.status = 'Added')
$baseGroupClause
) GROUP BY grp.id";
$groupsParams = [
1 => [$contact_id, 'Positive'],
];
- $do = CRM_Core_DAO::executeQuery($groupsSQL, $groupsParams);
+ $doCached = CRM_Core_DAO::executeQuery($groupsCachedSQL, $groupsParams);
+ $doAdded = CRM_Core_DAO::executeQuery($groupsAddedSQL, $groupsParams);
if ($return) {
$returnGroups = [];
- while ($do->fetch()) {
- $returnGroups[$do->group_id] = [
- 'title' => !empty($do->frontend_title) ? $do->frontend_title : $do->title,
- 'description' => !empty($do->frontend_description) ? $do->frontend_description : $do->description,
+ while ($doCached->fetch()) {
+ $returnGroups[$doCached->group_id] = [
+ 'title' => !empty($doCached->frontend_title) ? $doCached->frontend_title : $doCached->title,
+ 'description' => !empty($doCached->frontend_description) ? $doCached->frontend_description : $doCached->description,
+ ];
+ }
+ while ($doAdded->fetch()) {
+ $returnGroups[$doAdded->group_id] = [
+ 'title' => !empty($doAdded->frontend_title) ? $doAdded->frontend_title : $doAdded->title,
+ 'description' => !empty($doAdded->frontend_description) ? $doAdded->frontend_description : $doAdded->description,
];
}
return $returnGroups;
}
else {
- while ($do->fetch()) {
- $groups[$do->group_id] = !empty($do->frontend_title) ? $do->frontend_title : $do->title;
+ while ($doCached->fetch()) {
+ $groups[$doCached->group_id] = !empty($doCached->frontend_title) ? $doCached->frontend_title : $doCached->title;
+ }
+ while ($doAdded->fetch()) {
+ $groups[$doAdded->group_id] = !empty($doAdded->frontend_title) ? $doAdded->frontend_title : $doAdded->title;
}
}
$transaction = new CRM_Core_Transaction();
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Form/Approve.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Form/Approve.php
index ac554fae91c..ff5c6ddfe26 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Form/Approve.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Mailing/Form/Approve.php
@@ -167,7 +167,7 @@ public function postProcess() {
$params['scheduled_date'] = CRM_Utils_Date::processDate($mailing->scheduled_date);
}
- CRM_Mailing_BAO_Mailing::create($params, $ids);
+ CRM_Mailing_BAO_Mailing::create($params);
//when user perform mailing from search context
//redirect it to search result CRM-3711
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/Membership.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/Membership.php
index b6aba091359..6c954d976c8 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/Membership.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/Membership.php
@@ -193,13 +193,11 @@ public static function add(&$params) {
* @param array $values
* Output values of the object.
* @param bool $active
- * Do you want only active memberships to.
- * be returned
+ * Return only memberships with an 'is_current_member' status.
*
- * @return CRM_Member_BAO_Membership|null
- * The found object or null
+ * @return CRM_Member_BAO_Membership[]|null
*/
- public static function &getValues(&$params, &$values, $active = FALSE) {
+ public static function getValues($params, &$values, $active = FALSE) {
if (empty($params)) {
return NULL;
}
@@ -644,7 +642,6 @@ public static function deleteMembership($membershipId, $preserveContrib = FALSE)
$transaction = new CRM_Core_Transaction();
- $results = NULL;
//delete activity record
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
@@ -685,11 +682,11 @@ public static function deleteMembership($membershipId, $preserveContrib = FALSE)
* @param int $ownerMembershipId
* @param int $contactId
*
- * @return null
+ * @return void
*/
public static function deleteRelatedMemberships($ownerMembershipId, $contactId = NULL) {
if (!$ownerMembershipId && !$contactId) {
- return FALSE;
+ return;
}
$membership = new CRM_Member_DAO_Membership();
@@ -715,7 +712,7 @@ public static function deleteRelatedMemberships($ownerMembershipId, $contactId =
* @param string $status
* Active or inactive.
*
- * @return array
+ * @return array|null
* array of memberships based on status
*/
public static function activeMembers($memberships, $status = 'active') {
@@ -2188,13 +2185,12 @@ public function processPriceSet($membershipId, $lineItem) {
* @param bool $all
* if more than one payment associated with membership id need to be returned.
*
- * @return int|int[]
+ * @return int|int[]|null
* contribution id
* @todo we should get this off the line item
*
*/
public static function getMembershipContributionId($membershipId, $all = FALSE) {
-
$membershipPayment = new CRM_Member_DAO_MembershipPayment();
$membershipPayment->membership_id = $membershipId;
if ($all && $membershipPayment->find()) {
@@ -2293,8 +2289,6 @@ public static function updateAllMembershipStatus($params = []) {
AND {$membershipStatusClause}
AND civicrm_membership.owner_membership_id IS NULL ";
- $allMembershipTypes = CRM_Member_BAO_MembershipType::getAllMembershipTypes();
-
$dao2 = CRM_Core_DAO::executeQuery($query, $queryParams);
while ($dao2->fetch()) {
@@ -2302,12 +2296,10 @@ public static function updateAllMembershipStatus($params = []) {
// CRM-7248: added excludeIsAdmin param to the following fn call to prevent moving to admin statuses
//get the membership status as per id.
- $newStatus = civicrm_api3('membership_status', 'calc',
- [
- 'membership_id' => $dao2->membership_id,
- 'ignore_admin_only' => TRUE,
- ], TRUE
- );
+ $newStatus = civicrm_api3('membership_status', 'calc', [
+ 'membership_id' => $dao2->membership_id,
+ 'ignore_admin_only' => TRUE,
+ ]);
$statusId = $newStatus['id'] ?? NULL;
//process only when status change.
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipStatus.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipStatus.php
index 7fa4a1248aa..5f02f8c598e 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipStatus.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipStatus.php
@@ -14,26 +14,23 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus implements \Civi\Test\HookInterface {
+class CRM_Member_BAO_MembershipStatus extends CRM_Member_DAO_MembershipStatus implements \Civi\Core\HookInterface {
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Member_BAO_MembershipStatus
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $membershipStatus = new CRM_Member_DAO_MembershipStatus();
- $membershipStatus->copyValues($params);
- if ($membershipStatus->find(TRUE)) {
- CRM_Core_DAO::storeValues($membershipStatus, $defaults);
- return $membershipStatus;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipType.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipType.php
index 3b77fa2875e..7263f8f3c20 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipType.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/BAO/MembershipType.php
@@ -14,7 +14,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implements \Civi\Test\HookInterface {
+class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implements \Civi\Core\HookInterface {
/**
* Static holder for the default Membership Type.
@@ -25,23 +25,20 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType implem
public static $_membershipTypeInfo = [];
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Member_BAO_MembershipType
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $membershipType = new CRM_Member_DAO_MembershipType();
- $membershipType->copyValues($params);
- if ($membershipType->find(TRUE)) {
- CRM_Core_DAO::storeValues($membershipType, $defaults);
- return $membershipType;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form.php
index a8ffd62a2a9..c1003f62269 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form.php
@@ -159,6 +159,7 @@ public function preProcess() {
$this->assign('context', $this->_context);
$this->assign('membershipMode', $this->_mode);
+ $this->assign('newCredit', CRM_Core_Config::isEnabledBackOfficeCreditCardPayments());
$this->allMembershipTypeDetails = CRM_Member_BAO_Membership::buildMembershipTypeValues($this, [], TRUE);
foreach ($this->allMembershipTypeDetails as $index => $membershipType) {
if ($membershipType['auto_renew']) {
@@ -237,10 +238,8 @@ public function buildQuickForm() {
$this->assign('recurProcessor', json_encode($this->_recurPaymentProcessors));
// Build the form for auto renew. This is displayed when in credit card mode or update mode.
// The reason for showing it in update mode is not that clear.
+ $this->assign('allowAutoRenew', $this->_mode && !empty($this->_recurPaymentProcessors));
if ($this->_mode || ($this->_action & CRM_Core_Action::UPDATE)) {
- if (!empty($this->_recurPaymentProcessors)) {
- $this->assign('allowAutoRenew', TRUE);
- }
$autoRenewElement = $this->addElement('checkbox', 'auto_renew', ts('Membership renewed automatically'),
NULL, ['onclick' => "showHideByValue('auto_renew','','send-receipt','table-row','radio',true); showHideNotice( );"]
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/Membership.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/Membership.php
index 9766a5e3d5a..78f15d79d19 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/Membership.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/Membership.php
@@ -234,7 +234,7 @@ public function preProcess() {
CRM_Core_Error::statusBounce(ts("This Membership is linked to a contribution. You must have 'delete in CiviContribute' permission in order to delete this record."));
}
}
-
+ $mems_by_org = [];
if ($this->_action & CRM_Core_Action::ADD) {
if ($this->_contactID) {
//check whether contact has a current membership so we can alert user that they may want to do a renewal instead
@@ -249,7 +249,6 @@ public function preProcess() {
foreach ($cMemTypes as $memTypeID) {
$memberorgs[$memTypeID] = CRM_Member_BAO_MembershipType::getMembershipType($memTypeID)['member_of_contact_id'];
}
- $mems_by_org = [];
foreach ($contactMemberships as $mem) {
$mem['member_of_contact_id'] = $memberorgs[$mem['membership_type_id']] ?? NULL;
if (!empty($mem['membership_end_date'])) {
@@ -272,7 +271,6 @@ public function preProcess() {
);
$mems_by_org[$mem['member_of_contact_id']] = $mem;
}
- $this->assign('existingContactMemberships', $mems_by_org);
}
}
else {
@@ -287,6 +285,7 @@ public function preProcess() {
$resources->addSetting(['existingMems' => $passthru]);
}
}
+ $this->assign('existingContactMemberships', $mems_by_org);
if (!$this->_memType) {
$params = CRM_Utils_Request::exportValues();
@@ -377,10 +376,7 @@ public function setDefaultValues() {
if (empty($defaults['join_date'])) {
$defaults['join_date'] = CRM_Utils_Time::date('Y-m-d');
}
-
- if (!empty($defaults['membership_end_date'])) {
- $this->assign('endDate', $defaults['membership_end_date']);
- }
+ $this->assign('endDate', $defaults['membership_end_date'] ?? NULL);
return $defaults;
}
@@ -940,12 +936,8 @@ protected function emailReceipt($form, &$formValues) {
}
$form->assign('module', 'Membership');
- $form->assign('contactID', $formValues['contact_id']);
-
- $form->assign('membershipID', $this->getMembershipID());
if (!empty($formValues['contribution_id'])) {
- $form->assign('contributionID', $formValues['contribution_id']);
$form->assign('currency', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $formValues['contribution_id'], 'currency'));
}
else {
@@ -987,16 +979,19 @@ protected function emailReceipt($form, &$formValues) {
CRM_Core_BAO_MessageTemplate::sendTemplate(
[
- 'groupName' => 'msg_tpl_workflow_membership',
- 'valueName' => 'membership_offline_receipt',
- 'contactId' => $form->_receiptContactId,
+ 'workflow' => 'membership_offline_receipt',
'from' => $receiptFrom,
'toName' => $form->_contributorDisplayName,
'toEmail' => $form->_contributorEmail,
'PDFFilename' => ts('receipt') . '.pdf',
'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
- 'contributionId' => $formValues['contribution_id'],
'isTest' => (bool) ($form->_action & CRM_Core_Action::PREVIEW),
+ 'modelProps' => [
+ 'receiptText' => $this->getSubmittedValue('receipt_text'),
+ 'contributionId' => $formValues['contribution_id'],
+ 'contactId' => $form->_receiptContactId,
+ 'membershipId' => $this->getMembershipID(),
+ ],
]
);
@@ -1364,9 +1359,9 @@ public function submit(): void {
if ($this->getSubmittedValue('send_receipt') && $receiptSend) {
$formValues['contact_id'] = $this->_contactID;
$formValues['contribution_id'] = $contributionId;
- // We really don't need a distinct receipt_text_signup vs receipt_text_renewal as they are
- // handled in the receipt. But by setting one we avoid breaking templates for now
- // although at some point we should switch in the templates.
+ // receipt_text_signup is no longer used in receipts from 5.47
+ // but may linger in some sites that have not updated their
+ // templates.
$formValues['receipt_text_signup'] = $formValues['receipt_text'];
// send email receipt
$this->assignBillingName();
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/MembershipRenewal.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
index 03018c8dfd8..dede5c99d5b 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/Form/MembershipRenewal.php
@@ -376,7 +376,7 @@ public function buildQuickForm() {
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
- $this->add('textarea', 'receipt_text_renewal', ts('Renewal Message'));
+ $this->add('textarea', 'receipt_text', ts('Renewal Message'));
// Retrieve the name and email of the contact - this will be the TO for receipt email
list($this->_contributorDisplayName,
@@ -627,7 +627,7 @@ protected function submit() {
'membership_id' => $membership->id,
'contribution_recur_id' => $contributionRecurID,
]);
- CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams);
+ $this->setContributionID(CRM_Member_BAO_Membership::recordMembershipContribution($temporaryParams)->id);
}
if (!empty($this->_params['send_receipt'])) {
@@ -671,9 +671,6 @@ protected function sendReceipt($membership) {
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
$this->assign_by_ref('formValues', $this->_params);
- if (!empty($this->_params['contribution_id'])) {
- $this->assign('contributionID', $this->_params['contribution_id']);
- }
$this->assign('membership_name', CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType',
$membership->membership_type_id
@@ -694,7 +691,6 @@ protected function sendReceipt($membership) {
$this->assign('isAmountzero', 0);
$this->assign('is_pay_later', 0);
$this->assign('isPrimary', 1);
- $this->assign('receipt_text_renewal', $this->_params['receipt_text']);
if ($this->_mode === 'test') {
$this->assign('action', '1024');
}
@@ -702,13 +698,19 @@ protected function sendReceipt($membership) {
list($this->isMailSent) = CRM_Core_BAO_MessageTemplate::sendTemplate(
[
- 'groupName' => 'msg_tpl_workflow_membership',
- 'valueName' => 'membership_offline_receipt',
- 'contactId' => $this->_receiptContactId,
+ 'workflow' => 'membership_offline_receipt',
'from' => $receiptFrom,
'toName' => $this->_contributorDisplayName,
'toEmail' => $this->_contributorEmail,
'isTest' => $this->_mode === 'test',
+ 'PDFFilename' => ts('receipt') . '.pdf',
+ 'isEmailPdf' => Civi::settings()->get('invoice_is_email_pdf'),
+ 'modelProps' => [
+ 'receiptText' => $this->getSubmittedValue('receipt_text'),
+ 'contactId' => $this->_receiptContactId,
+ 'contributionID' => $this->getContributionID(),
+ 'membershipID' => $this->_membershipId,
+ ],
]
);
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php
new file mode 100644
index 00000000000..171fe673c2e
--- /dev/null
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Member/WorkflowMessage/MembershipOfflineReceipt.php
@@ -0,0 +1,36 @@
+membership = $membership;
+ if (!empty($membership['id'])) {
+ $this->membershipId = $membership['id'];
+ }
+ return $this;
+ }
+
+}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/Pledge.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/Pledge.php
index bdc26352bdb..7af5004ce58 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/Pledge.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/Pledge.php
@@ -24,25 +24,20 @@ class CRM_Pledge_BAO_Pledge extends CRM_Pledge_DAO_Pledge {
public static $_exportableFields = NULL;
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
+ *
+ * @return self|null
+ * The DAO object, if found.
*
- * @return CRM_Pledge_BAO_Pledge
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $pledge = new CRM_Pledge_DAO_Pledge();
- $pledge->copyValues($params);
- if ($pledge->find(TRUE)) {
- CRM_Core_DAO::storeValues($pledge, $defaults);
- return $pledge;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgeBlock.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgeBlock.php
index 55d0f4c7f4e..4cea3ce74c7 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgeBlock.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgeBlock.php
@@ -17,25 +17,20 @@
class CRM_Pledge_BAO_PledgeBlock extends CRM_Pledge_DAO_PledgeBlock {
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Pledge_BAO_PledgeBlock
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $pledgeBlock = new CRM_Pledge_DAO_PledgeBlock();
- $pledgeBlock->copyValues($params);
- if ($pledgeBlock->find(TRUE)) {
- CRM_Core_DAO::storeValues($pledgeBlock, $defaults);
- return $pledgeBlock;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgePayment.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgePayment.php
index ebacab842d7..b5097073653 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgePayment.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Pledge/BAO/PledgePayment.php
@@ -171,25 +171,20 @@ public static function add(array $params): CRM_Pledge_DAO_PledgePayment {
}
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
+ *
+ * @return self|null
+ * The DAO object, if found.
*
- * @return CRM_Pledge_BAO_PledgePayment
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- $payment = new CRM_Pledge_BAO_PledgePayment();
- $payment->copyValues($params);
- if ($payment->find(TRUE)) {
- CRM_Core_DAO::storeValues($payment, $defaults);
- return $payment;
- }
- return NULL;
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/LineItem.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/LineItem.php
index ab096b848d4..8251e127601 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/LineItem.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/LineItem.php
@@ -97,25 +97,20 @@ public static function create(&$params) {
}
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Price_BAO_LineItem
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params = [], &$defaults = []) {
- $lineItem = new CRM_Price_BAO_LineItem();
- $lineItem->copyValues($params);
- if ($lineItem->find(TRUE)) {
- CRM_Core_DAO::storeValues($lineItem, $defaults);
- return $lineItem;
- }
- return NULL;
+ public static function retrieve($params, &$defaults = []) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
@@ -1273,4 +1268,19 @@ public static function entityTables(): array {
];
}
+ /**
+ * Add contribution id select where.
+ *
+ * This overrides the parent to PREVENT additional entity_id based
+ * clauses being added. Additional filters joining on the participant
+ * and membership tables just seem too non-performant.
+ *
+ * @inheritDoc
+ */
+ public function addSelectWhereClause(): array {
+ $clauses['contribution_id'] = CRM_Utils_SQL::mergeSubquery('Contribution');
+ CRM_Utils_Hook::selectWhereClause($this, $clauses);
+ return $clauses;
+ }
+
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceField.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceField.php
index bac6d7a1a6e..6726f0b744c 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceField.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceField.php
@@ -168,17 +168,20 @@ public static function create(&$params) {
}
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Price_DAO_PriceField
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceField', $params, $defaults);
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceFieldValue.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceFieldValue.php
index 5df67efec82..ae00626f9f0 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceFieldValue.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceFieldValue.php
@@ -29,15 +29,15 @@ class CRM_Price_BAO_PriceFieldValue extends CRM_Price_DAO_PriceFieldValue {
* @return CRM_Price_DAO_PriceFieldValue
*/
public static function add($params) {
+ $fieldValueBAO = self::writeRecord($params);
+
if (!empty($params['is_default'])) {
$priceFieldID = $params['price_field_id'] ?? CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceFieldValue', $fieldValueBAO->id, 'price_field_id');
- $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1';
- $p = [1 => [$priceFieldID, 'Integer']];
+ $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE price_field_id = %1 and id != %2';
+ $p = [1 => [$priceFieldID, 'Integer'], 2 => [$fieldValueBAO->id, 'Integer']];
CRM_Core_DAO::executeQuery($query, $p);
}
- $fieldValueBAO = self::writeRecord($params);
-
// Reset the cached values in this function.
CRM_Price_BAO_PriceField::getOptions(CRM_Utils_Array::value('price_field_id', $params), FALSE, TRUE);
return $fieldValueBAO;
@@ -105,19 +105,20 @@ public static function getDefaults() {
}
/**
- * Retrieve DB object based on input parameters.
- *
- * It also stores all the retrieved values in the default array.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Price_DAO_PriceFieldValue
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceFieldValue', $params, $defaults);
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceSet.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceSet.php
index 2070e2c9364..acc70725784 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceSet.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/BAO/PriceSet.php
@@ -69,17 +69,20 @@ public static function create(&$params) {
}
/**
- * Fetch object based on array of properties.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
- * (reference ) an assoc array of name/value pairs.
+ * Array of criteria values.
* @param array $defaults
- * (reference ) an assoc array to hold the flattened values.
+ * Array to be populated with found values.
*
- * @return CRM_Price_DAO_PriceSet
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
- public static function retrieve(&$params, &$defaults) {
- return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $defaults);
+ public static function retrieve($params, &$defaults) {
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/Page/Option.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/Page/Option.php
index b3b2f7464a1..3a999008f55 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/Page/Option.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Price/Page/Option.php
@@ -25,6 +25,8 @@
*/
class CRM_Price_Page_Option extends CRM_Core_Page {
+ use CRM_Financial_Form_SalesTaxTrait;
+
public $useLivePageJS = TRUE;
/**
@@ -102,7 +104,7 @@ public static function &actionLinks() {
*
* @return void
*/
- public function browse() {
+ public function browse(): void {
$priceOptions = civicrm_api3('PriceFieldValue', 'get', [
'price_field_id' => $this->_fid,
// Explicitly do not check permissions so we are not
@@ -124,12 +126,8 @@ public function browse() {
$isEvent = TRUE;
}
- $config = CRM_Core_Config::singleton();
$taxRate = CRM_Core_PseudoConstant::getTaxRates();
- // display taxTerm for priceFields
- $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
- $taxTerm = Civi::settings()->get('tax_term');
- $invoicing = $invoiceSettings['invoicing'] ?? NULL;
+
$getTaxDetails = FALSE;
foreach ($customOption as $id => $values) {
$action = array_sum(array_keys(self::actionLinks()));
@@ -137,7 +135,7 @@ public function browse() {
if (isset($taxRate[$values['financial_type_id']])) {
// Cast to float so trailing zero decimals are removed
$customOption[$id]['tax_rate'] = (float) $taxRate[$values['financial_type_id']];
- if ($invoicing && isset($customOption[$id]['tax_rate'])) {
+ if (Civi::settings()->get('invoicing') && isset($customOption[$id]['tax_rate'])) {
$getTaxDetails = TRUE;
}
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']);
@@ -179,11 +177,11 @@ public function browse() {
'id', $returnURL, $filter
);
- $this->assign('taxTerm', $taxTerm);
$this->assign('getTaxDetails', $getTaxDetails);
$this->assign('customOption', $customOption);
$this->assign('sid', $this->_sid);
$this->assign('isEvent', $isEvent);
+ $this->assignSalesTaxTermToTemplate();
}
/**
@@ -228,8 +226,8 @@ public function edit($action) {
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceFieldValue::getOptionLabel($oid));
$this->assign('usedBy', $usedBy);
$comps = [
- "Event" => "civicrm_event",
- "Contribution" => "civicrm_contribution_page",
+ 'Event' => 'civicrm_event',
+ 'Contribution' => 'civicrm_contribution_page',
];
$priceSetContexts = [];
foreach ($comps as $name => $table) {
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/BAO/QueueItem.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/BAO/QueueItem.php
index 3b3f1384693..2051d7b5bbb 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/BAO/QueueItem.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/BAO/QueueItem.php
@@ -25,25 +25,31 @@ class CRM_Queue_BAO_QueueItem extends CRM_Queue_DAO_QueueItem {
/**
* Ensure that the required SQL table exists.
*
+ * The `civicrm_queue_item` table is a special requirement - without it, the upgrader cannot run.
+ * The upgrader will make a special request for `findCreateTable()` before computing upgrade-tasks.
+ *
* @return bool
* TRUE if table now exists
*/
- public static function findCreateTable() {
- $checkTableSql = "show tables like 'civicrm_queue_item'";
- $foundName = CRM_Core_DAO::singleValueQuery($checkTableSql);
- if ($foundName == 'civicrm_queue_item') {
- return TRUE;
+ public static function findCreateTable(): bool {
+ if (!CRM_Core_DAO::checkTableExists('civicrm_queue_item')) {
+ // Table originated in 4.2. We no longer support direct upgrades from <=4.2. Don't bother trying to create table.
+ return FALSE;
}
+ else {
+ return static::updateTable();
+ }
+ }
- // civicrm/sql/civicrm_queue_item.mysql
- $fileName = dirname(__FILE__) . '/../../../sql/civicrm_queue_item.mysql';
-
- $config = CRM_Core_Config::singleton();
- CRM_Utils_File::sourceSQLFile($config->dsn, $fileName);
-
- // Make sure it succeeded
- $foundName = CRM_Core_DAO::singleValueQuery($checkTableSql);
- return ($foundName == 'civicrm_queue_item');
+ /**
+ * Ensure that the `civicrm_queue_item` table is up-to-date.
+ *
+ * @return bool
+ */
+ public static function updateTable(): bool {
+ CRM_Upgrade_Incremental_Base::addColumn(NULL, 'civicrm_queue_item', 'run_count',
+ "int NOT NULL DEFAULT 0 COMMENT 'Number of times execution has been attempted.'");
+ return TRUE;
}
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/Queue.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/Queue.php
index fc5ce93eff8..2d8002f5517 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/Queue.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/Queue.php
@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Queue/Queue.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:5a49f8a2765460d48e4266efa9d447f2)
+ * (GenCodeChecksum:3b50eca7549430727237a4b2e295df1f)
*/
/**
@@ -56,13 +56,49 @@ class CRM_Queue_DAO_Queue extends CRM_Core_DAO {
public $type;
/**
- * Should the standard background attempt to autorun tasks in this queue?
+ * Name of the task runner
*
- * @var bool|string|null
- * (SQL type: tinyint)
+ * @var string
+ * (SQL type: varchar(64))
+ * Note that values will be retrieved from the database as a string.
+ */
+ public $runner;
+
+ /**
+ * Maximum number of items in a batch.
+ *
+ * @var int|string
+ * (SQL type: int unsigned)
+ * Note that values will be retrieved from the database as a string.
+ */
+ public $batch_limit;
+
+ /**
+ * When claiming an item (or batch of items) for work, how long should the item(s) be reserved. (Seconds)
+ *
+ * @var int|string
+ * (SQL type: int unsigned)
+ * Note that values will be retrieved from the database as a string.
+ */
+ public $lease_time;
+
+ /**
+ * Number of permitted retries. Set to zero (0) to disable.
+ *
+ * @var int|string
+ * (SQL type: int)
* Note that values will be retrieved from the database as a string.
*/
- public $is_autorun;
+ public $retry_limit;
+
+ /**
+ * Number of seconds to wait before retrying a failed execution.
+ *
+ * @var int|string
+ * (SQL type: int)
+ * Note that values will be retrieved from the database as a string.
+ */
+ public $retry_interval;
/**
* Class constructor.
@@ -145,21 +181,90 @@ public static function &fields() {
],
'add' => '5.47',
],
- 'is_autorun' => [
- 'name' => 'is_autorun',
- 'type' => CRM_Utils_Type::T_BOOLEAN,
- 'title' => ts('Enable Autorun'),
- 'description' => ts('Should the standard background attempt to autorun tasks in this queue?'),
- 'where' => 'civicrm_queue.is_autorun',
+ 'runner' => [
+ 'name' => 'runner',
+ 'type' => CRM_Utils_Type::T_STRING,
+ 'title' => ts('Runner'),
+ 'description' => ts('Name of the task runner'),
+ 'required' => FALSE,
+ 'maxlength' => 64,
+ 'size' => CRM_Utils_Type::BIG,
+ 'where' => 'civicrm_queue.runner',
'table_name' => 'civicrm_queue',
'entity' => 'Queue',
'bao' => 'CRM_Queue_BAO_Queue',
'localizable' => 0,
'html' => [
- 'type' => 'CheckBox',
- 'label' => ts("Auto Run"),
+ 'type' => 'Text',
+ ],
+ 'add' => '5.48',
+ ],
+ 'batch_limit' => [
+ 'name' => 'batch_limit',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Batch Limit'),
+ 'description' => ts('Maximum number of items in a batch.'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_queue.batch_limit',
+ 'default' => '1',
+ 'table_name' => 'civicrm_queue',
+ 'entity' => 'Queue',
+ 'bao' => 'CRM_Queue_BAO_Queue',
+ 'localizable' => 0,
+ 'html' => [
+ 'type' => 'Text',
+ ],
+ 'add' => '5.48',
+ ],
+ 'lease_time' => [
+ 'name' => 'lease_time',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Lease Time'),
+ 'description' => ts('When claiming an item (or batch of items) for work, how long should the item(s) be reserved. (Seconds)'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_queue.lease_time',
+ 'default' => '3600',
+ 'table_name' => 'civicrm_queue',
+ 'entity' => 'Queue',
+ 'bao' => 'CRM_Queue_BAO_Queue',
+ 'localizable' => 0,
+ 'html' => [
+ 'type' => 'Text',
+ ],
+ 'add' => '5.48',
+ ],
+ 'retry_limit' => [
+ 'name' => 'retry_limit',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Retry Limit'),
+ 'description' => ts('Number of permitted retries. Set to zero (0) to disable.'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_queue.retry_limit',
+ 'default' => '0',
+ 'table_name' => 'civicrm_queue',
+ 'entity' => 'Queue',
+ 'bao' => 'CRM_Queue_BAO_Queue',
+ 'localizable' => 0,
+ 'html' => [
+ 'type' => 'Text',
+ ],
+ 'add' => '5.48',
+ ],
+ 'retry_interval' => [
+ 'name' => 'retry_interval',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Retry Interval'),
+ 'description' => ts('Number of seconds to wait before retrying a failed execution.'),
+ 'required' => FALSE,
+ 'where' => 'civicrm_queue.retry_interval',
+ 'table_name' => 'civicrm_queue',
+ 'entity' => 'Queue',
+ 'bao' => 'CRM_Queue_BAO_Queue',
+ 'localizable' => 0,
+ 'html' => [
+ 'type' => 'Text',
],
- 'add' => NULL,
+ 'add' => '5.48',
],
];
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/QueueItem.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/QueueItem.php
index 7d4979ca957..0ad5fe3be62 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/QueueItem.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/DAO/QueueItem.php
@@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Queue/QueueItem.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:36871610524adb64bc8aa3bb24b295f4)
+ * (GenCodeChecksum:f5163d86b425127deb25d105976212bf)
*/
/**
@@ -71,6 +71,15 @@ class CRM_Queue_DAO_QueueItem extends CRM_Core_DAO {
*/
public $release_time;
+ /**
+ * Number of times execution has been attempted.
+ *
+ * @var int|string
+ * (SQL type: int)
+ * Note that values will be retrieved from the database as a string.
+ */
+ public $run_count;
+
/**
* Serialized queue data
*
@@ -188,6 +197,23 @@ public static function &fields() {
],
'add' => NULL,
],
+ 'run_count' => [
+ 'name' => 'run_count',
+ 'type' => CRM_Utils_Type::T_INT,
+ 'title' => ts('Run Count'),
+ 'description' => ts('Number of times execution has been attempted.'),
+ 'required' => TRUE,
+ 'where' => 'civicrm_queue_item.run_count',
+ 'default' => '0',
+ 'table_name' => 'civicrm_queue_item',
+ 'entity' => 'QueueItem',
+ 'bao' => 'CRM_Queue_BAO_QueueItem',
+ 'localizable' => 0,
+ 'html' => [
+ 'type' => 'Text',
+ ],
+ 'add' => '5.48',
+ ],
'data' => [
'name' => 'data',
'type' => CRM_Utils_Type::T_LONGTEXT,
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Queue.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Queue.php
index 87bad2f9e90..a8b98b8b64a 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Queue.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Queue.php
@@ -25,22 +25,25 @@ abstract class CRM_Queue_Queue {
*/
private $_name;
+ /**
+ * @var array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int}
+ * @see \CRM_Queue_Service::create()
+ */
+ protected $queueSpec;
+
/**
* Create a reference to queue. After constructing the queue, one should
* usually call createQueue (if it's a new queue) or loadQueue (if it's
* known to be an existing queue).
*
- * @param array $queueSpec
- * Array with keys:
- * - type: string, required, e.g. "interactive", "immediate", "stomp",
- * "beanstalk"
- * - name: string, required, e.g. "upgrade-tasks"
- * - reset: bool, optional; if a queue is found, then it should be
- * flushed; default to TRUE
- * - (additional keys depending on the queue provider).
+ * @param array{name: string, type: string, runner: string, batch_limit: int, lease_time: ?int, retry_limit: int, retry_interval: ?int} $queueSpec
+ * Ex: ['name' => 'my-import', 'type' => 'SqlParallel']
+ * The full definition of queueSpec is defined in CRM_Queue_Service.
+ * @see \CRM_Queue_Service::create()
*/
public function __construct($queueSpec) {
$this->_name = $queueSpec['name'];
+ $this->queueSpec = $queueSpec;
}
/**
@@ -52,6 +55,16 @@ public function getName() {
return $this->_name;
}
+ /**
+ * Get a property from the queueSpec.
+ *
+ * @param string $field
+ * @return mixed|null
+ */
+ public function getSpec(string $field) {
+ return $this->queueSpec[$field] ?? NULL;
+ }
+
/**
* Perform any registation or resource-allocation for a new queue
*/
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Service.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Service.php
index 576f76cdf2d..2a9815ecfcf 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Service.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Service.php
@@ -37,6 +37,14 @@ class CRM_Queue_Service {
protected static $_singleton;
+ /**
+ * List of fields which are shared by `$queueSpec` and `civicrm_queue`.
+ *
+ * @var string[]
+ * @readonly
+ */
+ private static $commonFields = ['name', 'type', 'runner', 'batch_limit', 'lease_time', 'retry_limit', 'retry_interval'];
+
/**
* FIXME: Singleton pattern should be removed when dependency-injection
* becomes available.
@@ -80,9 +88,12 @@ public function __construct() {
* flushed; default to TRUE
* - (additional keys depending on the queue provider).
* - is_persistent: bool, optional; if true, then this queue is loaded from `civicrm_queue` list
- * - is_autorun: bool, optional; if true, then this queue will be auto-scanned
- * by background task-runners
- *
+ * - runner: string, optional; if given, then items in this queue can run
+ * automatically via `hook_civicrm_queueRun_{$runner}`
+ * - batch_limit: int, Maximum number of items in a batch.
+ * - lease_time: int, When claiming an item (or batch of items) for work, how long should the item(s) be reserved. (Seconds)
+ * - retry_limit: int, Number of permitted retries. Set to zero (0) to disable.
+ * - retry_interval: int, Number of seconds to wait before retrying a failed execution.
* @return CRM_Queue_Queue
*/
public function create($queueSpec) {
@@ -121,22 +132,33 @@ public function create($queueSpec) {
* @throws \CRM_Core_Exception
*/
protected function findCreateQueueSpec(array $queueSpec): array {
- $storageFields = ['type', 'is_autorun'];
- $dao = new CRM_Queue_DAO_Queue();
- $dao->name = $queueSpec['name'];
- if ($dao->find(TRUE)) {
- return array_merge($queueSpec, CRM_Utils_Array::subset($dao->toArray(), $storageFields));
+ $loaded = $this->findQueueSpec($queueSpec);
+ if ($loaded !== NULL) {
+ return $loaded;
}
if (empty($queueSpec['type'])) {
throw new \CRM_Core_Exception(sprintf('Failed to find or create persistent queue "%s". Missing field "%s".',
$queueSpec['name'], 'type'));
}
- $queueSpec = array_merge(['is_autorun' => FALSE], $queueSpec);
+
+ $dao = new CRM_Queue_DAO_Queue();
+ $dao->name = $queueSpec['name'];
$dao->copyValues($queueSpec);
$dao->insert();
- return $queueSpec;
+ return $this->findQueueSpec($queueSpec);
+ }
+
+ protected function findQueueSpec(array $queueSpec): ?array {
+ $dao = new CRM_Queue_DAO_Queue();
+ $dao->name = $queueSpec['name'];
+ if ($dao->find(TRUE)) {
+ return array_merge($queueSpec, CRM_Utils_Array::subset($dao->toArray(), static::$commonFields));
+ }
+ else {
+ return NULL;
+ }
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Task.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Task.php
index cb510da2058..ab8fa06b249 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Task.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Queue/Task.php
@@ -47,10 +47,10 @@ class CRM_Queue_Task {
* (CRM_Queue_TaskContext).
* @param array $arguments
* Serializable, extra arguments to pass to the callback (in order).
- * @param string $title
+ * @param string|null $title
* A printable string which describes this task.
*/
- public function __construct($callback, $arguments, $title = NULL) {
+ public function __construct($callback, array $arguments = [], ?string $title = NULL) {
$this->callback = $callback;
$this->arguments = $arguments;
$this->title = $title;
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/BAO/ReportInstance.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/BAO/ReportInstance.php
index 9d755dabd06..930b44aad15 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/BAO/ReportInstance.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/BAO/ReportInstance.php
@@ -14,7 +14,7 @@
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
-class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance implements Civi\Test\HookInterface {
+class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance implements Civi\Core\HookInterface {
/**
* Takes an associative array and creates an instance object.
@@ -243,22 +243,20 @@ public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
}
/**
- * Retrieve instance.
+ * Retrieve DB object and copy to defaults array.
*
* @param array $params
+ * Array of criteria values.
* @param array $defaults
+ * Array to be populated with found values.
*
- * @return CRM_Report_DAO_ReportInstance|null
+ * @return self|null
+ * The DAO object, if found.
+ *
+ * @deprecated
*/
public static function retrieve($params, &$defaults) {
- $instance = new CRM_Report_DAO_ReportInstance();
- $instance->copyValues($params);
-
- if ($instance->find(TRUE)) {
- CRM_Core_DAO::storeValues($instance, $defaults);
- return $instance;
- }
- return NULL;
+ return self::commonRetrieve(self::class, $params, $defaults);
}
/**
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/Form.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/Form.php
index 692894151b1..0f906d9d5b6 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/Form.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Report/Form.php
@@ -3523,10 +3523,10 @@ public function filterStat(&$statistics) {
}
}
}
- else {
- // Prevents an e-notice in statistics.tpl.
- $statistics['filters'] = [];
- }
+ }
+ // Prevents an e-notice in statistics.tpl.
+ if (!isset($statistics['filters'])) {
+ $statistics['filters'] = [];
}
}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/UF/Page/AJAX.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/UF/Page/AJAX.php
index 79788616a2d..fd1526bd95b 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/UF/Page/AJAX.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/UF/Page/AJAX.php
@@ -24,7 +24,7 @@ class CRM_UF_Page_AJAX {
* Function the check whether the field belongs.
* to multi-record custom set
*/
- public function checkIsMultiRecord() {
+ public static function checkIsMultiRecord() {
$customId = $_GET['customId'];
$isMultiple = CRM_Core_BAO_CustomField::isMultiRecordField($customId);
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/MessageTemplates.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/MessageTemplates.php
index 9f0f1f36da7..bf9c443a39c 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/MessageTemplates.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/MessageTemplates.php
@@ -315,8 +315,15 @@ protected function getTemplateUpdates() {
],
],
[
- // This is the same list of templates that were modified in 5.47.alpha1. We need to update them again to undo the {$event.event_tz} bits.
- 'version' => '5.47.3',
+ 'version' => '5.48.alpha1',
+ 'upgrade_descriptor' => ts('Replace {receipt_text_renewal} with {receipt_text}'),
+ 'templates' => [
+ ['name' => 'membership_offline_receipt', 'type' => 'html'],
+ ['name' => 'membership_offline_receipt', 'type' => 'text'],
+ ],
+ ],
+ [
+ 'version' => '5.48.beta2',
'upgrade_descriptor' => ts('Revert time zone for Event dates'),
'templates' => [
['name' => 'event_online_receipt', 'type' => 'html'],
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortyEight.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortyEight.php
new file mode 100644
index 00000000000..e92d9331b12
--- /dev/null
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortyEight.php
@@ -0,0 +1,111 @@
+createEventTzPreUpgradeMessage();
+ }
+ }
+
+ /**
+ * Compute any messages which should be displayed after upgrade.
+ *
+ * Note: This function is called iteratively for each incremental upgrade step.
+ * There must be a concrete step (eg 'X.Y.Z.mysql.tpl' or 'upgrade_X_Y_Z()').
+ *
+ * @param string $postUpgradeMessage
+ * alterable.
+ * @param string $rev
+ * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
+ */
+ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev): void {
+ if ($rev === '5.48.beta2') {
+ $postUpgradeMessage .= $this->createEventTzPostUpgradeMessage();
+ }
+ }
+
+ /**
+ * Upgrade step; adds tasks including 'runSql'.
+ *
+ * @param string $rev
+ * The version number matching this function name
+ */
+ public function upgrade_5_48_alpha1($rev): void {
+ $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+ $this->addTask('Add "runner" to "civicrm_queue"', 'addColumn', 'civicrm_queue', 'runner',
+ "varchar(64) NULL COMMENT 'Name of the task runner'"
+ );
+ $this->addTask('Convert "is_autorun" to "runner"', 'convertAutorun');
+ $this->addTask('Drop "is_autorun" from "civicrm_queue"', 'dropColumn', 'civicrm_queue', 'is_autorun');
+ $this->addTask('Add "batch_limit" to "civicrm_queue"', 'addColumn', 'civicrm_queue', 'batch_limit',
+ "int unsigned NOT NULL DEFAULT 1 COMMENT 'Maximum number of items in a batch.'"
+ );
+ $this->addTask('Add "lease_time" to "civicrm_queue"', 'addColumn', 'civicrm_queue', 'lease_time',
+ "int unsigned NOT NULL DEFAULT 3600 COMMENT 'When claiming an item (or batch of items) for work, how long should the item(s) be reserved. (Seconds)'"
+ );
+ $this->addTask('Add "retry_limit" to "civicrm_queue"', 'addColumn', 'civicrm_queue', 'retry_limit',
+ "int NOT NULL DEFAULT 0 COMMENT 'Number of permitted retries. Set to zero (0) to disable.'"
+ );
+ $this->addTask('Add "retry_interval" to "civicrm_queue"', 'addColumn', 'civicrm_queue', 'retry_interval',
+ "int NULL COMMENT 'Number of seconds to wait before retrying a failed execution.'"
+ );
+ }
+
+ /**
+ * Upgrade step; adds tasks including 'runSql'.
+ *
+ * @param string $rev
+ * The version number matching this function name
+ */
+ public function upgrade_5_48_beta2($rev): void {
+ // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
+ $this->addEventTzTasks();
+ }
+
+ /**
+ * The `is_autorun` column was introduced in 5.47, but we didn't finish adding the
+ * additional changes to use, so there shouldn't be any real usage. But just to be
+ * paranoid, we'll convert to 5.48's `runner`.
+ *
+ * @param \CRM_Queue_TaskContext $ctx
+ * @return bool
+ */
+ public static function convertAutorun(CRM_Queue_TaskContext $ctx) {
+ CRM_Core_DAO::executeQuery('UPDATE civicrm_queue SET runner = "task" WHERE is_autorun = 1');
+ return TRUE;
+ }
+
+}
diff --git a/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortySeven.php b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortySeven.php
index e33a2a969eb..7fcf0bfcc81 100644
--- a/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortySeven.php
+++ b/profiles/civicrm_starterkit/modules/civicrm/CRM/Upgrade/Incremental/php/FiveFortySeven.php
@@ -21,8 +21,6 @@
*/
class CRM_Upgrade_Incremental_php_FiveFortySeven extends CRM_Upgrade_Incremental_Base {
- use CRM_Upgrade_Incremental_php_TimezoneRevertTrait;
-
/**
* Compute any messages which should be displayed before upgrade.
*
@@ -49,26 +47,6 @@ public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NU
'
+ {{:: ts('To enable REST authentication, the AuthX extension must be installed.') }} + + {{:: ts('Manage Extensions') }} + +
+- - {{:: ts('Search configuration copied from the "Export" action can be pasted here.') }} -
-- {{:: ts('Note: a Saved Search with the same name must not already exist.') }} -
-