CRM/Upgrade - Make the Tajikistan change replayable
authorTim Otten <totten@civicrm.org>
Thu, 12 Oct 2017 14:31:21 +0000 (15:31 +0100)
committerTim Otten <totten@civicrm.org>
Thu, 12 Oct 2017 14:31:21 +0000 (15:31 +0100)
CRM/Upgrade/Incremental/php/FourSeven.php
CRM/Upgrade/Incremental/sql/4.7.26.mysql.tpl

index a80352a4cba3ad5e944ab79f01294a5e0eb89cce..cf71dc5dc2dd0959e644d83e1bd0c09e2521b27d 100644 (file)
@@ -447,6 +447,7 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base
    */
   public function upgrade_4_7_26($rev) {
     $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
+    $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.'");
     $this->addTask('CRM-21195 - Add icon field to civicrm_navigation', 'addColumn',
@@ -1247,6 +1248,28 @@ FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_
     return TRUE;
   }
 
+  /**
+   * Add in missing Tajikistan Subdivisions
+   *
+   * @param \CRM_Queue_TaskContext $ctx
+   *
+   * @return bool
+   */
+  public static function tajikistanMissingSubdivisions(CRM_Queue_TaskContext $ctx) {
+    $sql = 'INSERT INTO civicrm_state_province (id, country_id, abbreviation, name) VALUES';
+    $updates = array();
+    if (!CRM_Core_DAO::singleValueQuery("Select id FROM civicrm_state_province WHERE country_id = 1209 AND name = 'Dushanbe'")) {
+      $updates[] = '(NULL, 1209, "DU", "Dushanbe")';
+    }
+    if (!CRM_Core_DAO::singleValueQuery("Select id FROM civicrm_state_province WHERE country_id = 1209 AND name = 'Nohiyahoi Tobei Jumhurí'")) {
+      $updates[] = '(NULL, 1209, "RA", "Nohiyahoi Tobei Jumhurí")';
+    }
+    if (!empty($updates)) {
+      CRM_Core_DAO::executeQuery($sql . implode(', ', $updates));
+    }
+    return TRUE;
+  }
+
   /**
    * Remove the contribution logging reports which have been broken for a very long time.
    *
index 55168d405a07e6cbfe3cb799cc60366412eb0494..b9310381e7bf87f0b3580f04a2fea4eb8a77ae65 100644 (file)
@@ -2,8 +2,3 @@
 
 -- 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.';
-
--- CRM-21234 Missing subdivisions of Tajikistan.
- INSERT INTO civicrm_state_province (id, country_id, abbreviation, name) VALUES
-   (NULL, 1209, "DU", "Dushanbe"),
-   (NULL, 1209, "RA", "Nohiyahoi Tobei Jumhurí");