From 62e13e769e97ba6cc4b8918f84311822b9902f2f Mon Sep 17 00:00:00 2001 From: Ruben Rodriguez Date: Thu, 10 Sep 2015 18:24:23 -0400 Subject: [PATCH] Added the current uncommited changes to production code, and rebased to 4.6.8 --- CRM/Activity/BAO/Activity.php | 2 +- CRM/Contact/BAO/Contact.php | 3 +- CRM/Contact/BAO/Contact/Utils.php | 2 +- CRM/Contact/BAO/GroupContact.php | 6 ++- CRM/Contact/BAO/GroupContactCache.php | 34 ++++++++++----- CRM/Contact/Form/Task/PDFLatexCommon.php | 9 ++-- CRM/Contribute/BAO/Contribution.php | 3 +- CRM/Event/BAO/Participant.php | 3 +- CRM/Member/BAO/Membership.php | 8 ++-- CRM/Member/Import/Form/DataSource.php | 1 + CRM/Price/BAO/PriceSet.php | 31 +++++++++++--- CRM/Utils/PDF/Utils.php | 41 +++++++++++++++---- .../Form/Contribution/PremiumBlock.tpl | 9 ++++ 13 files changed, 112 insertions(+), 40 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index f42e030d44..b0c860ce66 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -586,7 +586,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity { } // reset the group contact cache since smart groups might be affected due to this - CRM_Contact_BAO_GroupContactCache::remove(); + // CRM_Contact_BAO_GroupContactCache::remove(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Activity', $activity->id, $activity); diff --git a/CRM/Contact/BAO/Contact.php b/CRM/Contact/BAO/Contact.php index 06cd9f22ab..b2f3001709 100644 --- a/CRM/Contact/BAO/Contact.php +++ b/CRM/Contact/BAO/Contact.php @@ -1930,7 +1930,8 @@ ORDER BY civicrm_email.is_primary DESC"; } // reset the group contact cache for this group - CRM_Contact_BAO_GroupContactCache::remove(); + // HACK: Dave disabled this on 12/09/2014 due to a crazy amount of lock wait timeouts on cache tables, causing donations to fail. + //CRM_Contact_BAO_GroupContactCache::remove(); if ($editHook) { CRM_Utils_Hook::post('edit', 'Profile', $contactID, $params); diff --git a/CRM/Contact/BAO/Contact/Utils.php b/CRM/Contact/BAO/Contact/Utils.php index 5af6e2e21a..c1fb7ec696 100644 --- a/CRM/Contact/BAO/Contact/Utils.php +++ b/CRM/Contact/BAO/Contact/Utils.php @@ -991,7 +991,7 @@ Group By componentId"; FROM civicrm_contact WHERE contact_type = %1 AND ({$idFldName} IS NULL - OR ( {$idFldName} IS NOT NULL AND ({$displayFldName} IS NULL OR {$displayFldName} = '')) )"; + OR ( {$idFldName} IS NOT NULL AND ({$displayFldName} IS NULL OR {$displayFldName} = '')) ) LIMIT 800"; } if ($limit) { diff --git a/CRM/Contact/BAO/GroupContact.php b/CRM/Contact/BAO/GroupContact.php index 8a4bb40b9e..2e74adb00a 100644 --- a/CRM/Contact/BAO/GroupContact.php +++ b/CRM/Contact/BAO/GroupContact.php @@ -145,12 +145,14 @@ class CRM_Contact_BAO_GroupContact extends CRM_Contact_DAO_GroupContact { // also reset the acl cache $config = CRM_Core_Config::singleton(); if (!$config->doNotResetCache) { - CRM_ACL_BAO_Cache::resetCache(); + // HACK: Dave commented this out on 12/09/2014 due to lock wait timeouts on the acl cache that caused donations to fail. + //CRM_ACL_BAO_Cache::resetCache(); } // reset the group contact cache for all group(s) // if this group is being used as a smart group - CRM_Contact_BAO_GroupContactCache::remove(); + // HACK: Dave had to disable this, too! + //CRM_Contact_BAO_GroupContactCache::remove(); CRM_Utils_Hook::post('create', 'GroupContact', $groupId, $contactIds); diff --git a/CRM/Contact/BAO/GroupContactCache.php b/CRM/Contact/BAO/GroupContactCache.php index ba013e276d..b9da3338c8 100644 --- a/CRM/Contact/BAO/GroupContactCache.php +++ b/CRM/Contact/BAO/GroupContactCache.php @@ -321,11 +321,13 @@ WHERE id IN ( $groupIDs ) $now = CRM_Utils_Date::getUTCTime(); $refreshTime = CRM_Utils_Date::getUTCTime($smartGroupCacheTimeout * 60); + // HACK: Hardcoded delete limit. + $deleteLimit = 1000; if (!isset($groupID)) { if ($smartGroupCacheTimeout == 0) { $query = " -TRUNCATE civicrm_group_contact_cache +DELETE FROM civicrm_group_contact_cache LIMIT $deleteLimit "; $update = " UPDATE civicrm_group g @@ -336,9 +338,14 @@ SET cache_date = null, else { $query = " DELETE gc -FROM civicrm_group_contact_cache gc -INNER JOIN civicrm_group g ON g.id = gc.group_id -WHERE TIMESTAMPDIFF(MINUTE, g.cache_date, $now) >= $smartGroupCacheTimeout +FROM civicrm_group_contact_cache AS gc +INNER JOIN ( + SELECT id + FROM civicrm_group + WHERE TIMESTAMPDIFF(MINUTE, cache_date, $now) >= $smartGroupCacheTimeout + LIMIT $deleteLimit + ) AS g +ON g.id=gc.group_id "; $update = " UPDATE civicrm_group g @@ -357,9 +364,10 @@ AND refresh_date IS NULL elseif (is_array($groupID)) { $groupIDs = implode(', ', $groupID); $query = " -DELETE g -FROM civicrm_group_contact_cache g -WHERE g.group_id IN ( $groupIDs ) +DELETE +FROM civicrm_group_contact_cache +WHERE group_id IN ( $groupIDs ) +LIMIT $deleteLimit "; $update = " UPDATE civicrm_group g @@ -370,9 +378,10 @@ WHERE id IN ( $groupIDs ) } else { $query = " -DELETE g -FROM civicrm_group_contact_cache g -WHERE g.group_id = %1 +DELETE +FROM civicrm_group_contact_cache +WHERE group_id = %1 +LIMIT $deleteLimit "; $update = " UPDATE civicrm_group g @@ -383,7 +392,10 @@ WHERE id = %1 $params = array(1 => array($groupID, 'Integer')); } - CRM_Core_DAO::executeQuery($query, $params); + // Nibble at the rows, don't try to delete everything at once! + do { + $dao = CRM_Core_DAO::executeQuery($query, $params); + } while($dao->affectedRows() != 0); if ($refresh) { CRM_Core_DAO::executeQuery($refresh, $params); diff --git a/CRM/Contact/Form/Task/PDFLatexCommon.php b/CRM/Contact/Form/Task/PDFLatexCommon.php index a0ca45339c..4dbdb1806b 100644 --- a/CRM/Contact/Form/Task/PDFLatexCommon.php +++ b/CRM/Contact/Form/Task/PDFLatexCommon.php @@ -48,7 +48,7 @@ class CRM_Contact_Form_Task_PDFLatexCommon { static function preProcess(&$form) { $messageText = array(); $messageSubject = array(); - $dao = new CRM_Core_BAO_MessageTemplates(); + $dao = new CRM_Core_BAO_MessageTemplate(); $dao->is_active = 1; $dao->find(); while ($dao->fetch()) { @@ -254,14 +254,14 @@ class CRM_Contact_Form_Task_PDFLatexCommon { } if (CRM_Utils_Array::value('saveTemplate', $formValues) && $formValues['saveTemplate']) { $messageTemplate['msg_title'] = $formValues['saveTemplateName']; - CRM_Core_BAO_MessageTemplates::add($messageTemplate); + CRM_Core_BAO_MessageTemplate::add($messageTemplate); } if (CRM_Utils_Array::value('updateTemplate', $formValues) && $formValues['template'] && $formValues['updateTemplate']) { $messageTemplate['id'] = $formValues['template']; unset($messageTemplate['msg_title']); - CRM_Core_BAO_MessageTemplates::add($messageTemplate); + CRM_Core_BAO_MessageTemplate::add($messageTemplate); } } elseif (CRM_Utils_Array::value('template', $formValues) > 0) { @@ -384,10 +384,11 @@ class CRM_Contact_Form_Task_PDFLatexCommon { foreach ($form->_contactIds as $contactId) { $activityTargetParams = array( + 'contact_id' => $contactId, 'activity_id' => empty($activity->id) ? $activityIds[$contactId] : $activity->id, 'target_contact_id' => $contactId, ); - CRM_Activity_BAO_Activity::createActivityTarget($activityTargetParams); + CRM_Activity_BAO_ActivityTarget::create($activityTargetParams); } } diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 6ed0fd7e3f..96d8be55d3 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -192,7 +192,8 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { self::recordFinancialAccounts($params); // reset the group contact cache for this group - CRM_Contact_BAO_GroupContactCache::remove(); + // HACK: dave hack - these caches are murder!!! + // CRM_Contact_BAO_GroupContactCache::remove(); if ($contributionID) { CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution); diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index 631f220efb..11975612f8 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -143,7 +143,8 @@ class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant { $session = CRM_Core_Session::singleton(); // reset the group contact cache for this group - CRM_Contact_BAO_GroupContactCache::remove(); + // HACK: by davet + // CRM_Contact_BAO_GroupContactCache::remove(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO); diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 2a319b87fd..3af944e35f 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -143,7 +143,8 @@ class CRM_Member_BAO_Membership extends CRM_Member_DAO_Membership { CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray); // reset the group contact cache since smart groups might be affected due to this - CRM_Contact_BAO_GroupContactCache::remove(); + // HACK: a new fragrance by davet + // CRM_Contact_BAO_GroupContactCache::remove(); if ($id) { if ($membership->status_id != $oldStatus) { @@ -920,14 +921,15 @@ INNER JOIN civicrm_membership_type type ON ( type.id = membership.membership_ty $form->addRule('selectMembership', ts('Please select one of the memberships.'), 'required'); } else { - $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_priceSetId); + $autoRenewOption = CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($form->_priceSetId); $form->assign('autoRenewOption', $autoRenewOption); } if (!$form->_values['is_pay_later'] && is_array($form->_paymentProcessors) && ($allowAutoRenewMembership || $autoRenewOption)) { $form->addElement('checkbox', 'auto_renew', ts('Please renew my membership automatically.')); + $temphax =& $form->getElement('auto_renew'); + $temphax->setValue(1); } - } $form->assign('membershipBlock', $membershipBlock); diff --git a/CRM/Member/Import/Form/DataSource.php b/CRM/Member/Import/Form/DataSource.php index 9acf849845..d67bd616af 100644 --- a/CRM/Member/Import/Form/DataSource.php +++ b/CRM/Member/Import/Form/DataSource.php @@ -56,6 +56,7 @@ class CRM_Member_Import_Form_DataSource extends CRM_Core_Form { * @return void */ public function buildQuickForm() { + //Setting Upload File Size $config = CRM_Core_Config::singleton(); diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 794c0a591b..8e9c3dca73 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1300,7 +1300,7 @@ GROUP BY mt.member_of_contact_id"; // Auto renew checkbox should be frozen if for all the membership type auto renew is required // get the membership type auto renew option and check if required or optional - $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit + $query = 'SELECT mt.auto_renew, mt.duration_interval, mt.duration_unit, pf.id, pf.html_type FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id @@ -1324,9 +1324,22 @@ GROUP BY mt.member_of_contact_id"; $interval[$dao->duration_interval] = $dao->duration_interval; $unit[$dao->duration_unit] = $dao->duration_unit; - } - - if (count($interval) == 1 && count($unit) == 1 && $autoRenewOption > 0) { + $type[$dao->id] = $dao->html_type; + } + + // Autorenew is only a valid option when: + // + // * Only a single membership can be chosen (i.e. a single radio + // button group) + // + // OR + // + // * There is no variation in the duration intervals or units for + // all of the relevant membership types. + $sameDuration = count($interval) == 1 && count($unit) == 1; + $singleRadioGroup = array_values($type) == array('Radio'); + + if ($sameDuration || $singleRadioGroup) { return $autoRenewOption; } else { @@ -1343,12 +1356,18 @@ GROUP BY mt.member_of_contact_id"; * @return array * associate array of frequency interval and unit */ - public static function getRecurDetails($priceSetId) { + public static function getRecurDetails($priceSetId, $priceFieldValueIds) { + // Escape the array of ids. + foreach ($priceFieldValueIds as $index => $id) { + $priceFieldValueIds[$index] = CRM_Utils_Type::escape($id, 'Integer'); + } + $query = 'SELECT mt.duration_interval, mt.duration_unit FROM civicrm_price_field_value pfv INNER JOIN civicrm_membership_type mt ON pfv.membership_type_id = mt.id INNER JOIN civicrm_price_field pf ON pfv.price_field_id = pf.id - WHERE pf.price_set_id = %1 LIMIT 1'; + WHERE pf.price_set_id = %1 AND pfv.id IN (' + . implode(',', $priceFieldValueIds) . ') LIMIT 1'; $params = array(1 => array($priceSetId, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); diff --git a/CRM/Utils/PDF/Utils.php b/CRM/Utils/PDF/Utils.php index 3882c7b606..3b82400709 100644 --- a/CRM/Utils/PDF/Utils.php +++ b/CRM/Utils/PDF/Utils.php @@ -39,6 +39,15 @@ define('DOMPDF_ENABLE_AUTOLOAD', FALSE); class CRM_Utils_PDF_Utils { + public static function enqueuePDF($pdf) { + + $fname = time().'_lp.pdf'; + file_put_contents('/tmp/'.$fname, $pdf); + header('Location: /civicrm/lp-setup?file='.$fname); + exit; + + } + public static function latex2pdf(&$text, $fileName = 'civicrm.pdf', $output = FALSE, $pdfFormat = NULL) { /* FIXME: get $paper_size, $orientation, $margins */ @@ -49,13 +58,22 @@ class CRM_Utils_PDF_Utils { $pages = array($text); } - - $head='\documentclass[11pt]{letter} + $head='\documentclass[12pt]{letter} \usepackage{url} \usepackage{ucs} \usepackage{graphicx} \usepackage[T1]{fontenc} \usepackage{fullpage} +\usepackage{fontspec,xunicode} +%% VERY IMPORTANT. Configures supported languages and fonts to use for each one. +\usepackage[Latin, Hebrew, Arabics, CJK, Diacritics]{ucharclasses} +\setDefaultTransitions{\fontspec{CMU Serif}}{} +\setTransitionsForLatin{\fontspec{CMU Serif}}{} +\setTransitionsForArabics{\fontspec{Droid Sans Arabic}}{} +\setTransitionsForCJK{\fontspec{WenQuanYi Zen Hei}}{} +\setTransitionsForDiacritics{\fontspec{Droid Sans Arabic}}{} +\setTransitionTo{Hebrew}{\fontspec{David CLM}} +\setmainfont{CMU Serif} \newcommand{\fsfclosing}[1]{\par\nobreak\vspace{\parskip} \stopbreaks @@ -64,7 +82,7 @@ class CRM_Utils_PDF_Utils { \hspace*{\longindentation}\fi \parbox{\indentedwidth}{\raggedright \ignorespaces #1\\\\[1\medskipamount] - \hspace*{-0.25in}\includegraphics[scale=1.0]{sigjohns.pdf} + \hspace*{-0.25in}\includegraphics[scale=1.0]{/var/www/drupal-7.27/sites/all/modules/civicrm/sigjohns.pdf} \\\\ \ifx\@empty\fromsig @@ -75,16 +93,16 @@ class CRM_Utils_PDF_Utils { %% This line might be necessary, but it was not able to find utf8.def on my %% machine. -\usepackage[utf8x]{inputenc} +%% \usepackage[utf8x]{inputenc} \pagestyle{empty} \tolerance=8000 \address{\vspace{0.05in}} \signature{John Sullivan \\\\ Executive Director} \usepackage[ -top = 0.4in, -bottom = 0.9in, -left = 0.8in, -right = 0.8in]{geometry} +top = 1.5in, +bottom = 1.25in, +left = 1.0in, +right = 1.0in]{geometry} \begin{document} '; $footer=' @@ -123,8 +141,10 @@ right = 0.8in]{geometry} header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); echo $pdf; +// CRM_Utils_PDF_Utils::enqueuePDF($pdf); + } - } + } /** * @param $text @@ -316,6 +336,7 @@ right = 0.8in]{geometry} $snappy->setOption("margin-right", $margins[2] . $margins[0]); $snappy->setOption("margin-bottom", $margins[3] . $margins[0]); $snappy->setOption("margin-left", $margins[4] . $margins[0]); + $html = preg_replace('/{ }/', ' ', $html); $pdf = $snappy->getOutputFromHtml($html); if ($output) { return $pdf; @@ -324,6 +345,8 @@ right = 0.8in]{geometry} header('Content-Type: application/pdf'); header('Content-Disposition: attachment; filename="' . $fileName . '"'); echo $pdf; + //CRM_Utils_PDF_Utils::enqueuePDF($pdf); + } } diff --git a/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl b/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl index 98f60d3935..acd25cf3ec 100644 --- a/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl +++ b/templates/CRM/Contribute/Form/Contribution/PremiumBlock.tpl @@ -193,6 +193,14 @@ amount = 0; } + // next, check for contribution amount price sets + check_price_set('.contribution_amount-content input[type="radio"]'); + + // next, check for membership level price set + check_price_set('.membership_amount-content input[type="radio"]'); + + check_price_set(cj('.price-set-option-content input[type="radio"]')); + // make sure amount is a number at this point if(!amount) amount = 0; @@ -210,6 +218,7 @@ // update premiums function update_premiums() { var amount = get_amount(); + console.log('amount:', amount); $('.premium').each(function(){ var min_contribution = $(this).attr('min_contribution'); -- 2.25.1