CRM-20892 Fix up issue where created_date may not have yet been converted to timestam...
authorSeamus Lee <seamuslee001@gmail.com>
Sun, 29 Oct 2017 21:15:10 +0000 (08:15 +1100)
committerSeamus Lee <seamuslee001@gmail.com>
Sun, 29 Oct 2017 21:15:10 +0000 (08:15 +1100)
CRM/Upgrade/Incremental/php/FourSeven.php
CRM/Upgrade/Incremental/sql/4.7.27.mysql.tpl

index d1bc87ba8b7f863f6a64089c016efeebdf54ae9b..d51e716e5d7fd0b057b348f0cae054900f173981 100644 (file)
@@ -447,6 +447,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
    */
   public function upgrade_4_7_27($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+    $this->addTask('CRM-20892 Change created_date to default to NULL', 'civiMailingCreatedDateNull');
     $this->addTask('CRM-21234 Missing subdivisions of Tajikistan', 'tajikistanMissingSubdivisions');
     $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.'");
@@ -1310,4 +1311,17 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_
     return $config->imageUploadDir && $config->imageUploadURL && $check->isDirAccessible($config->imageUploadDir, $config->imageUploadURL);
   }
 
+  /**
+   * CRM-20892 Convert default of created_date in civicrm_mailing table to NULL
+   * @return bool
+   */
+  public static function civiMailingCreatedDateNull(CRM_Queue_TaskContext $ctx) {
+    $dataType = 'timestamp';
+    if (CRM_Utils_Check_Component_Timestamps::isFieldType('civicrm_mailing', 'created_date', 'datetime')) {
+      $dataType = 'datetime';
+    }
+    CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_mailing CHANGE created_date created_date {$dataType} NULL DEFAULT NULL COMMENT 'Date and time this mailing was created.'");
+    return TRUE;
+  }
+
 }
index 749a947a170c6543e22e7f1791850e8397a7348d..a971b26276bef6d93ed2da0903b7f9718fcc9740 100644 (file)
@@ -1,4 +1 @@
 {* file to handle db changes in 4.7.27 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.';