Merge pull request #15510 from civicrm/5.19
[civicrm-core.git] / CRM / Core / I18n / Schema.php
index 71627d76d4b039d71cbf821889ec4b00944363b5..64cb94b08f9f7e665f1ff31590fdb39d91d626b0 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 class CRM_Core_I18n_Schema {
 
@@ -73,7 +73,7 @@ class CRM_Core_I18n_Schema {
     // build the column-adding SQL queries
     $columns = CRM_Core_I18n_SchemaStructure::columns();
     $indices = CRM_Core_I18n_SchemaStructure::indices();
-    $queries = array();
+    $queries = [];
     foreach ($columns as $table => $hash) {
       // drop old indices
       if (isset($indices[$table])) {
@@ -167,7 +167,7 @@ class CRM_Core_I18n_Schema {
     $retain,
     $table,
     $class = 'CRM_Core_I18n_SchemaStructure',
-    $triggers = array()
+    $triggers = []
   ) {
     $domain = new CRM_Core_DAO_Domain();
     $domain->find(TRUE);
@@ -180,8 +180,8 @@ class CRM_Core_I18n_Schema {
 
     $columns =& $class::columns();
     $indices =& $class::indices();
-    $queries = array();
-    $dropQueries = array();
+    $queries = [];
+    $dropQueries = [];
     // drop indices
     if (isset($indices[$table])) {
       foreach ($indices[$table] as $index) {
@@ -260,7 +260,7 @@ class CRM_Core_I18n_Schema {
     // build the required SQL queries
     $columns = CRM_Core_I18n_SchemaStructure::columns();
     $indices = CRM_Core_I18n_SchemaStructure::indices();
-    $queries = array();
+    $queries = [];
     foreach ($columns as $table => $hash) {
       // add new columns
       foreach ($hash as $column => $type) {
@@ -314,13 +314,13 @@ class CRM_Core_I18n_Schema {
     }
     $indices =& $class::indices();
     $tables =& $class::tables();
-    $queries = array();
+    $queries = [];
     $dao = new CRM_Core_DAO();
 
     // get all of the already existing indices
-    $existing = array();
+    $existing = [];
     foreach (array_keys($indices) as $table) {
-      $existing[$table] = array();
+      $existing[$table] = [];
       $dao->query("SHOW INDEX FROM $table", FALSE);
       while ($dao->fetch()) {
         if (preg_match('/_[a-z][a-z]_[A-Z][A-Z]$/', $dao->Key_name)) {
@@ -417,9 +417,9 @@ class CRM_Core_I18n_Schema {
     $version = str_ireplace(".upgrade", "", $version);
 
     // fetch all the SchemaStructure versions we ship and sort by version
-    $schemas = array();
+    $schemas = [];
     foreach (scandir(dirname(__FILE__)) as $file) {
-      $matches = array();
+      $matches = [];
       if (preg_match('/^SchemaStructure_([0-9a-z_]+)\.php$/', $file, $matches)) {
         $schemas[] = str_replace('_', '.', $matches[1]);
       }
@@ -451,10 +451,10 @@ class CRM_Core_I18n_Schema {
     $indices =& $class::indices();
     $columns =& $class::columns();
     if (!isset($indices[$table])) {
-      return array();
+      return [];
     }
 
-    $queries = array();
+    $queries = [];
     foreach ($indices[$table] as $index) {
       $unique = isset($index['unique']) && $index['unique'] ? 'UNIQUE' : '';
       foreach ($index['field'] as $i => $col) {
@@ -495,8 +495,8 @@ class CRM_Core_I18n_Schema {
    */
   private static function createViewQuery($locale, $table, &$dao, $class = 'CRM_Core_I18n_SchemaStructure', $isUpgradeMode = FALSE) {
     $columns =& $class::columns();
-    $cols = array();
-    $tableCols = array();
+    $cols = [];
+    $tableCols = [];
     $dao->query("DESCRIBE {$table}", FALSE);
     while ($dao->fetch()) {
       // view non-internationalized columns directly
@@ -560,7 +560,7 @@ class CRM_Core_I18n_Schema {
         continue;
       }
 
-      $trigger = array();
+      $trigger = [];
 
       foreach ($hash as $column => $_) {
         $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
@@ -569,9 +569,9 @@ class CRM_Core_I18n_Schema {
         }
         foreach ($locales as $old) {
           $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
-          foreach (array_merge($locales, array(
+          foreach (array_merge($locales, [
             $locale,
-          )) as $loc) {
+          ]) as $loc) {
             if ($loc == $old) {
               continue;
             }
@@ -582,17 +582,17 @@ class CRM_Core_I18n_Schema {
       }
 
       $sql = implode(' ', $trigger);
-      $info[] = array(
-        'table' => array($table),
+      $info[] = [
+        'table' => [$table],
         'when' => 'BEFORE',
-        'event' => array('UPDATE'),
+        'event' => ['UPDATE'],
         'sql' => $sql,
-      );
+      ];
     }
 
     // take care of the ON INSERT triggers
     foreach ($columns as $table => $hash) {
-      $trigger = array();
+      $trigger = [];
       foreach ($hash as $column => $_) {
         $trigger[] = "IF NEW.{$column}_{$locale} IS NOT NULL THEN";
         foreach ($locales as $old) {
@@ -600,9 +600,9 @@ class CRM_Core_I18n_Schema {
         }
         foreach ($locales as $old) {
           $trigger[] = "ELSEIF NEW.{$column}_{$old} IS NOT NULL THEN";
-          foreach (array_merge($locales, array(
+          foreach (array_merge($locales, [
             $locale,
-          )) as $loc) {
+          ]) as $loc) {
             if ($loc == $old) {
               continue;
             }
@@ -613,12 +613,12 @@ class CRM_Core_I18n_Schema {
       }
 
       $sql = implode(' ', $trigger);
-      $info[] = array(
-        'table' => array($table),
+      $info[] = [
+        'table' => [$table],
         'when' => 'BEFORE',
-        'event' => array('INSERT'),
+        'event' => ['INSERT'],
         'sql' => $sql,
-      );
+      ];
     }
   }