Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed Mailing Component entity #12728

Merged
merged 3 commits into from
Sep 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CRM/Admin/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static function getStatusMsg() {
$ret['content'] = ts('Are you sure you want to disable this Participant Status?') . '<br/><br/> ' . 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;

Expand Down
6 changes: 3 additions & 3 deletions CRM/Core/DAO/AllCoreTables.data.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@
'class' => 'CRM_Batch_DAO_EntityBatch',
'table' => 'civicrm_entity_batch',
],
'CRM_Mailing_DAO_Component' => [
'name' => 'Component',
'class' => 'CRM_Mailing_DAO_Component',
'CRM_Mailing_DAO_MailingComponent' => [
'name' => 'MailingComponent',
'class' => 'CRM_Mailing_DAO_MailingComponent',
'table' => 'civicrm_mailing_component',
],
'CRM_Mailing_DAO_MailingAB' => [
Expand Down
3 changes: 2 additions & 1 deletion CRM/Core/DAO/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/Component.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:14ca0040d5a5656fd5dd91ad60a8ac89)
* (GenCodeChecksum:d0152fb407a743b3e15fd20c35f41c67)
*/

/**
Expand Down Expand Up @@ -69,6 +69,7 @@ public static function &fields() {
'id' => [
'name' => 'id',
'type' => CRM_Utils_Type::T_INT,
'title' => ts('Component ID'),
'description' => 'Component ID',
'required' => TRUE,
'table_name' => 'civicrm_component',
Expand Down
115 changes: 2 additions & 113 deletions CRM/Mailing/BAO/Component.php
Original file line number Diff line number Diff line change
@@ -1,121 +1,10 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @deprecated copy of renamed class.
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
*/
class CRM_Mailing_BAO_Component extends CRM_Mailing_DAO_Component {

/**
* Class constructor.
*/
public function __construct() {
parent::__construct();
}

/**
* Fetch object based on array of properties.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $defaults
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Core_BAO_LocationType.
*/
public static function retrieve(&$params, &$defaults) {
$component = new CRM_Mailing_DAO_Component();
$component->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_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_DAO_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 {

}
14 changes: 7 additions & 7 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,14 +823,14 @@ public function getTestRecipients($testParams) {
*/
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();
Expand Down Expand Up @@ -1691,8 +1691,8 @@ public static function checkSendable($mailing) {
}

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;
Expand Down Expand Up @@ -1784,7 +1784,7 @@ public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
'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(),
);

Expand Down Expand Up @@ -2718,15 +2718,15 @@ public static function getMailingContent(&$report, &$form, $isSMS = FALSE) {

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;
$textHeader = $header->body_text;
}

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;
Expand Down
114 changes: 114 additions & 0 deletions CRM/Mailing/BAO/MailingComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
*/
class CRM_Mailing_BAO_MailingComponent extends CRM_Mailing_DAO_MailingComponent {

/**
* Fetch object based on array of properties.
*
* @param array $params
* (reference ) an assoc array of name/value pairs.
* @param array $defaults
* (reference ) an assoc array to hold the flattened values.
*
* @return CRM_Core_BAO_LocationType.
*/
public static function retrieve(&$params, &$defaults) {
$component = new CRM_Mailing_DAO_MailingComponent();
$component->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;
}

}
12 changes: 6 additions & 6 deletions CRM/Mailing/DAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Mailing/Mailing.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:3e332257744be5cf9d7a2545f69f67eb)
* (GenCodeChecksum:3e943186d58d8e39d9765ce22d85ac79)
*/

/**
Expand Down Expand Up @@ -401,7 +401,7 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
'FKClassName' => 'CRM_Mailing_DAO_Component',
'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
],
'footer_id' => [
'name' => 'footer_id',
Expand All @@ -412,7 +412,7 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
'FKClassName' => 'CRM_Mailing_DAO_Component',
'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
],
'reply_id' => [
'name' => 'reply_id',
Expand All @@ -423,7 +423,7 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
'FKClassName' => 'CRM_Mailing_DAO_Component',
'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
],
'unsubscribe_id' => [
'name' => 'unsubscribe_id',
Expand All @@ -434,7 +434,7 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
'FKClassName' => 'CRM_Mailing_DAO_Component',
'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
],
'resubscribe_id' => [
'name' => 'resubscribe_id',
Expand All @@ -454,7 +454,7 @@ public static function &fields() {
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
'FKClassName' => 'CRM_Mailing_DAO_Component',
'FKClassName' => 'CRM_Mailing_DAO_MailingComponent',
],
'name' => [
'name' => 'name',
Expand Down
Loading