Merge pull request #4893 from colemanw/INFRA-132
[civicrm-core.git] / CRM / Logging / Schema.php
index d733c8446781fb29ef9c1973d6c54cc8bcf77ee4..2cd7b80006664e06da18df9dad02b2506b0b3e57 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -55,7 +55,7 @@ class CRM_Logging_Schema {
   /**
    * Populate $this->tables and $this->logs with current db state.
    */
-  function __construct() {
+  public function __construct() {
     $dao = new CRM_Contact_DAO_Contact();
     $civiDBName = $dao->_database;
 
@@ -74,10 +74,9 @@ AND    TABLE_NAME LIKE 'civicrm_%'
     $this->tables = preg_grep('/^civicrm_import_job_/', $this->tables, PREG_GREP_INVERT);
     $this->tables = preg_grep('/_cache$/', $this->tables, PREG_GREP_INVERT);
     $this->tables = preg_grep('/_log/', $this->tables, PREG_GREP_INVERT);
-    $this->tables = preg_grep('/^civicrm_task_action_temp_/', $this->tables, PREG_GREP_INVERT);
-    $this->tables = preg_grep('/^civicrm_export_temp_/', $this->tables, PREG_GREP_INVERT);
     $this->tables = preg_grep('/^civicrm_queue_/', $this->tables, PREG_GREP_INVERT);
     $this->tables = preg_grep('/^civicrm_menu/', $this->tables, PREG_GREP_INVERT); //CRM-14672
+    $this->tables = preg_grep('/_temp_/', $this->tables, PREG_GREP_INVERT);
 
     // do not log civicrm_mailing_event* tables, CRM-12300
     $this->tables = preg_grep('/^civicrm_mailing_event_/', $this->tables, PREG_GREP_INVERT);
@@ -108,14 +107,14 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * Return logging custom data tables.
    */
-  function customDataLogTables() {
+  public function customDataLogTables() {
     return preg_grep('/^log_civicrm_value_/', $this->logs);
   }
 
   /**
    * Return custom data tables for specified entity / extends.
    */
-  function entityCustomDataLogTables($extends) {
+  public function entityCustomDataLogTables($extends) {
     $customGroupTables = array();
     $customGroupDAO = CRM_Core_BAO_CustomGroup::getAllCustomGroupsByBaseEntity($extends);
     $customGroupDAO->find();
@@ -128,7 +127,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * Disable logging by dropping the triggers (but keep the log tables intact).
    */
-  function disableLogging() {
+  public function disableLogging() {
     $config = CRM_Core_Config::singleton();
     $config->logging = FALSE;
 
@@ -143,7 +142,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * Drop triggers for all logged tables.
    */
-  function dropTriggers($tableName = NULL) {
+  public function dropTriggers($tableName = NULL) {
     $dao = new CRM_Core_DAO;
 
     if ($tableName) {
@@ -187,7 +186,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
    *
    * @return void
    */
-  function enableLogging() {
+  public function enableLogging() {
     $this->fixSchemaDifferences(TRUE);
     $this->addReports();
   }
@@ -199,7 +198,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
    *
    * @return void
    */
-  function fixSchemaDifferences($enableLogging = FALSE) {
+  public function fixSchemaDifferences($enableLogging = FALSE) {
     $config = CRM_Core_Config::singleton();
     if ($enableLogging) {
       $config->logging = TRUE;
@@ -214,13 +213,16 @@ 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 mixed    array of columns to add or null (to check for the missing columns)
-   * @param $rebuildTrigger boolean should we rebuild the triggers
+   * @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 bool $rebuildTrigger
+   *   should we rebuild the triggers.
    *
    * @return void
    */
-  function fixSchemaDifferencesFor($table, $cols = array(), $rebuildTrigger = FALSE) {
+  public function fixSchemaDifferencesFor($table, $cols = array(), $rebuildTrigger = FALSE) {
     if (empty($table)) {
       return FALSE;
     }
@@ -290,7 +292,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
   /**
    * @param bool $rebuildTrigger
    */
-  function fixSchemaDifferencesForAll($rebuildTrigger = FALSE) {
+  public function fixSchemaDifferencesForAll($rebuildTrigger = FALSE) {
     $diffs = array();
     foreach ($this->tables as $table) {
       if (empty($this->logs[$table])) {
@@ -321,7 +323,7 @@ AND    TABLE_NAME LIKE 'log_civicrm_%'
    *
    * @return mixed
    */
-  function fixTimeStampAndNotNullSQL($query) {
+  public function fixTimeStampAndNotNullSQL($query) {
     $query = str_ireplace("TIMESTAMP NOT NULL", "TIMESTAMP NULL", $query);
     $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP", '', $query);
     $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP", '', $query);
@@ -411,7 +413,7 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
               'COLUMN_NAME' => $dao->COLUMN_NAME,
               'DATA_TYPE'   => $dao->DATA_TYPE,
               'IS_NULLABLE' => $dao->IS_NULLABLE,
-              'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT
+              'COLUMN_DEFAULT' => $dao->COLUMN_DEFAULT,
             );
       }
     }
@@ -424,7 +426,7 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
    *
    * @return array
    */
-  function columnsWithDiffSpecs($civiTable, $logTable) {
+  public function columnsWithDiffSpecs($civiTable, $logTable) {
     $civiTableSpecs = $this->columnSpecsOf($civiTable);
     $logTableSpecs  = $this->columnSpecsOf($logTable);
 
@@ -437,7 +439,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();
       }
 
@@ -447,11 +449,13 @@ WHERE  table_schema IN ('{$this->db}', '{$civiDB}')";
         if ($civiTableSpecs[$col]['DATA_TYPE'] != CRM_Utils_Array::value('DATA_TYPE', $logTableSpecs[$col])) {
           // if data-type is different, surely consider the column
           $diff['MODIFY'][] = $col;
-        } else if ($civiTableSpecs[$col]['IS_NULLABLE'] != CRM_Utils_Array::value('IS_NULLABLE', $logTableSpecs[$col]) &&
+        }
+        elseif ($civiTableSpecs[$col]['IS_NULLABLE'] != CRM_Utils_Array::value('IS_NULLABLE', $logTableSpecs[$col]) &&
           $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;
-        } else if ($civiTableSpecs[$col]['COLUMN_DEFAULT'] != CRM_Utils_Array::value('COLUMN_DEFAULT', $logTableSpecs[$col]) &&
+        }
+        elseif ($civiTableSpecs[$col]['COLUMN_DEFAULT'] != CRM_Utils_Array::value('COLUMN_DEFAULT', $logTableSpecs[$col]) &&
           !strstr($civiTableSpecs[$col]['COLUMN_DEFAULT'], 'TIMESTAMP')) {
           // if default property is different, and its not about a timestamp column, consider it
           $diff['MODIFY'][] = $col;
@@ -564,7 +568,7 @@ COLS;
    * @param null $tableName
    * @param bool $force
    */
-  function triggerInfo(&$info, $tableName = NULL, $force = FALSE) {
+  public function triggerInfo(&$info, $tableName = NULL, $force = FALSE) {
     // check if we have logging enabled
     $config =& CRM_Core_Config::singleton();
     if (!$config->logging) {
@@ -587,7 +591,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()))) {
@@ -595,7 +599,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} (";
@@ -654,15 +658,13 @@ COLS;
    * 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');
     }
   }
 
 }
-