From 4825de4addc7ff31729975caaf2d26318482ad1c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 24 Sep 2018 13:48:26 -0400 Subject: [PATCH] Rename MailingComponent BAO --- CRM/Admin/Page/AJAX.php | 2 +- CRM/Mailing/BAO/Component.php | 115 +------------------------- CRM/Mailing/BAO/Mailing.php | 14 ++-- CRM/Mailing/BAO/MailingComponent.php | 114 +++++++++++++++++++++++++ CRM/Mailing/Event/BAO/Confirm.php | 2 +- CRM/Mailing/Event/BAO/Reply.php | 2 +- CRM/Mailing/Event/BAO/Resubscribe.php | 2 +- CRM/Mailing/Event/BAO/Subscribe.php | 2 +- CRM/Mailing/Event/BAO/Unsubscribe.php | 2 +- CRM/Mailing/Form/Component.php | 12 +-- CRM/Mailing/Page/Component.php | 2 +- CRM/Mailing/PseudoConstant.php | 4 +- 12 files changed, 138 insertions(+), 135 deletions(-) create mode 100644 CRM/Mailing/BAO/MailingComponent.php diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 1fef6d99e8..24f4c25f58 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -165,7 +165,7 @@ class CRM_Admin_Page_AJAX { $ret['content'] = ts('Are you sure you want to disable this Participant Status?') . '

' . ts('Users will no longer be able to select this value when adding or editing Participant Status.'); break; - case 'CRM_Mailing_BAO_Component': + case 'CRM_Mailing_BAO_MailingComponent': $ret['content'] = ts('Are you sure you want to disable this component?'); break; diff --git a/CRM/Mailing/BAO/Component.php b/CRM/Mailing/BAO/Component.php index 77d7f85576..8137d4a642 100644 --- a/CRM/Mailing/BAO/Component.php +++ b/CRM/Mailing/BAO/Component.php @@ -1,121 +1,10 @@ copyValues($params); - if ($component->find(TRUE)) { - CRM_Core_DAO::storeValues($component, $defaults); - return $component; - } - return NULL; - } - - /** - * Update the is_active flag in the db. - * - * @param int $id - * Id of the database record. - * @param bool $is_active - * Value we want to set the is_active field. - * - * @return bool - * true if we found and updated the object, else false - */ - public static function setIsActive($id, $is_active) { - return CRM_Core_DAO::setFieldValue('CRM_Mailing_BAO_Component', $id, 'is_active', $is_active); - } - - /** - * Create and Update mailing component. - * - * @param array $params - * (reference ) an assoc array of name/value pairs. - * @param array $ids - * (deprecated) the array that holds all the db ids. - * - * @return CRM_Mailing_BAO_Component - */ - public static function add(&$params, $ids = array()) { - $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); - $component = new CRM_Mailing_BAO_Component(); - if ($id) { - $component->id = $id; - $component->find(TRUE); - } - - $component->copyValues($params); - if (empty($id) && empty($params['body_text'])) { - $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params)); - } - - if ($component->is_default) { - if (!empty($id)) { - $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2'; - $sqlParams = array( - 1 => array($component->component_type, 'String'), - 2 => array($id, 'Positive'), - ); - } - else { - $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1'; - $sqlParams = array( - 1 => array($component->component_type, 'String'), - ); - } - CRM_Core_DAO::executeQuery($sql, $sqlParams); - } - - $component->save(); - return $component; - } +class CRM_Mailing_BAO_Component extends CRM_Mailing_BAO_MailingComponent { } diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 212284f00e..f7087d35ca 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -823,14 +823,14 @@ ORDER BY civicrm_email.is_bulkmail DESC */ private function getHeaderFooter() { if (!$this->header and $this->header_id) { - $this->header = new CRM_Mailing_BAO_Component(); + $this->header = new CRM_Mailing_BAO_MailingComponent(); $this->header->id = $this->header_id; $this->header->find(TRUE); $this->header->free(); } if (!$this->footer and $this->footer_id) { - $this->footer = new CRM_Mailing_BAO_Component(); + $this->footer = new CRM_Mailing_BAO_MailingComponent(); $this->footer->id = $this->footer_id; $this->footer->find(TRUE); $this->footer->free(); @@ -1691,8 +1691,8 @@ ORDER BY civicrm_email.is_bulkmail DESC } if (!Civi::settings()->get('disable_mandatory_tokens_check')) { - $header = $mailing->header_id && $mailing->header_id != 'null' ? CRM_Mailing_BAO_Component::findById($mailing->header_id) : NULL; - $footer = $mailing->footer_id && $mailing->footer_id != 'null' ? CRM_Mailing_BAO_Component::findById($mailing->footer_id) : NULL; + $header = $mailing->header_id && $mailing->header_id != 'null' ? CRM_Mailing_BAO_MailingComponent::findById($mailing->header_id) : NULL; + $footer = $mailing->footer_id && $mailing->footer_id != 'null' ? CRM_Mailing_BAO_MailingComponent::findById($mailing->footer_id) : NULL; foreach (array('body_html', 'body_text') as $field) { if (empty($mailing->{$field})) { continue; @@ -1784,7 +1784,7 @@ ORDER BY civicrm_email.is_bulkmail DESC 'forward' => CRM_Mailing_Event_BAO_Forward::getTableName(), 'url' => CRM_Mailing_BAO_TrackableURL::getTableName(), 'urlopen' => CRM_Mailing_Event_BAO_TrackableURLOpen::getTableName(), - 'component' => CRM_Mailing_BAO_Component::getTableName(), + 'component' => CRM_Mailing_BAO_MailingComponent::getTableName(), 'spool' => CRM_Mailing_BAO_Spool::getTableName(), ); @@ -2718,7 +2718,7 @@ SELECT $mailing.id as mailing_id if (!$isSMS) { if ($report['mailing']['header_id']) { - $header = new CRM_Mailing_BAO_Component(); + $header = new CRM_Mailing_BAO_MailingComponent(); $header->id = $report['mailing']['header_id']; $header->find(TRUE); $htmlHeader = $header->body_html; @@ -2726,7 +2726,7 @@ SELECT $mailing.id as mailing_id } if ($report['mailing']['footer_id']) { - $footer = new CRM_Mailing_BAO_Component(); + $footer = new CRM_Mailing_BAO_MailingComponent(); $footer->id = $report['mailing']['footer_id']; $footer->find(TRUE); $htmlFooter = $footer->body_html; diff --git a/CRM/Mailing/BAO/MailingComponent.php b/CRM/Mailing/BAO/MailingComponent.php new file mode 100644 index 0000000000..9e1081cd0e --- /dev/null +++ b/CRM/Mailing/BAO/MailingComponent.php @@ -0,0 +1,114 @@ +copyValues($params); + if ($component->find(TRUE)) { + CRM_Core_DAO::storeValues($component, $defaults); + return $component; + } + return NULL; + } + + /** + * Update the is_active flag in the db. + * + * @param int $id + * Id of the database record. + * @param bool $is_active + * Value we want to set the is_active field. + * + * @return bool + * true if we found and updated the object, else false + */ + public static function setIsActive($id, $is_active) { + return CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_MailingComponent', $id, 'is_active', $is_active); + } + + /** + * Create and Update mailing component. + * + * @param array $params + * (reference ) an assoc array of name/value pairs. + * @param array $ids + * (deprecated) the array that holds all the db ids. + * + * @return CRM_Mailing_BAO_MailingComponent + */ + public static function add(&$params, $ids = array()) { + $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + $component = new CRM_Mailing_BAO_MailingComponent(); + if ($id) { + $component->id = $id; + $component->find(TRUE); + } + + $component->copyValues($params); + if (empty($id) && empty($params['body_text'])) { + $component->body_text = CRM_Utils_String::htmlToText(CRM_Utils_Array::value('body_html', $params)); + } + + if ($component->is_default) { + if (!empty($id)) { + $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1 AND id <> %2'; + $sqlParams = array( + 1 => array($component->component_type, 'String'), + 2 => array($id, 'Positive'), + ); + } + else { + $sql = 'UPDATE civicrm_mailing_component SET is_default = 0 WHERE component_type = %1'; + $sqlParams = array( + 1 => array($component->component_type, 'String'), + ); + } + CRM_Core_DAO::executeQuery($sql, $sqlParams); + } + + $component->save(); + return $component; + } + +} diff --git a/CRM/Mailing/Event/BAO/Confirm.php b/CRM/Mailing/Event/BAO/Confirm.php index 1d3c2d4d18..090a25d1f3 100644 --- a/CRM/Mailing/Event/BAO/Confirm.php +++ b/CRM/Mailing/Event/BAO/Confirm.php @@ -111,7 +111,7 @@ class CRM_Mailing_Event_BAO_Confirm extends CRM_Mailing_Event_DAO_Confirm { $group->id = $se->group_id; $group->find(TRUE); - $component = new CRM_Mailing_BAO_Component(); + $component = new CRM_Mailing_BAO_MailingComponent(); $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Welcome'; diff --git a/CRM/Mailing/Event/BAO/Reply.php b/CRM/Mailing/Event/BAO/Reply.php index 679822ffe0..dffa7512f9 100644 --- a/CRM/Mailing/Event/BAO/Reply.php +++ b/CRM/Mailing/Event/BAO/Reply.php @@ -242,7 +242,7 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply { $to = empty($replyto) ? $eq->email : $replyto; - $component = new CRM_Mailing_BAO_Component(); + $component = new CRM_Mailing_BAO_MailingComponent(); $component->id = $mailing->reply_id; $component->find(TRUE); diff --git a/CRM/Mailing/Event/BAO/Resubscribe.php b/CRM/Mailing/Event/BAO/Resubscribe.php index 360bd36bfe..04b06ba5f5 100644 --- a/CRM/Mailing/Event/BAO/Resubscribe.php +++ b/CRM/Mailing/Event/BAO/Resubscribe.php @@ -215,7 +215,7 @@ class CRM_Mailing_Event_BAO_Resubscribe { WHERE $jobTable.id = $job"); $dao->fetch(); - $component = new CRM_Mailing_BAO_Component(); + $component = new CRM_Mailing_BAO_MailingComponent(); $component->id = $dao->resubscribe_id; $component->find(TRUE); diff --git a/CRM/Mailing/Event/BAO/Subscribe.php b/CRM/Mailing/Event/BAO/Subscribe.php index d82776413b..4fb544de30 100644 --- a/CRM/Mailing/Event/BAO/Subscribe.php +++ b/CRM/Mailing/Event/BAO/Subscribe.php @@ -215,7 +215,7 @@ SELECT civicrm_email.id as email_id $group->id = $this->group_id; $group->find(TRUE); - $component = new CRM_Mailing_BAO_Component(); + $component = new CRM_Mailing_BAO_MailingComponent(); $component->is_default = 1; $component->is_active = 1; $component->component_type = 'Subscribe'; diff --git a/CRM/Mailing/Event/BAO/Unsubscribe.php b/CRM/Mailing/Event/BAO/Unsubscribe.php index aa6950cb8c..7f1dd8798c 100644 --- a/CRM/Mailing/Event/BAO/Unsubscribe.php +++ b/CRM/Mailing/Event/BAO/Unsubscribe.php @@ -353,7 +353,7 @@ WHERE email = %2 WHERE $jobTable.id = $job"); $dao->fetch(); - $component = new CRM_Mailing_BAO_Component(); + $component = new CRM_Mailing_BAO_MailingComponent(); if ($is_domain) { $component->id = $dao->optout_id; diff --git a/CRM/Mailing/Form/Component.php b/CRM/Mailing/Form/Component.php index b1875ee16b..d7c72e34ef 100644 --- a/CRM/Mailing/Form/Component.php +++ b/CRM/Mailing/Form/Component.php @@ -62,24 +62,24 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { $this->applyFilter(array('name', 'subject', 'body_html'), 'trim'); $this->add('text', 'name', ts('Name'), - CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_Component', 'name'), TRUE + CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_MailingComponent', 'name'), TRUE ); $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array( - 'CRM_Mailing_BAO_Component', + 'CRM_Mailing_BAO_MailingComponent', $this->_id, )); $this->add('select', 'component_type', ts('Component Type'), CRM_Core_SelectValues::mailingComponents()); $this->add('text', 'subject', ts('Subject'), - CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_Component', 'subject'), + CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_MailingComponent', 'subject'), TRUE ); $this->add('textarea', 'body_text', ts('Body - TEXT Format'), - CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_Component', 'body_text') + CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_MailingComponent', 'body_text') ); $this->add('textarea', 'body_html', ts('Body - HTML Format'), - CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_Component', 'body_html') + CRM_Core_DAO::getAttribute('CRM_Mailing_BAO_MailingComponent', 'body_html') ); $this->addYesNo('is_default', ts('Default?')); @@ -132,7 +132,7 @@ class CRM_Mailing_Form_Component extends CRM_Core_Form { $params['id'] = $this->_id; } - $component = CRM_Mailing_BAO_Component::add($params); + $component = CRM_Mailing_BAO_MailingComponent::add($params); CRM_Core_Session::setStatus(ts('The mailing component \'%1\' has been saved.', array( 1 => $component->name, ) diff --git a/CRM/Mailing/Page/Component.php b/CRM/Mailing/Page/Component.php index d587d15beb..fbf5627e7b 100644 --- a/CRM/Mailing/Page/Component.php +++ b/CRM/Mailing/Page/Component.php @@ -51,7 +51,7 @@ class CRM_Mailing_Page_Component extends CRM_Core_Page_Basic { * Classname of BAO. */ public function getBAOName() { - return 'CRM_Mailing_BAO_Component'; + return 'CRM_Mailing_BAO_MailingComponent'; } /** diff --git a/CRM/Mailing/PseudoConstant.php b/CRM/Mailing/PseudoConstant.php index bebcc3fc17..460084d77f 100644 --- a/CRM/Mailing/PseudoConstant.php +++ b/CRM/Mailing/PseudoConstant.php @@ -158,13 +158,13 @@ class CRM_Mailing_PseudoConstant extends CRM_Core_PseudoConstant { } if (!$type) { self::$component[$name] = NULL; - CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_BAO_Component'); + CRM_Core_PseudoConstant::populate(self::$component[$name], 'CRM_Mailing_BAO_MailingComponent'); } else { // we need to add an additional filter for $type self::$component[$name] = array(); - $object = new CRM_Mailing_BAO_Component(); + $object = new CRM_Mailing_BAO_MailingComponent(); $object->component_type = $type; $object->selectAdd(); $object->selectAdd("id, name"); -- 2.25.1