/** * Check MySQL version: returns false only if version is gathered and it isn't suit * * @param string $errorMsg Error message if checking failed * @param string $value Actual value of the checked parameter * @param resource $isConnected MySQL connection link OPTIONAL * * @return boolean */ function checkMysqlVersion(&$errorMsg, &$value, $isConnected = false) { global $isDBConnected; $result = true; $value = xtr('unknown'); $pdoErrorMsg = ''; $version = false; if (defined('DB_URL')) { // Connect via PDO and get DB version $data = unserialize(constant('DB_URL')); // Support of Drupal 6 $db_url if (!is_array($data)) { $data = parseDbURL(constant('DB_URL')); } $isConnected = dbConnect($data, $pdoErrorMsg); if (!$isConnected) { $errorMsg = xtr('Can\'t connect to MySQL server') . (!empty($pdoErrorMsg) ? ': ' . $pdoErrorMsg : ''); } } if ($isConnected || $isDBConnected) { try { $version = \Includes\Utils\Database::getDbVersion(); } catch (Exception $e) { $pdoErrorMsg = $e->getMessage(); } // Check version if ($version) { x_install_log(xtr('MySQL version: ' . $version)); if (version_compare($version, constant('LC_MYSQL_VERSION_MIN')) < 0) { $result = false; $errorMsg = xtr('MySQL version must be :minver as a minimum.', array(':minver' => constant('LC_MYSQL_VERSION_MIN'))); } else { // Check for InnoDb support if (!\Includes\Utils\Database::isInnoDBSupported()) { $result = false; $errorMsg = xtr('MySQL server doesn\'t support InnoDB engine. It is required for X-Cart operation'); } } } else { $errorMsg = xtr('Cannot get the MySQL server version') . (!empty($pdoErrorMsg) ? ' : ' . $pdoErrorMsg : '.'); } } $value = $version; return $result; }
/** * Check if LiteCommerce installed * Use into Drupal connector * * :FIXME: check this carefully * * @param string $dbURL Database Url string (e.g. mysql://username:password@localhost/databasename) * * @return bool */ function isLiteCommerceInstalled($dbURL = null, &$message) { // Check by template and config.php file $checkResult = file_exists(LC_DIR_SKINS . 'admin/en/welcome.tpl') && (file_exists(LC_DIR_CONFIG . 'config.php') || file_exists(LC_DIR_CONFIG . 'config.local.php')); if ($checkResult) { // Get database options from config.php $configData = \Includes\Utils\ConfigParser::getOptions('database_details'); if (is_array($configData)) { // Check if host, dbname and username is not empty $checkResult = !empty($configData['hostspec']) && !empty($configData['database']) && !empty($configData['username']); if ($checkResult) { if (isset($dbURL)) { // Support of Drupal 6 installation if (is_array($dbURL)) { $data = $dbURL; } else { $data = parseDbURL($dbURL); } if (!empty($data)) { // Compare database options from config and from parameter $checkResult = $configData['hostspec'] == $data['mysqlhost'] && $configData['username'] == $data['mysqluser'] && $configData['password'] == $data['mysqlpass'] && $configData['database'] == $data['mysqlbase'] && (!isset($data['mysqlport']) || $configData['port'] == $data['mysqlport']) && (!isset($data['mysqlsock']) || $configData['socket'] == $data['mysqlsock']); if (!$checkResult) { $message = 'Database parameters (specified in Drupal and LiteCommerce configs) comparison failed'; } } else { $message = '$dbURL passed but hasn\'t any data or corrupted'; $checkResult = false; } } else { $data = null; } if ($checkResult) { // Check if connection works $checkResult = dbConnect($data, $errorMsg); if ($checkResult) { $res = dbFetchColumn('SELECT profile_id from xlite_profiles LIMIT 1', $errorMsg); if (empty($res)) { $message = 'There are no profiles found in the database'; $checkResult = false; } elseif (\Includes\Decorator\Utils\CacheManager::isRebuildNeeded(\Includes\Decorator\Utils\CacheManager::STEP_THIRD)) { $message = 'Cache isn\'t built yet'; $checkResult = false; } } else { $message = 'Cannot connect to the database'; } } } else { $message = 'Host, username or database name are empty'; } } else { $message = 'Corrupted LiteCommerce config file'; $checkResult = false; } } else { $message = 'config.php or admin/en/welcome.tpl files are not found'; } return $checkResult; }