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

CRM-20892 Add in modified_date column to civicrm_mailing to assist in… #10953

Merged
merged 3 commits into from
Sep 11, 2017
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
10 changes: 9 additions & 1 deletion CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,11 +1600,19 @@ public static function add(&$params, $ids = array()) {
) {
$params['replyto_email'] = $params['from_email'];
}

$mailing->copyValues($params);

// CRM-20892 Unset Modifed Date here so that MySQL can correctly set an updated modfied date.
unset($mailing->modified_date);
$result = $mailing->save();

// CRM-20892 Re find record after saing so we can set the updated modified date in the result.
$mailing->find(TRUE);

if (isset($mailing->modified_date)) {
$result->modified_date = $mailing->modified_date;
}

if (!empty($ids['mailing'])) {
CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
}
Expand Down
26 changes: 24 additions & 2 deletions CRM/Mailing/DAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*
* Generated from xml/schema/CRM/Mailing/Mailing.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:9a7cf33adcdee2e83d5fe1b5a28186cb)
* (GenCodeChecksum:3e332257744be5cf9d7a2545f69f67eb)
*/
require_once 'CRM/Core/DAO.php';
require_once 'CRM/Utils/Type.php';
Expand Down Expand Up @@ -210,6 +210,12 @@ class CRM_Mailing_DAO_Mailing extends CRM_Core_DAO {
* @var timestamp
*/
public $created_date;
/**
* When the mailing (or closely related entity) was created or modified or deleted.
*
* @var timestamp
*/
public $modified_date;
/**
* FK to Contact ID who scheduled this mailing
*
Expand Down Expand Up @@ -673,7 +679,7 @@ static function &fields() {
'title' => ts('Mailing Created Date') ,
'description' => 'Date and time this mailing was created.',
'required' => false,
'default' => 'CURRENT_TIMESTAMP',
'default' => 'NULL',
'table_name' => 'civicrm_mailing',
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
Expand All @@ -683,6 +689,22 @@ static function &fields() {
'formatType' => 'activityDateTime',
) ,
) ,
'mailing_modified_date' => array(
'name' => 'modified_date',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'title' => ts('Modified Date') ,
'description' => 'When the mailing (or closely related entity) was created or modified or deleted.',
'required' => false,
'export' => true,
'where' => 'civicrm_mailing.modified_date',
'headerPattern' => '',
'dataPattern' => '',
'default' => 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
'table_name' => 'civicrm_mailing',
'entity' => 'Mailing',
'bao' => 'CRM_Mailing_BAO_Mailing',
'localizable' => 0,
) ,
'scheduled_id' => array(
'name' => 'scheduled_id',
'type' => CRM_Utils_Type::T_INT,
Expand Down
10 changes: 10 additions & 0 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ public function upgrade_4_7_25($rev) {
'civicrm_case', 'modified_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When was the case (or closely related entity) was created or modified or deleted.'");
}

/**
* Upgrade function.
*
* @param string $rev
*/
public function upgrade_4_7_26($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
$this->addTask('CRM-20892 - Add modified_date to civicrm_mailing', 'addColumn',
'civicrm_mailing', 'modified_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When the mailing (or closely related entity) was created or modified or deleted.'");
}

/*
* Important! All upgrade functions MUST add a 'runSql' task.
Expand Down
3 changes: 3 additions & 0 deletions CRM/Upgrade/Incremental/sql/4.7.26.mysql.tpl
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
{* file to handle db changes in 4.7.26 during upgrade *}

-- CRM-20892 Change created_date default so that we can add a modified_date column
ALTER TABLE civicrm_mailing CHANGE created_date created_date timestamp NULL DEFAULT NULL COMMENT 'Date and time this mailing was created.';
5 changes: 5 additions & 0 deletions Civi/Core/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ public function createContainer() {
->setFactory(array($class, 'singleton'));
}

$container->setDefinition('civi.mailing.triggers', new Definition(
'Civi\Core\SqlTrigger\TimestampTriggers',
array('civicrm_mailing', 'Mailing')
))->addTag('kernel.event_listener', array('event' => 'hook_civicrm_triggerInfo', 'method' => 'onTriggerInfo'));

$container->setDefinition('civi.activity.triggers', new Definition(
'Civi\Core\SqlTrigger\TimestampTriggers',
array('civicrm_activity', 'Activity')
Expand Down
54 changes: 27 additions & 27 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion xml/schema/Mailing/Mailing.xml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@
<field>
<name>created_date</name>
<type>timestamp</type>
<default>CURRENT_TIMESTAMP</default>
<default>NULL</default>
<required>false</required>
<title>Mailing Created Date</title>
<comment>Date and time this mailing was created.</comment>
Expand All @@ -282,6 +282,16 @@
<formatType>activityDateTime</formatType>
</html>
</field>
<field>
<name>modified_date</name>
<uniqueName>mailing_modified_date</uniqueName>
<type>timestamp</type>
<comment>When the mailing (or closely related entity) was created or modified or deleted.</comment>
<required>false</required>
<export>true</export>
<default>CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP</default>
<add>4.7</add>
</field>
<field>
<name>scheduled_id</name>
<title>Scheduled By</title>
Expand Down