Merge pull request #5109 from colemanw/buttons
[civicrm-core.git] / CRM / Logging / Schema.php
index 17846862a9a2edb87cf51451190f1535077e6e96..6c6fe46cd200672c638e1173ffb4ac86932d3257 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
@@ -48,7 +48,7 @@ class CRM_Logging_Schema {
 
   //CRM-13028 / NYSS-6933 - table => array (cols) - to be excluded from the update statement
   private $exceptions = array(
-    'civicrm_job'   => array('last_run'),
+    'civicrm_job' => array('last_run'),
     'civicrm_group' => array('cache_date'),
   );
 
@@ -143,7 +143,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
    * Drop triggers for all logged tables.
    */
   public function dropTriggers($tableName = NULL) {
-    $dao = new CRM_Core_DAO;
+    $dao = new CRM_Core_DAO();
 
     if ($tableName) {
       $tableNames = array($tableName);
@@ -160,7 +160,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
       $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_before_update");
       $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_before_delete");
 
-     // after triggers
+      // after triggers
       $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_insert");
       $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_update");
       $dao->executeQuery("DROP TRIGGER IF EXISTS {$validName}_after_delete");
@@ -194,7 +194,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * Sync log tables and rebuild triggers.
    *
-   * @param bool $enableLogging: Ensure logging is enabled
+   * @param bool $enableLogging : Ensure logging is enabled
    *
    * @return void
    */
@@ -213,12 +213,12 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * Add missing (potentially specified) log table columns for the given table.
    *
-   * @param $table
-   *   String name of the relevant table.
-   * @param $cols
+   * @param string $table
+   *   name of the relevant table.
+   * @param array $cols
    *   Mixed array of columns to add or null (to check for the missing columns).
-   * @param $rebuildTrigger
-   *   Boolean should we rebuild the triggers.
+   * @param bool $rebuildTrigger
+   *   should we rebuild the triggers.
    *
    * @return void
    */
@@ -313,12 +313,11 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
     }
   }
 
-  /*
-   * log_civicrm_contact.modified_date for example would always be copied from civicrm_contact.modified_date,
+  /**
+   * Log_civicrm_contact.modified_date for example would always be copied from civicrm_contact.modified_date,
    * so there's no need for a default timestamp and therefore we remove such default timestamps
    * also eliminate the NOT NULL constraint, since we always copy and schema can change down the road)
-   */
-  /**
+   *
    * @param $query
    *
    * @return mixed
@@ -348,13 +347,14 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
     // add report instances
     $domain_id = CRM_Core_Config::domainID();
     foreach ($this->reports as $report) {
-      $dao             = new CRM_Report_DAO_ReportInstance;
-      $dao->domain_id  = $domain_id;
-      $dao->report_id  = $report;
-      $dao->title      = $titles[$report];
+      $dao = new CRM_Report_DAO_ReportInstance();
+      $dao->domain_id = $domain_id;
+      $dao->report_id = $report;
+      $dao->title = $titles[$report];
       $dao->permission = 'administer CiviCRM';
-      if ($report == 'logging/contact/summary')
+      if ($report == 'logging/contact/summary') {
         $dao->is_reserved = 1;
+      }
       $dao->insert();
     }
   }
@@ -408,13 +408,12 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
         if (!array_key_exists($dao->TABLE_NAME, $columnSpecs)) {
           $columnSpecs[$dao->TABLE_NAME] = array();
         }
-        $columnSpecs[$dao->TABLE_NAME][$dao->COLUMN_NAME] =
-          array(
-              'COLUMN_NAME' => $dao->COLUMN_NAME,
-              'DATA_TYPE'   => $dao->DATA_TYPE,
-              'IS_NULLABLE' => $dao->IS_NULLABLE,
-              'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT
-            );
+        $columnSpecs[$dao->TABLE_NAME][$dao->COLUMN_NAME] = array(
+          'COLUMN_NAME' => $dao->COLUMN_NAME,
+          'DATA_TYPE' => $dao->DATA_TYPE,
+          'IS_NULLABLE' => $dao->IS_NULLABLE,
+          'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT,
+        );
       }
     }
     return $columnSpecs[$table];
@@ -428,7 +427,7 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
    */
   public function columnsWithDiffSpecs($civiTable, $logTable) {
     $civiTableSpecs = $this->columnSpecsOf($civiTable);
-    $logTableSpecs  = $this->columnSpecsOf($logTable);
+    $logTableSpecs = $this->columnSpecsOf($logTable);
 
     $diff = array('ADD' => array(), 'MODIFY' => array(), 'OBSOLETE' => array());
 
@@ -439,7 +438,7 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
     // NOTE: we consider only those columns for modifications where there is a spec change, and that the column definition
     // wasn't deliberately modified by fixTimeStampAndNotNullSQL() method.
     foreach ($civiTableSpecs as $col => $colSpecs) {
-      if (!isset($logTableSpecs[$col]) || !is_array($logTableSpecs[$col]) ) {
+      if (!isset($logTableSpecs[$col]) || !is_array($logTableSpecs[$col])) {
         $logTableSpecs[$col] = array();
       }
 
@@ -451,12 +450,14 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
           $diff['MODIFY'][] = $col;
         }
         elseif ($civiTableSpecs[$col]['IS_NULLABLE'] != CRM_Utils_Array::value('IS_NULLABLE', $logTableSpecs[$col]) &&
-          $logTableSpecs[$col]['IS_NULLABLE'] == 'NO') {
+          $logTableSpecs[$col]['IS_NULLABLE'] == 'NO'
+        ) {
           // if is-null property is different, and log table's column is NOT-NULL, surely consider the column
           $diff['MODIFY'][] = $col;
         }
         elseif ($civiTableSpecs[$col]['COLUMN_DEFAULT'] != CRM_Utils_Array::value('COLUMN_DEFAULT', $logTableSpecs[$col]) &&
-          !strstr($civiTableSpecs[$col]['COLUMN_DEFAULT'], 'TIMESTAMP')) {
+          !strstr($civiTableSpecs[$col]['COLUMN_DEFAULT'], 'TIMESTAMP')
+        ) {
           // if default property is different, and its not about a timestamp column, consider it
           $diff['MODIFY'][] = $col;
         }
@@ -467,7 +468,8 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
     $oldCols = array_diff(array_keys($logTableSpecs), array_keys($civiTableSpecs));
     foreach ($oldCols as $col) {
       if (!in_array($col, array('log_date', 'log_conn_id', 'log_user_id', 'log_action')) &&
-        $logTableSpecs[$col]['IS_NULLABLE'] == 'NO') {
+        $logTableSpecs[$col]['IS_NULLABLE'] == 'NO'
+      ) {
         // if its a column present only in log table, not among those used by log tables for special purpose, and not-null
         $diff['OBSOLETE'][] = $col;
       }
@@ -528,7 +530,7 @@ COLS;
     // delete report instances
     $domain_id = CRM_Core_Config::domainID();
     foreach ($this->reports as $report) {
-      $dao            = new CRM_Report_DAO_ReportInstance;
+      $dao = new CRM_Report_DAO_ReportInstance();
       $dao->domain_id = $domain_id;
       $dao->report_id = $report;
       $dao->delete();
@@ -591,7 +593,7 @@ COLS;
       $columns = $this->columnsOf($table, $force);
 
       // only do the change if any data has changed
-      $cond = array( );
+      $cond = array();
       foreach ($columns as $column) {
         // ignore modified_date changes
         if ($column != 'modified_date' && !in_array($column, CRM_Utils_Array::value($table, $this->exceptions, array()))) {
@@ -599,7 +601,7 @@ COLS;
         }
       }
       $suppressLoggingCond = "@civicrm_disable_logging IS NULL OR @civicrm_disable_logging = 0";
-      $updateSQL = "IF ( (" . implode( ' OR ', $cond ) . ") AND ( $suppressLoggingCond ) ) THEN ";
+      $updateSQL = "IF ( (" . implode(' OR ', $cond) . ") AND ( $suppressLoggingCond ) ) THEN ";
 
       if ($this->useDBPrefix) {
         $sqlStmt = "INSERT INTO `{$this->db}`.log_{tableName} (";
@@ -617,13 +619,13 @@ COLS;
 
       $sqlStmt = '';
       foreach ($columns as $column) {
-        $sqlStmt   .= "NEW.$column, ";
+        $sqlStmt .= "NEW.$column, ";
         $deleteSQL .= "OLD.$column, ";
       }
-      $sqlStmt   .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');";
+      $sqlStmt .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');";
       $deleteSQL .= "CONNECTION_ID(), @civicrm_user_id, '{eventName}');";
 
-      $sqlStmt   .= "END IF;";
+      $sqlStmt .= "END IF;";
       $deleteSQL .= "END IF;";
 
       $insertSQL .= $sqlStmt;
@@ -657,13 +659,12 @@ COLS;
    * where we want to do a mass cleanup but dont want to bother with
    * an audit trail
    *
-   * @static
    */
-  public static function disableLoggingForThisConnection( ) {
+  public static function disableLoggingForThisConnection() {
     // do this only if logging is enabled
-    $config = CRM_Core_Config::singleton( );
-    if ( $config->logging ) {
-      CRM_Core_DAO::executeQuery( 'SET @civicrm_disable_logging = 1' );
+    $config = CRM_Core_Config::singleton();
+    if ($config->logging) {
+      CRM_Core_DAO::executeQuery('SET @civicrm_disable_logging = 1');
     }
   }