Skip to content

Commit

Permalink
Merge pull request #4 from civicrm/master
Browse files Browse the repository at this point in the history
Catching up w/ core
  • Loading branch information
laryn authored Aug 22, 2017
2 parents 74c7dfd + 8af1022 commit b536a00
Show file tree
Hide file tree
Showing 26 changed files with 596 additions and 130 deletions.
1 change: 1 addition & 0 deletions CRM/ACL/Page/EntityRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public function run() {

// finally browse the acl's
if ($this->_action & CRM_Core_Action::BROWSE) {
$this->browse();
}

// This replaces parent run, but do parent's parent run
Expand Down
96 changes: 40 additions & 56 deletions CRM/Admin/Form/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,49 +69,17 @@ public function setDefaultValues() {
$defaults['file_type'] = 0;
}

$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults);
$this->assign('workflow_id', $this->_workflow_id);
if ($this->_action & CRM_Core_Action::ADD) {
$defaults['is_active'] = 1;
//set the context for redirection after form submit or cancel
$session = CRM_Core_Session::singleton();
$session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates',
'selectedChild=user&reset=1'
));
}

// FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm()
if ($this->_action & CRM_Core_Action::UPDATE) {
if ($this->_workflow_id) {
$selectedChild = 'workflow';
}
else {
$selectedChild = 'user';
}

$documentInfo = CRM_Core_BAO_File::getEntityFile('civicrm_msg_template', $this->_id, TRUE);
if (!empty($documentInfo)) {
$defaults['file_type'] = 1;
$this->_is_document = TRUE;
$this->assign('attachment', $documentInfo);
}

$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
$cancelURL = str_replace('&', '&', $cancelURL);
$this->addButtons(
array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
),
)
);
}

