Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-21687

MariaDB 10.2 and logging: log_civicrm_activity schema syntax error

    Details

    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code
    • Verified?:
      Yes

      Description

      When upgrading CiviCRM to 4.7.29 while running MariaDB, a schema change fails to execute.  There seem to be two ways to address the issue:

      File:  civicrm/CRM/Logging/Schema.php

      Below line 488 add:

      $query = str_ireplace("CURRENT_TIMESTAMP()", 'CURRENT_TIMESTAMP', $query);

      Or replace line 490 which reads:

      $query = str_ireplace("DEFAULT CURRENT_TIMESTAMP", '', $query);

      with:

      $query = preg_replace("/DEFAULT CURRENT_TIMESTAMP(())/", '', $query);

      Many thanks to @bgm for the direction on this.

      I have not done any testing on this in regards to MySQL 5.X.

      Related SE link:  https://civicrm.stackexchange.com/questions/22347/civicrm-upgrade-civicrm-log-civicrm-activity-error/22348#22348

      Mattermost thread:  https://chat.civicrm.org/civicrm/pl/o7gdy9aw33by7jkfbeu5keixnw

      backTrace

      #0 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Error.php(187): CRM_Core_Error::backtrace()
      #1 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(921): CRM_Core_Error::handle(Object(DB_Error))
      #2 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB.php(984): PEAR_Error->__construct("DB Error: syntax error", -2, 16, (Array:2), "ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #3 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(575): DB_Error->__construct(-2, 16, (Array:2), "ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #4 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/PEAR.php(223): PEAR->_raiseError(Object(DB_mysqli), NULL, -2, 16, (Array:2), "ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...", "DB_Error", TRUE)
      #5 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1905): PEAR->__call("raiseError", (Array:7))
      #6 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(933): DB_common->raiseError(-2, NULL, NULL, "ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...", "1064 ** You have an error in your SQL syntax; check the manual that correspon...")
      #7 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/mysqli.php(403): DB_mysqli->mysqliRaiseError()
      #8 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/common.php(1216): DB_mysqli->simpleQuery("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #9 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(2446): DB_common->query("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #10 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/packages/DB/DataObject.php(1635): DB_DataObject->_query("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #11 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(369): DB_DataObject->query("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...")
      #12 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/DAO.php(1318): CRM_Core_DAO->query("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...", FALSE)
      #13 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Logging/Schema.php(399): CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NU...", (Array:0), TRUE, NULL, FALSE, FALSE)
      #14 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Logging/Schema.php(468): CRM_Logging_Schema->fixSchemaDifferencesFor("civicrm_activity", (Array:3), FALSE)
      #15 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Logging/Schema.php(286): CRM_Logging_Schema->fixSchemaDifferencesForAll()
      #16 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Form.php(770): CRM_Logging_Schema->fixSchemaDifferences()
      #17 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Page/Upgrade.php(182): CRM_Upgrade_Form::doFinish()
      #18 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Upgrade/Page/Upgrade.php(81): CRM_Upgrade_Page_Upgrade->runFinish()
      #19 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(309): CRM_Upgrade_Page_Upgrade->run((Array:2), NULL)
      #20 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(84): CRM_Core_Invoke::runItem((Array:13))
      #21 /var/www/html/wp/wp-content/plugins/civicrm/civicrm/CRM/Core/Invoke.php(52): CRM_Core_Invoke::_invoke((Array:2))
      #22 /var/www/html/wp/wp-content/plugins/civicrm/civicrm.php(1216): CRM_Core_Invoke::invoke((Array:2))
      #23 /var/www/html/wp/wp-includes/class-wp-hook.php(286): CiviCRM_For_WordPress->invoke("")
      #24 /var/www/html/wp/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters("", (Array:1))
      #25 /var/www/html/wp/wp-includes/plugin.php(453): WP_Hook->do_action((Array:1))
      #26 /var/www/html/wp/wp-admin/admin.php(224): do_action("toplevel_page_CiviCRM")
      #27 {main}

      Database Error Code: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '() ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely rela' at line 1, 1064
      Additional Details:

      Array
      (
          [callback] => Array
              (
                  [0] => CRM_Core_Error
                  [1] => handle
              )

          [code] => -2
          [message] => DB Error: syntax error
          [mode] => 16
          [debug_info] => ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NULL () ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely related entity) was created or modified or deleted.' [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '() ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely rela' at line 1]
          [type] => DB_Error
          [user_info] => ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NULL () ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely related entity) was created or modified or deleted.' [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '() ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely rela' at line 1]
          [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="ALTER TABLE `civicrm`.log_civicrm_activity ADD   `modified_date` timestamp NULL () ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely related entity) was created or modified or deleted.' [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '() ON UPDATE current_timestamp() COMMENT 'When was the activity (or closely rela' at line 1]"]
      )

       

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gharris G H
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: