function is_osclass_installed() { if (!file_exists(ABS_PATH . 'config.php')) { return false; } require_once ABS_PATH . 'config.php'; $conn = new DBConnectionClass(osc_db_host(), osc_db_user(), osc_db_password(), osc_db_name()); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); $rs = $comm->query(sprintf("SELECT * FROM %st_preference WHERE s_name = 'osclass_installed'", DB_TABLE_PREFIX)); if ($rs == false) { return false; } if ($rs->numRows() != 1) { return false; } return true; }
function oc_install() { $dbhost = Params::getParam('dbhost'); $dbname = Params::getParam('dbname'); $username = Params::getParam('username'); $password = Params::getParam('password'); $tableprefix = Params::getParam('tableprefix'); $createdb = false; if ($tableprefix == '') { $tableprefix = 'oc_'; } if (Params::getParam('createdb') != '') { $createdb = true; } if ($createdb) { $adminuser = Params::getParam('admin_username'); $adminpwd = Params::getParam('admin_password'); $master_conn = new DBConnectionClass($dbhost, $adminuser, $adminpwd, ''); $error_num = $master_conn->getErrorConnectionLevel(); if ($error_num > 0) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot connect to database. Error number: ' . $error_num, __FILE__ . "::" . __LINE__); } switch ($error_num) { case 1049: return array('error' => 'The database doesn\'t exist. You should check the "Create DB" checkbox and fill username and password with the right privileges'); break; case 1045: return array('error' => 'Cannot connect to the database. Check if the user has privileges.'); break; case 1044: return array('error' => 'Cannot connect to the database. Check if the username and password are correct.'); break; case 2005: return array('error' => 'Cannot resolve MySQL host. Check if the host is correct.'); break; default: return array('error' => 'Cannot connect to database. Error number: ' . $error_num . '.'); break; } } $m_db = $master_conn->getOsclassDb(); $comm = new DBCommandClass($m_db); $comm->query(sprintf("CREATE DATABASE IF NOT EXISTS %s DEFAULT CHARACTER SET 'UTF8' COLLATE 'UTF8_GENERAL_CI'", $dbname)); $error_num = $comm->getErrorLevel(); if ($error_num > 0) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot create the database. Error number: ' . $error_num, __FILE__ . "::" . __LINE__); } if (in_array($error_num, array(1006, 1044, 1045))) { return array('error' => 'Cannot create the database. Check if the admin username and password are correct.'); } return array('error' => 'Cannot create the database. Error number: ' . $error_num . '.'); } unset($conn); unset($comm); unset($master_conn); } $conn = new DBConnectionClass($dbhost, $username, $password, $dbname); $error_num = $conn->getErrorLevel(); if ($error_num > 0) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot connect to database. Error number: ' . $error_num, __FILE__ . "::" . __LINE__); } switch ($error_num) { case 1049: return array('error' => 'The database doesn\'t exist. You should check the "Create DB" checkbox and fill username and password with the right privileges'); break; case 1045: return array('error' => 'Cannot connect to the database. Check if the user has privileges.'); break; case 1044: return array('error' => 'Cannot connect to the database. Check if the username and password are correct.'); break; case 2005: return array('error' => 'Cannot resolve MySQL host. Check if the host is correct.'); break; default: return array('error' => 'Cannot connect to database. Error number: ' . $error_num . '.'); break; } } if (file_exists(ABS_PATH . 'config.php')) { if (!is_writable(ABS_PATH . 'config.php')) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot write in config.php file. Check if the file is writable.', __FILE__ . "::" . __LINE__); } return array('error' => 'Cannot write in config.php file. Check if the file is writable.'); } create_config_file($dbname, $username, $password, $dbhost, $tableprefix); } else { if (!file_exists(ABS_PATH . 'config-sample.php')) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('It doesn\'t exist config-sample.php. Check if you have everything well decompressed.', __FILE__ . "::" . __LINE__); } return array('error' => 'It doesn\'t exist config-sample.php. Check if you have everything well decompressed.'); } if (!is_writable(ABS_PATH)) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Can\'t copy config-sample.php. Check if the root directory is writable.', __FILE__ . "::" . __LINE__); } return array('error' => 'Can\'t copy config-sample.php. Check if the root directory is writable.'); } copy_config_file($dbname, $username, $password, $dbhost, $tableprefix); } require_once ABS_PATH . 'config.php'; $sql = file_get_contents(ABS_PATH . 'oc-includes/osclass/installer/struct.sql'); $c_db = $conn->getOsclassDb(); $comm = new DBCommandClass($c_db); $comm->importSQL($sql); $error_num = $comm->getErrorLevel(); if ($error_num > 0) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot create the database structure. Error number: ' . $error_num, __FILE__ . "::" . __LINE__); } switch ($error_num) { case 1050: return array('error' => 'There are tables with the same name in the database. Change the table prefix or the database and try again.'); break; default: return array('error' => 'Cannot create the database structure. Error number: ' . $error_num . '.'); break; } } require_once LIB_PATH . 'osclass/locales.php'; require_once LIB_PATH . 'osclass/model/OSCLocale.php'; $localeManager = OSCLocale::newInstance(); $locales = osc_listLocales(); foreach ($locales as $locale) { $values = array('pk_c_code' => $locale['code'], 's_name' => $locale['name'], 's_short_name' => $locale['short_name'], 's_description' => $locale['description'], 's_version' => $locale['version'], 's_author_name' => $locale['author_name'], 's_author_url' => $locale['author_url'], 's_currency_format' => $locale['currency_format'], 's_date_format' => $locale['date_format'], 'b_enabled' => $locale['code'] == 'en_US' ? 1 : 0, 'b_enabled_bo' => 1); if (isset($locale['stop_words'])) { $values['s_stop_words'] = $locale['stop_words']; } $localeManager->insert($values); } $required_files = array('basic_data.sql', 'categories.sql', 'pages.sql'); $sql = ''; foreach ($required_files as $file) { if (!file_exists(ABS_PATH . 'oc-includes/osclass/installer/' . $file)) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('the file ' . $file . ' doesn\'t exist in data folder', __FILE__ . "::" . __LINE__); } return array('error' => 'the file ' . $file . ' doesn\'t exist in data folder'); } else { $sql .= file_get_contents(ABS_PATH . 'oc-includes/osclass/installer/' . $file); } } $comm->importSQL($sql); $error_num = $comm->getErrorLevel(); if ($error_num > 0) { if (reportToOsclass()) { LogOsclassInstaller::instance()->error('Cannot insert basic configuration. Error number: ' . $error_num, __FILE__ . "::" . __LINE__); } switch ($error_num) { case 1471: return array('error' => 'Cannot insert basic configuration. This user has no privileges to \'INSERT\' into the database.'); break; default: return array('error' => 'Cannot insert basic configuration. Error number: ' . $error_num . '.'); break; } } if (reportToOsclass()) { set_allow_report_osclass(true); } else { set_allow_report_osclass(false); } return false; }