return $defaults;
Expand All @@ -121,7 +89,6 @@ public function setDefaultValues() {
* Build the form object.
*/
public function buildQuickForm() {

// For VIEW we only want Done button
if ($this->_action & CRM_Core_Action::VIEW) {
// currently, the above action is used solely for previewing default workflow templates
Expand All @@ -138,18 +105,36 @@ public function buildQuickForm() {
);
}
else {
$this->addButtons(array(
array(
'type' => 'upload',
'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
$this->assign('workflow_id', $this->_workflow_id);

if ($this->_workflow_id) {
$selectedChild = 'workflow';
}
else {
$selectedChild = 'user';
}

$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1");
$cancelURL = str_replace('&', '&', $cancelURL);
$buttons[] = array(
'type' => 'upload',
'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
'isDefault' => TRUE,
);
if (!($this->_action & CRM_Core_Action::DELETE)) {
$buttons[] = array(
'type' => 'submit',
'name' => ts('Save and Done'),
'subName' => 'done',
);
}
$buttons[] = array(
'type' => 'cancel',
'name' => ts('Cancel'),
'js' => array('onclick' => "location.href='{$cancelURL}'; return false;"),
);
$this->addButtons($buttons);
}

if ($this->_action & CRM_Core_Action::DELETE) {
Expand Down Expand Up @@ -221,7 +206,6 @@ public function buildQuickForm() {
);

$this->add('checkbox', 'is_active', ts('Enabled?'));

$this->addFormRule(array(__CLASS__, 'formRule'), $this);

if ($this->_action & CRM_Core_Action::VIEW) {
Expand All @@ -243,21 +227,19 @@ public function buildQuickForm() {
* array of errors
*/
public static function formRule($params, $files, $self) {
$errors = array();

// If user uploads non-document file other than odt/docx
if (!empty($files['file_id']['tmp_name']) &&
array_search($files['file_id']['type'], CRM_Core_SelectValues::documentApplicationType()) == NULL
) {
$error['file_id'] = ts('Invalid document file format');
$errors['file_id'] = ts('Invalid document file format');
}
// If default is not set and no document file is uploaded
elseif (empty($files['file_id']['tmp_name']) && !empty($params['file_type']) && !$self->_is_document) {
//On edit page of docx/odt message template if user changes file type but forgot to upload document
$errors['file_id'] = ts('Please upload document');
}

return $errors;
return empty($errors) ? TRUE : $errors;
}

/**
Expand All @@ -272,10 +254,8 @@ public function postProcess() {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
}
else {
$params = array();

// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$params = $this->controller->exportValues();

if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
Expand All @@ -286,7 +266,7 @@ public function postProcess() {
unset($params['msg_text']);
CRM_Utils_File::formatFile($params, 'file_id');
}
// delete related file refernces if html/text/pdf template are chosen over document
// delete related file references if html/text/pdf template are chosen over document
elseif (!empty($this->_id)) {
$entityFileDAO = new CRM_Core_DAO_EntityFile();
$entityFileDAO->entity_id = $this->_id;
Expand All @@ -300,6 +280,7 @@ public function postProcess() {
}
}

$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
if ($this->_workflow_id) {
$params['workflow_id'] = $this->_workflow_id;
$params['is_active'] = TRUE;
Expand All @@ -308,12 +289,15 @@ public function postProcess() {
$messageTemplate = CRM_Core_BAO_MessageTemplate::add($params);
CRM_Core_Session::setStatus(ts('The Message Template \'%1\' has been saved.', array(1 => $messageTemplate->msg_title)), ts('Saved'), 'success');

if (isset($this->_submitValues['_qf_MessageTemplates_upload'])) {
// Save button was pressed
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates/add', "action=update&id={$messageTemplate->id}&reset=1"));
}
// Save and done button was pressed
if ($this->_workflow_id) {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1'));
}
else {
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1'));
}
}

Expand Down
4 changes: 4 additions & 0 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,10 @@ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $prima
$from .= CRM_Mailing_BAO_Query::from($name, $mode, $side);
continue;
}
elseif ($mode & CRM_Contact_BAO_Query::MODE_CAMPAIGN) {
$from .= CRM_Campaign_BAO_Query::from($name, $mode, $side);
continue;
}

case 'civicrm_website':
$from .= " $side JOIN civicrm_website ON contact_a.id = civicrm_website.contact_id ";
Expand Down
14 changes: 13 additions & 1 deletion CRM/Contact/DAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Contact/Contact.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:6b04aae8fb2f9ebedb5aa9c792b81e30)
* (GenCodeChecksum:1e87927c8c8bdec9acfe3c306bb711d4)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -968,6 +968,10 @@ static function &fields() {
'entity' => 'Contact',
'bao' => 'CRM_Contact_BAO_Contact',
'localizable' => 0,
'pseudoconstant' => array(
'optionGroupName' => 'email_greeting',
'optionEditPath' => 'civicrm/admin/options/email_greeting',
)
) ,
'email_greeting_custom' => array(
'name' => 'email_greeting_custom',
Expand Down Expand Up @@ -1016,6 +1020,10 @@ static function &fields() {
'html' => array(
'type' => 'Text',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'postal_greeting',
'optionEditPath' => 'civicrm/admin/options/postal_greeting',
)
) ,
'postal_greeting_custom' => array(
'name' => 'postal_greeting_custom',
Expand Down Expand Up @@ -1081,6 +1089,10 @@ static function &fields() {
'html' => array(
'type' => 'Text',
) ,
'pseudoconstant' => array(
'optionGroupName' => 'addressee',
'optionEditPath' => 'civicrm/admin/options/addressee',
)
) ,
'addressee_display' => array(
'name' => 'addressee_display',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Edit/CommunicationPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public static function formRule($fields, $files, $self) {

$greetings = self::getGreetingFields($self->_contactType);
foreach ($greetings as $greeting => $details) {
$customizedValue = CRM_Core_OptionGroup::getValue($greeting, 'Customized', 'name');
$customizedValue = CRM_Core_PseudoConstant::getKey('CRM_Contact_BAO_Contact', $details['field'], 'Customized');
if (CRM_Utils_Array::value($details['field'], $fields) == $customizedValue && empty($fields[$details['customField']])) {
$errors[$details['customField']] = ts('Custom %1 is a required field if %1 is of type Customized.',
array(1 => $details['label'])
Expand Down
6 changes: 1 addition & 5 deletions CRM/Contact/Form/Task/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ public function preProcess() {
if (!$cid && $this->_context != 'standalone') {
parent::preProcess();
}

//early prevent, CRM-6209
if (count($this->_contactIds) > CRM_Contact_Form_Task_EmailCommon::MAX_EMAILS_KILL_SWITCH) {
CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.', array(1 => CRM_Contact_Form_Task_EmailCommon::MAX_EMAILS_KILL_SWITCH)));
}
CRM_Contact_Form_Task_EmailCommon::bounceIfSimpleMailLimitExceeded(count($this->_contactIds));

$this->assign('single', $this->_single);
if (CRM_Core_Permission::check('administer CiviCRM')) {
Expand Down
21 changes: 16 additions & 5 deletions CRM/Contact/Form/Task/EmailCommon.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,7 @@ public static function formRule($fields, $dontCare, $self) {
* @param CRM_Core_Form $form
*/
public static function postProcess(&$form) {
if (count($form->_contactIds) > self::MAX_EMAILS_KILL_SWITCH) {
CRM_Core_Error::fatal(ts('Please do not use this task to send a lot of emails (greater than %1). We recommend using CiviMail instead.',
array(1 => self::MAX_EMAILS_KILL_SWITCH)
));
}
self::bounceIfSimpleMailLimitExceeded(count($form->_contactIds));

// check and ensure that
$formValues = $form->controller->exportValues($form->getName());
Expand Down Expand Up @@ -626,4 +622,19 @@ protected static function saveMessageTemplate($formValues) {
}
}

/**
* Bounce if there are more emails than permitted.
*
* @param int $count
* The number of emails the user is attempting to send
*/
public static function bounceIfSimpleMailLimitExceeded($count) {
$limit = Civi::settings()->get('simple_mail_limit');
if ($count > $limit) {
CRM_Core_Error::statusBounce(ts('Please do not use this task to send a lot of emails (greater than %1). Many countries have legal requirements when sending bulk emails and the CiviMail framework has opt out functionality and domain tokens to help meet these.',
array(1 => $limit)
));
}
}

}
2 changes: 1 addition & 1 deletion CRM/Contact/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function initTasks() {
'result' => FALSE,
),
self::EMAIL_CONTACTS => array(
'title' => ts('Email - send now (to 50 or less)'),
'title' => ts('Email - send now (to %1 or less)', array(1 => Civi::settings()->get('simple_mail_limit'))),
'class' => 'CRM_Contact_Form_Task_Email',
'result' => TRUE,
'url' => 'civicrm/task/send-email',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ protected function postProcessMembership(
$isTest = CRM_Utils_Array::value('is_test', $membershipParams, FALSE);
$errors = $paymentResults = array();
$form->_values['isMembership'] = TRUE;
$isRecurForFirstTransaction = CRM_Utils_Array::value('is_recur', $form->_values, CRM_Utils_Array::value('is_recur', $membershipParams));
$isRecurForFirstTransaction = CRM_Utils_Array::value('is_recur', $form->_params, CRM_Utils_Array::value('is_recur', $membershipParams));

$totalAmount = $membershipParams['amount'];

Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/BAO/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static function filePostProcess(
$mimeType = NULL
) {
if (!$mimeType) {
CRM_Core_Error::fatal(ts('Mime Type is now a required parameter'));
CRM_Core_Error::statusBounce(ts('Mime Type is now a required parameter for file upload'));
}

$config = CRM_Core_Config::singleton();
Expand All @@ -116,7 +116,7 @@ public static function filePostProcess(
CRM_Utils_File::createDir($directoryName);

if (!rename($data, $directoryName . DIRECTORY_SEPARATOR . $filename)) {
CRM_Core_Error::fatal(ts('Could not move custom file to custom upload directory'));
CRM_Core_Error::statusBounce(ts('Could not move custom file to custom upload directory'));
}

// to get id's
Expand Down
26 changes: 14 additions & 12 deletions CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ public function recur(&$input, &$ids, &$objects, $first) {
return FALSE;
}

if ($input['txnType'] == 'recurring_payment' &&
$input['paymentStatus'] != 'Completed'
) {
CRM_Core_Error::debug_log_message("Ignore all IPN payments that are not completed");
echo "Failure: Invalid parameters<p>";
return FALSE;
}

$recur = &$objects['contributionRecur'];

// make sure the invoice ids match
Expand Down Expand Up @@ -245,7 +237,19 @@ public function recur(&$input, &$ids, &$objects, $first) {
$recur->start_date = $now;
}
else {
$recur->modified_date = $now;
$input['invoice_id'] = md5(uniqid(rand(), TRUE));
$input['original_contribution_id'] = $ids['contribution'];
$input['contribution_recur_id'] = $ids['contributionRecur'];

if ($input['paymentStatus'] != 'Completed') {
throw new CRM_Core_Exception("Ignore all IPN payments that are not completed");
}
// In future moving to create pending & then complete, but this OK for now.
// Also consider accepting 'Failed' like other processors.
$input['contribution_status_id'] = 1;

civicrm_api3('Contribution', 'repeattransaction', $input);
return;
}

//contribution installment is completed
Expand Down Expand Up @@ -310,6 +314,7 @@ public function recur(&$input, &$ids, &$objects, $first) {
$contribution->amount_level = $objects['contribution']->amount_level;
$contribution->campaign_id = $objects['contribution']->campaign_id;
$objects['contribution'] = &$contribution;
$contribution->invoice_id = md5(uniqid(rand(), TRUE));
}
// CRM-13737 - am not aware of any reason why payment_date would not be set - this if is a belt & braces
$objects['contribution']->receive_date = !empty($input['payment_date']) ? date('YmdHis', strtotime($input['payment_date'])) : $now;
Expand Down Expand Up @@ -356,9 +361,6 @@ public function single(&$input, &$ids, &$objects, $recur = FALSE, $first = FALSE

$transaction = new CRM_Core_Transaction();

$participant = &$objects['participant'];
$membership = &$objects['membership'];

$status = $input['paymentStatus'];
if ($status == 'Denied' || $status == 'Failed' || $status == 'Voided') {
return $this->failed($objects, $transaction);
Expand Down
Loading

0 comments on commit b536a00

Please sign in to comment.