Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:NETivism/netiCRM into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Nov 14, 2024
2 parents 7e380af + 987d98a commit 9781c23
Show file tree
Hide file tree
Showing 18 changed files with 202 additions and 29 deletions.
39 changes: 39 additions & 0 deletions CRM/Activity/PseudoConstant.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

class CRM_Activity_PseudoConstant extends CRM_Core_PseudoConstant {

/**
* Get all Activity Statuses.
*
* The static array activityStatus is returned
*
* @access public
* @static
*
* @return array - array reference of all activity statuses
*/
public static function &activityStatus($column = 'label') {
return parent::activityStatus($column);
}

/**
* Get all Activty types.
*
* The static array activityType is returned
*
* @param boolean $all - get All Activity types - default is to get only active ones.
*
* @access public
* @static
*
* @return array - array reference of all activty types.
*/
public static function &activityType($all = TRUE,
$includeCaseActivities = FALSE,
$reset = FALSE,
$returnColumn = 'label',
$includeCampaignActivities = FALSE
) {
return parent::activityType($all, $includeCaseActivities, $reset, $returnColumn, $includeCampaignActivities);
}
}
9 changes: 9 additions & 0 deletions CRM/Admin/Form/Setting/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function buildQuickForm() {
// Refs #38829, Add receipt Email Encryption option
$this->add('checkbox', 'receiptEmailEncryption', ts('Email Receipt Password'));
$this->addElement('text', 'receiptEmailEncryptionText', ts('Email Receipt Password Explanation Text'));
$this->addFormRule(array(get_class($this), 'formRule'));
}

