From a0f40af469a0fb9f31f80c595110dfa318ea91bc Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 26 Mar 2015 12:21:47 -0400 Subject: [PATCH] CRM-16155 - Cleanup and optimize api calls to prefetch mailing data --- CRM/Mailing/Info.php | 91 ++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/CRM/Mailing/Info.php b/CRM/Mailing/Info.php index ca87b76f65..273372de0e 100644 --- a/CRM/Mailing/Info.php +++ b/CRM/Mailing/Info.php @@ -58,7 +58,7 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { } /** - * EXPERIMENTAL: Get a list of AngularJS modules + * Get AngularJS modules and their dependencies * * @return array * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) @@ -95,60 +95,79 @@ class CRM_Mailing_Info extends CRM_Core_Component_Info { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); - $params = array('options' => array('limit' => 0)); + $params = array( + 'options' => array('limit' => 0), + 'sequential' => 1, + ); $civiMails = civicrm_api3('Mailing', 'get', $params + array( 'is_completed' => 1, 'return' => array('id', 'name', 'scheduled_date'), )); - $campNames = civicrm_api3('Campaign', 'get', $params); - $groupNames = civicrm_api3('Group', 'get', $params); - $headerfooterList = civicrm_api3('MailingComponent', 'get', $params); + $campNames = civicrm_api3('Campaign', 'get', $params + array( + 'is_active' => 1, + 'return' => 'title', + )); + $groupNames = civicrm_api3('Group', 'get', $params + array( + 'is_active' => 1, + 'return' => array('title', 'visibility', 'group_type', 'is_hidden'), + )); + $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array( + 'is_active' => 1, + 'return' => array('name', 'component_type', 'is_default'), + )); $emailAdd = civicrm_api3('Email', 'get', array( 'sequential' => 1, 'return' => "email", 'contact_id' => $contactID, )); + + // FIXME: Loading the contents of every template into the dom does not scale well $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array( 'sequential' => 1, + 'is_active' => 1, 'return' => array("msg_html", "id", "msg_title", "msg_subject", "msg_text"), 'workflow_id' => array('IS NULL' => ""), )); $mailGrp = civicrm_api3('MailingGroup', 'get', $params); - $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1)); + $mailTokens = civicrm_api3('Mailing', 'gettokens', array( + 'entity' => array('contact', 'mailing'), + 'sequential' => 1 + )); $fromAddress = civicrm_api3('OptionValue', 'get', $params + array( 'option_group_id' => "from_email_address", )); - CRM_Core_Resources::singleton()->addSetting(array( - 'crmMailing' => array( - 'civiMails' => array_values($civiMails['values']), - 'campNames' => array_values($campNames['values']), - 'groupNames' => array_values($groupNames['values']), - 'headerfooterList' => array_values($headerfooterList['values']), - 'mesTemplate' => array_values($mesTemplate['values']), - 'emailAdd' => array_values($emailAdd['values']), - 'mailGrp' => array_values($mailGrp['values']), - 'mailTokens' => $mailTokens['values'], - 'contactid' => $contactID, - 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), - 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), - 'fromAddress' => array_values($fromAddress['values']), - 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array( - 'id' => 'user_contact_id', - 'return' => 'email', - )), - 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), - 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(), - ), - )); - CRM_Core_Resources::singleton()->addPermissions(array( - 'view all contacts', - 'access CiviMail', - 'create mailings', - 'schedule mailings', - 'approve mailings', - 'delete in CiviMail', - )); + CRM_Core_Resources::singleton() + ->addSetting(array( + 'crmMailing' => array( + 'civiMails' => $civiMails['values'], + 'campNames' => $campNames['values'], + 'groupNames' => $groupNames['values'], + 'headerfooterList' => $headerfooterList['values'], + 'mesTemplate' => $mesTemplate['values'], + 'emailAdd' => $emailAdd['values'], + 'mailGrp' => $mailGrp['values'], + 'mailTokens' => $mailTokens['values'], + 'contactid' => $contactID, + 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), + 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), + 'fromAddress' => $fromAddress['values'], + 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array( + 'id' => 'user_contact_id', + 'return' => 'email', + )), + 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), + 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled(), + ), + )) + ->addPermissions(array( + 'view all contacts', + 'access CiviMail', + 'create mailings', + 'schedule mailings', + 'approve mailings', + 'delete in CiviMail', + )); return $result; } -- 2.25.1