Skip to content

Commit

Permalink
CRM-20892 Convert Created_date to default NULL and add in trigger to …
Browse files Browse the repository at this point in the history
…set it

Remove duplicate was

Move field around in table definition as per Eileen's comment
  • Loading branch information
seamuslee001 committed Sep 10, 2017
1 parent 619d330 commit e7a6eae
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 64 deletions.
48 changes: 24 additions & 24 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:7f90165e5c470ceb7e4644a5ab0660d1)
* (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 @@ -299,12 +305,6 @@ class CRM_Mailing_DAO_Mailing extends CRM_Core_DAO {
* @var string
*/
public $language;
/**
* When was the mailing (or closely related entity) was created or modified or deleted.
*
* @var timestamp
*/
public $modified_date;
/**
* Class constructor.
*/
Expand Down Expand Up @@ -679,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 @@ -689,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 Expand Up @@ -914,22 +930,6 @@ static function &fields() {
'optionEditPath' => 'civicrm/admin/options/languages',
)
) ,
'mailing_modified_date' => array(
'name' => 'modified_date',
'type' => CRM_Utils_Type::T_TIMESTAMP,
'title' => ts('Modified Date') ,
'description' => 'When was 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,
) ,
);
CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Upgrade/Incremental/php/FourSeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ public function upgrade_4_7_25($rev) {
* @param string $rev
*/
public function upgrade_4_7_26($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 was the mailing (or closely related entity) was created or modified or deleted.'");
$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.'");
}

/*
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.

22 changes: 11 additions & 11 deletions 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 Expand Up @@ -487,14 +497,4 @@
<type>Select</type>
</html>
</field>
<field>
<name>modified_date</name>
<uniqueName>mailing_modified_date</uniqueName>
<type>timestamp</type>
<comment>When was 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>
</table>

0 comments on commit e7a6eae

Please sign in to comment.