function setDefaultValues() {
Expand Down Expand Up @@ -141,6 +142,14 @@ public function postProcess() {
parent::commonProcess($params);
}

static function formRule($fields, $files, $self) {
$errors = [];
if ((!empty($fields['receiptDisplayLegalID']) && $fields['receiptDisplayLegalID'] !== 'complete') && (!empty($fields['receiptEmailEncryption']) && $fields['receiptEmailEncryption'] === '1')) {
$errors['receiptEmailEncryption'] = ts('When the legal ID display option is not set to complete display, email receipt encryption cannot be enabled.');
}
return empty($errors) ? true : $errors;
}

/**
* Resize a premium image to a different size
*
Expand Down
89 changes: 81 additions & 8 deletions CRM/Batch/BAO/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class CRM_Batch_BAO_Batch extends CRM_Batch_DAO_Batch {
*/
const EXPIRE_DAY = 8;

/**
* stuck expire hour
*/
const EXPIRE_HOUR = 4;

/**
* Batch id to load
* @var int
Expand Down Expand Up @@ -170,25 +175,23 @@ public static function runQueue() {
$message = ts('Success processing queuing batch.');
}
}
if (date('G') >= 3 && date('G') <= 6) {
self::expireBatch();
}
return $message;
}

/**
* Run last queuing batching
* Expire batches over expire days
* This will delete data column and purge download file to prevent db growing
*
* @return string
* message that indicate current running status
* message that indicate expires
*/
public static function expireBatch() {
$type = self::batchType();
$status = self::batchStatus();
unset($status['Running']);
unset($status['Pending']);
$purgeDay = self::EXPIRE_DAY*4;
$sql = "SELECT id FROM civicrm_batch WHERE type_id = %1 AND status_id IN (".CRM_Utils_Array::implode(',', $status).") AND DATE_ADD(modified_date, INTERVAL ".$purgeDay." DAY) < NOW() AND modified_date IS NOT NULL ORDER BY modified_date ASC";
$sql = "SELECT id FROM civicrm_batch WHERE type_id = %1 AND status_id IN (".CRM_Utils_Array::implode(',', $status).") AND DATE_ADD(modified_date, INTERVAL ".$purgeDay." DAY) < NOW() AND modified_date IS NOT NULL AND data IS NOT NULL ORDER BY modified_date ASC";
$dao = CRM_Core_DAO::executeQuery($sql, array(
1 => array($type['Auto'], 'Integer'),
));
Expand All @@ -202,10 +205,13 @@ public static function expireBatch() {
if ($batch->id) {
if (isset($batch->data['download']['file']) && file_exists($batch->data['download']['file'])) {
@unlink($batch->data['download']['file']);
$expires[] = $dao->id;
}
// $batch->delete(); // do not delete batch db record, purge file only
$expires[] = $dao->id;
CRM_Core_DAO::executeQuery("UPDATE civicrm_batch SET data = NULL WHERE id = %1", array(1 => array($dao->id, 'Integer')));
}
// refs #41959, free memory of batch result to prevent memory leak
$batch->free();
unset($batch);
}
if (count($expires)) {
$msg = 'Batch ids in '.CRM_Utils_Array::implode(",", $expires).' has been expires';
Expand All @@ -215,6 +221,73 @@ public static function expireBatch() {
return '';
}

/**
* Auto remove stuck batch
*
* @return null
*/
public static function cancelStuckBatch() {
$type = self::batchType();
$status = self::batchStatus();
$statusRunning = $status['Running'];
$statusCanceled = $status['Canceled'];

$sql = "SELECT id, data, modified_date, description FROM civicrm_batch WHERE type_id = %1 AND status_id = %2 ORDER BY created_date ASC LIMIT 1";
$dao = CRM_Core_DAO::executeQuery($sql, array(
1 => array($type['Auto'], 'Integer'),
2 => array($statusRunning, 'Integer'),
));
$dao->fetch();
if (!empty($dao->id)) {
if ($dao->data) {
$meta = unserialize($dao->data);
// after 4 hours without any progress, cancel it
if (is_array($meta) && empty($meta['processed']) && !empty($dao->modified_date)) {
$lastSuccessTime = strtotime($dao->modified_date);
if (CRM_REQUEST_TIME - $lastSuccessTime > 3600 * self::EXPIRE_HOUR) {
CRM_Core_Error::debug_log_message("Canceled running batch id {$dao->id} due to zero progress over ".self::EXPIRE_HOUR." hours.");
CRM_Core_DAO::executeQuery("UPDATE civicrm_batch SET status_id = %1, description = %2 WHERE id = %3", array(
1 => array($statusCanceled, 'Integer'),
2 => array(ts('Batch running failed. Contact the site administrator for assistance.'), 'String'),
3 => array($dao->id, 'Integer'),
));
}
}
elseif(!empty($meta['processed'])){
if (!empty($dao->description)) {
$processHistories = explode(':', $dao->description);
}
else {
$processHistories = array();
}
$stuck = 0;
foreach($processHistories as $lastProcessed) {
if ((int)$meta['processed'] == (int)$lastProcessed) {
$stuck++;
}
}
if ($stuck <= self::EXPIRE_HOUR) {
array_unshift($processHistories, $meta['processed']);
$processHistories = array_slice($processHistories, 0, self::EXPIRE_HOUR+2);
CRM_Core_DAO::executeQuery("UPDATE civicrm_batch SET description = %1 WHERE id = %2", array(
1 => array(implode(':', $processHistories), 'String'),
2 => array($dao->id, 'Integer'),
));
}
else {
// no progress after 4 times(have same processed records), cancel it
CRM_Core_Error::debug_log_message("Canceled running batch id {$dao->id} due to stuck in progress {$meta['processed']} for {$stuck} times.");
CRM_Core_DAO::executeQuery("UPDATE civicrm_batch SET status_id = %1, description = %2 WHERE id = %3", array(
1 => array($statusCanceled, 'Integer'),
2 => array(ts('Batch running failed. Contact the site administrator for assistance.').' ('.$dao->description.')', 'String'),
3 => array($dao->id, 'Integer'),
));
}
}
}
}
}

/**
* Constructor
*
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionRecur.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function buildQuickForm() {
}
}
if (!empty($paymentClass)) {
if (!empty($paymentClass::$_editableFields)) {
if (isset($paymentClass::$_editableFields) && is_array($paymentClass::$_editableFields)) {
$activeFields = $paymentClass::$_editableFields;
}
else if(method_exists($paymentClass, 'getEditableFields')) {
Expand Down
14 changes: 8 additions & 6 deletions CRM/Contribute/Form/PCP/PCPAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,17 @@ public function buildQuickForm() {
static function formRule($fields, $files, $self) {
$errors = array();
require_once "CRM/Utils/Rule.php";
foreach ($fields as $key => $value) {
if (strpos($key, 'email-') !== FALSE && !empty($value)) {
$ufContactId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
if ($ufContactId && $ufContactId != $self->_contactID) {
$errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
if (!CRM_Core_Permission::check('access CiviContribute')) {
foreach ($fields as $key => $value) {
if (strpos($key, 'email-') !== FALSE && !empty($value)) {
$ufContactId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFMatch', $value, 'contact_id', 'uf_name');
if ($ufContactId && $ufContactId != $self->_contactID) {
$errors[$key] = ts('There is already an user associated with this email address. Please enter different email address.');
}
}
}
}
return empty($errors) ? TRUE : $errors;
return $errors;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/BAO/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ static function ajax() {
break;
case CRM_Utils_Type::T_STRING:
default:
if (is_array($value)) {
$params[$key] = (string) reset($value);
}
if (!CRM_Utils_Type::validate($value, 'String', FALSE)) {
unset($params[$key]);
}
Expand Down
2 changes: 2 additions & 0 deletions CRM/Core/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ abstract class CRM_Core_Payment {

protected $_paymentForm = NULL;

public static $_editableFields = array();

/**
* singleton function used to manage this object
*
Expand Down
4 changes: 3 additions & 1 deletion CRM/Core/Payment/LinePay.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ function doConfirm($params){
$ids['contribution'] = $contribution->id;
$ids['contact'] = $contribution->contact_id;
$validate_result = $ipn->validateData($input, $ids, $objects, FALSE);
if($validate_result && $this->_linePayAPI->_response->returnCode != '1172'){ // Refs #31598, 1172 means duplicated order, often means trigger twice.
// Refs #31598, 1172 means duplicated order, often means trigger twice.
// Refs #41790, 1198 means duplicate API requests.
if($validate_result && ($this->_linePayAPI->_response->returnCode != '1172' && $this->_linePayAPI->_response->returnCode != '1198')){
$transaction = new CRM_Core_Transaction();
if($is_success){
$input['payment_instrument_id'] = $contribution->payment_instrument_id;
Expand Down
6 changes: 6 additions & 0 deletions api/v3/Generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ function civicrm_api3_generic_getoptions($apiRequest) {
$fieldName = 'participant_'.$apiRequest['params']['field'];
}
}
// special case for activity
if ($entity == 'activity') {
if (in_array($apiRequest['params']['field'], array('status_id', 'type_id', 'status', 'type'))) {
$fieldName = 'activity_'.$apiRequest['params']['field'];
}
}

$constantEntities = _civicrm_api3_pseudoconstant_entity();
$fieldNameWithoutId = strtolower(preg_replace('/_id$/i', '', $fieldName));
Expand Down
1 change: 1 addition & 0 deletions api/v3/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1672,5 +1672,6 @@ function _civicrm_api3_pseudoconstant_entity() {
'contribution' => 'Contribute',
'event' => 'Event',
'membership' => 'Member',
'activity' => 'Activity',
);
}
9 changes: 9 additions & 0 deletions l10n/pot/civicrm.pot
Original file line number Diff line number Diff line change
Expand Up @@ -49586,4 +49586,13 @@ msgstr ""

#: templates/CRM/Group/Page/Group.tpl
msgid "Public Mailing List Group"
msgstr ""

#: CRM/Admin/Form/Setting/Receipt.php
#: templates/CRM/Admin/Form/Setting/Receipt.tpl
msgid "When the legal ID display option is not set to complete display, email receipt encryption cannot be enabled."
msgstr ""

#: CRM/Batch/BAO/Batch.php
msgid "Batch running failed. Contact the site administrator for assistance."
msgstr ""
Binary file modified l10n/zh_TW/LC_MESSAGES/civicrm.mo
Binary file not shown.
17 changes: 14 additions & 3 deletions l10n/zh_TW/civicrm.po
Original file line number Diff line number Diff line change
Expand Up @@ -3133,7 +3133,7 @@ msgstr "至"
#: CRM/Contact/Form/Search/Custom/Basic.php CRM/Contact/Selector.php
#: templates/CRM/Contact/Form/Task/Print.tpl
msgid "Postal"
msgstr "郵件"
msgstr "郵遞區號"

#: CRM/Contact/Form/Search/Custom/Basic.php
#: CRM/Contact/Form/Search/Custom/MultipleValues.php
Expand Down Expand Up @@ -49699,13 +49699,13 @@ msgid ""
"receipt includes tax filing credentials (such as ID number or Uniform "
"Number), encryption will be done using these credentials. If these fields "
"are not present, the recipient's email address will be used for encryption."
msgstr "啟用後,將會為電子郵件收據加上密碼,若收據中有包含報稅憑證(例如身份證字號、統一編號),將會用報稅憑證進行加密;若沒有該欄位的值,將會用收件人 Email 地址加密。"
msgstr "啟用後,將會為電子郵件收據加上密碼,若收據中有包含報稅憑證(例如身份證字號、統一編號),將會用報稅憑證進行加密;若沒有該欄位的值,將會使用聯絡人的身份證字號進行加密;若聯絡人資料中無填寫身分證字號,將會用收件人 Email 地址加密。"

msgid ""
"If no specific text is set, the default text will be: Your PDF receipt is "
"encrypted. The password is either your tax certificate number or, if not "
"provided, your email address."
msgstr "若未設定文案,預設文案為「您的PDF收據已加密。密碼是您的報稅憑證若未提供此號碼,則使用您的電子郵件地址作為密碼。」"
msgstr "若未設定文案,預設文案為「您的PDF收據已加密。密碼是您的報稅憑證若未提供此號碼,則使用您的身分證字號;若上述兩項皆為未提供;則使用您的電子郵件地址作為密碼。」"

#: CRM/Admin/Form/Setting/Miscellaneous.php
msgid "Path to qpdf executable"
Expand Down Expand Up @@ -50154,3 +50154,14 @@ msgstr "你選擇的群組是最後一個公開的電子報群組,移除後將
#: templates/CRM/Group/Page/Group.tpl
msgid "Public Mailing List Group"
msgstr "公開的電子報訂閱群組"

#: CRM/Admin/Form/Setting/Receipt.php
#: templates/CRM/Admin/Form/Setting/Receipt.tpl
msgid ""
"When the legal ID display option is not set to complete display, email "
"receipt encryption cannot be enabled."
msgstr "當身分證字號呈現方式不是完全顯示時,無法啟用電子收據加密功能"

#: CRM/Batch/BAO/Batch.php
msgid "Batch running failed. Contact the site administrator for assistance."
msgstr "批次執行失敗。請聯繫網站管理員以取得協助。"
12 changes: 12 additions & 0 deletions templates/CRM/Admin/Form/Setting/Receipt.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@
$('[name='+deleteFieldName+']').val(1);
$(this).parent().find('img').css('filter','brightness(50%)');
});
$('input[name^="receiptDisplayLegalID"]').click(function() {
const selectedValue = $('input[name^="receiptDisplayLegalID"]:checked').val();
$('.crm-form-block-receiptEmailEncryption .warning-message').remove();
if (selectedValue !== 'complete') {
$('input[name="receiptEmailEncryption"]').prop('checked', false);
$('.crm-form-block-receiptEmailEncryption .description').after(
'<span class="description warning-message font-red"; display: block; margin-top: 5px;">' +
'{/literal}{ts}When the legal ID display option is not set to complete display, email receipt encryption cannot be enabled.{/ts}{literal}' +
'</span>'
);
}
});
})
</script>
<style type="text/css">
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Group/Form/Edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ cj(document).ready( function($) {
$("input[name=_qf_Edit_upload]").on("click", function(e){
e.preventDefault();
let thisform = $(this).closest('form');
if ($("#group_type\\\[2\\\]").prop('checked') && $("#visibility").val() === 'Public Pages') {
if ($("#visibility").val() === 'Public Pages') {
let groupName = $('input[name=title]').val();
$('#dialog-confirm-groupname').html($('#dialog-confirm-groupname').html().replace('[[placeholder]]', groupName));
$("#dialog-confirm-groupname").dialog({
Expand Down
Loading

0 comments on commit 9781c23

Please sign in to comment.