From 032c9d10d4dbb4e11334d72f67b3a96d55ede165 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Fri, 8 Mar 2013 07:11:40 -0500 Subject: [PATCH] CRM-12056 - Avoid SQL error during pre-install check on older version of MySQL --- CRM/Core/DAO.php | 23 +++++++++++++++++++++-- CRM/Upgrade/Form.php | 4 ++-- install/index.php | 6 +++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index e54678e1a0..1eb3f9e895 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -743,7 +743,7 @@ FROM civicrm_domain * @static * @access public */ - static function getFieldValue($daoName, $searchValue, $returnColumn = 'name', $searchColumn = 'id', $force = false) { + static function getFieldValue($daoName, $searchValue, $returnColumn = 'name', $searchColumn = 'id', $force = FALSE) { if ( empty($searchValue) || trim(strtolower($searchValue)) == 'null' @@ -1315,7 +1315,7 @@ SELECT contact_id } if(in_array($FKClassName, CRM_Core_DAO::$_testEntitiesToSkip)){ $depObject = new $FKClassName(); - $depObject->find(true); + $depObject->find(TRUE); } elseif ($daoName == 'CRM_Member_DAO_MembershipType' && $name == 'member_of_contact_id') { // FIXME: the fields() metadata is not specific enough $depObject = CRM_Core_DAO::createTestObject($FKClassName, array('contact_type' => 'Organization')); @@ -1712,5 +1712,24 @@ SELECT contact_id return (empty($errors)) ? FALSE : TRUE; } + + /** + * Lookup the value of a MySQL global configuration variable. + * + * @param string $name e.g. "thread_stack" + * @param mixed $default + * @return mixed + */ + public static function getGlobalSetting($name, $default = NULL) { + // Alternatively, SELECT @@GLOBAL.thread_stack, but + // that has been reported to fail under MySQL 5.0 for OS X + $escapedName = self::escapeString($name); + $dao = CRM_Core_DAO::executeQuery("SHOW VARIABLES LIKE '$escapedName'"); + if ($dao->fetch()) { + return $dao->Value; + } else { + return $default; + } + } } diff --git a/CRM/Upgrade/Form.php b/CRM/Upgrade/Form.php index 035265cb31..d14e918b4b 100644 --- a/CRM/Upgrade/Form.php +++ b/CRM/Upgrade/Form.php @@ -403,8 +403,8 @@ SET version = '$version' $error = ts('CiviCRM %1 requires MySQL trigger privileges.', array(1 => $latestVer)); } - - if (CRM_Core_DAO::singleValueQuery('SELECT @@GLOBAL.thread_stack') < (1024*self::MINIMUM_THREAD_STACK)) { + + if (CRM_Core_DAO::getGlobalSetting('thread_stack', 0) < (1024*self::MINIMUM_THREAD_STACK)) { $error = ts('CiviCRM %1 requires MySQL thread stack >= %2k', array( 1 => $latestVer, 2 => self::MINIMUM_THREAD_STACK, diff --git a/install/index.php b/install/index.php index 8d744247e0..8272ac4bd1 100644 --- a/install/index.php +++ b/install/index.php @@ -904,14 +904,14 @@ class InstallRequirements { return; } - $result = mysql_query('SELECT @@GLOBAL.thread_stack', $conn); // bytes => kb + $result = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb if (!$result) { $testDetails[2] = 'Could not query thread_stack.'; $this->error($testDetails); } else { $values = mysql_fetch_row($result); - if ($values[0] < (1024*$minValueKB)) { - $testDetails[2] = 'MySQL "thread_stack" is ' . ($values[0]/1024) . 'k'; + if ($values[1] < (1024*$minValueKB)) { + $testDetails[2] = 'MySQL "thread_stack" is ' . ($values[1]/1024) . 'k'; $this->error($testDetails); } } -- 2.25.1