📄 installer.php
字号:
{
executeSql('sql/' . $this->getConfigKey('DB_TYPE') . '_zencart_40.sql', $this->getConfigKey('DB_DATABASE'), $this->getConfigKey('DB_PREFIX'));
}
// end of modification
//update the cache folder setting:
$this->dbAfterLoadActions();
if (file_exists('includes/local/developers_' . $this->getConfigKey('DB_TYPE') . '.sql')) {
executeSql('includes/local/developers_' . $this->getConfigKey('DB_TYPE') . '.sql', $this->getConfigKey('DB_DATABASE'), $this->getConfigKey('DB_PREFIX'));
}
// process any plugin SQL scripts
$this->dbHandleSQLPlugins();
// Close the database connection
$this->db->Close();
}
/**
* Support for SQL Plugins in installer
*/
function dbHandleSQLPlugins() {
$sqlpluginsdir = 'sql/plugins/';
if ($dir = @dir($sqlpluginsdir)) {
while ($file = $dir->read()) {
if (!is_dir($sqlpluginsdir . $file)) {
if (ZC_UPG_DEBUG3) echo '<br />checking file: ' . $sqlpluginsdir . $file;
if (preg_match('/^' . $this->getConfigKey('DB_TYPE') . '.*\.sql$/', $file) > 0) {
$directory_array[] = $file;
}
}
}
if (sizeof($directory_array)) {
sort($directory_array);
}
$dir->close();
}
for ($i = 0, $n = sizeof($directory_array); $i < $n; $i++) {
$file = $directory_array[$i];
if (file_exists($sqlpluginsdir . $file)) {
echo '<br />Processing Plugin: ' . $sqlpluginsdir . $file . '<br />';
executeSql($sqlpluginsdir . $file, $this->getConfigKey('DB_DATABASE'), $this->getConfigKey('DB_PREFIX'));
}
}
}
function dbAfterLoadActions() {
$this->dbActivate(); // can likely remove this line for v1.4
//update the cache folder setting:
$sql = "update ". $this->getConfigKey('DB_PREFIX') ."configuration set configuration_value='". $this->getConfigKey('DIR_FS_SQL_CACHE') ."' where configuration_key = 'SESSION_WRITE_DIRECTORY'";
$this->db->Execute($sql);
//update the logging_folder setting:
$sql = "update ". $this->getConfigKey('DB_PREFIX') ."configuration set configuration_value='". $this->getConfigKey('DIR_FS_SQL_CACHE') ."/page_parse_time.log' where configuration_key = 'STORE_PAGE_PARSE_TIME_LOG'";
$this->db->Execute($sql);
//update the phpbb setting:
$sql = "update ". $this->getConfigKey('DB_PREFIX') ."configuration set configuration_value='". $this->getConfigKey('PHPBB_ENABLE') ."' where configuration_key = 'PHPBB_LINKS_ENABLED'";
$this->db->Execute($sql);
}
function dbDemoDataInstall() {
$this->dbActivate(); // can likely remove this line for v1.4
global $db;
$db = $this->db;
executeSql('demo/' . DB_TYPE . '_demo.sql', DB_DATABASE, DB_PREFIX);
}
function validateStoreSetup($data) {
$this->configInfo['store_name'] = $this->isEmpty(zen_db_prepare_input($data['store_name']), ERROR_TEXT_STORE_NAME_ISEMPTY, ERROR_CODE_STORE_NAME_ISEMPTY);
$this->configInfo['store_owner'] = $this->isEmpty(zen_db_prepare_input($data['store_owner']), ERROR_TEXT_STORE_OWNER_ISEMPTY, ERROR_CODE_STORE_OWNER_ISEMPTY);
$this->configInfo['store_owner_email'] = $this->isEmpty(zen_db_prepare_input($data['store_owner_email']), ERROR_TEXT_STORE_OWNER_EMAIL_ISEMPTY, ERROR_CODE_STORE_OWNER_EMAIL_ISEMPTY);
$this->configInfo['store_owner_email'] = $this->isEmpty(zen_db_prepare_input($data['store_owner_email']), ERROR_TEXT_STORE_OWNER_EMAIL_NOTEMAIL, ERROR_CODE_STORE_OWNER_EMAIL_NOTEMAIL);
$this->configInfo['store_address'] = $this->isEmpty(zen_db_prepare_input($data['store_address']), ERROR_TEXT_STORE_ADDRESS_ISEMPTY, ERROR_CODE_STORE_ADDRESS_ISEMPTY);
$this->configInfo['store_country'] = zen_db_prepare_input($data['store_country']);
$this->configInfo['store_zone'] = zen_db_prepare_input($data['store_zone']);
$this->configInfo['store_default_language'] = zen_db_prepare_input($data['store_default_language']);
$this->configInfo['store_default_currency'] = zen_db_prepare_input($data['store_default_currency']);
}
function dbStoreSetup() {
$this->dbActivate(); // can likely remove this line for v1.4
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_name']) . "' where configuration_key = 'STORE_NAME'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_owner']) . "' where configuration_key = 'STORE_OWNER'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_owner_email']) . "' where configuration_key in
('STORE_OWNER_EMAIL_ADDRESS', 'EMAIL_FROM', 'SEND_EXTRA_ORDER_EMAILS_TO', 'SEND_EXTRA_CREATE_ACCOUNT_EMAILS_TO', 'SEND_EXTRA_LOW_STOCK_EMAILS_TO', 'SEND_EXTRA_GV_CUSTOMER_EMAILS_TO', 'SEND_EXTRA_GV_ADMIN_EMAILS_TO', 'SEND_EXTRA_DISCOUNT_COUPON_ADMIN_EMAILS_TO', 'SEND_EXTRA_ORDERS_STATUS_ADMIN_EMAILS_TO', 'SEND_EXTRA_TELL_A_FRIEND_EMAILS_TO', 'SEND_EXTRA_REVIEW_NOTIFICATION_EMAILS_TO', 'MODULE_PAYMENT_CC_EMAIL')";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_country']) . "' where configuration_key in ('STORE_COUNTRY', 'SHIPPING_ORIGIN_COUNTRY')";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_zone']) . "' where configuration_key = 'STORE_ZONE'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_address']) . "' where configuration_key = 'STORE_NAME_ADDRESS'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_default_language']) . "' where configuration_key = 'DEFAULT_LANGUAGE'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '" . $this->db->prepare_input($this->configInfo['store_default_currency']) . "' where configuration_key = 'DEFAULT_CURRENCY'";
$this->db->Execute($sql);
$sql = "update " . DB_PREFIX . "currencies set value = 1 where code = '" . $this->db->prepare_input($this->configInfo['store_default_currency']) . "'";
$this->db->Execute($sql);
}
function validateAdminSetup($data) {
$this->dbActivate();
if (!isset($this->configInfo['check_for_updates'])) $this->configInfo['check_for_updates'] = (isset($data['check_for_updates']) && $data['check_for_updates']== '1' ) ? 1 : 0;
$this->configInfo['admin_username'] = zen_db_prepare_input($data['admin_username']);
$this->configInfo['admin_email'] = zen_db_prepare_input($data['admin_email']);
$this->configInfo['admin_pass'] = zen_db_prepare_input($data['admin_pass']);
$this->isEmpty($this->configInfo['admin_username'], ERROR_TEXT_ADMIN_USERNAME_ISEMPTY, ERROR_CODE_ADMIN_USERNAME_ISEMPTY);
$this->isEmpty($this->configInfo['admin_email'], ERROR_TEXT_ADMIN_EMAIL_ISEMPTY, ERROR_CODE_ADMIN_EMAIL_ISEMPTY);
$this->isEmail($this->configInfo['admin_email'], ERROR_TEXT_ADMIN_EMAIL_NOTEMAIL, ERROR_CODE_ADMIN_EMAIL_NOTEMAIL);
$this->isEmpty($this->configInfo['admin_pass'], ERROR_TEXT_ADMIN_PASS_ISEMPTY, ERROR_CODE_ADMIN_PASS_ISEMPTY);
}
function dbAdminSetup() {
$this->dbActivate(); // can likely remove this line for v1.4
$sql = "update " . DB_PREFIX . "admin set admin_name = '" . $this->configInfo['admin_username'] . "', admin_email = '" . $this->configInfo['admin_email'] . "', admin_pass = '" . zen_encrypt_password($this->configInfo['admin_pass']) . "' where admin_id = 1";
$this->db->Execute($sql) or die("Error in query: $sql".$this->db->ErrorMsg());
// enable/disable automatic version-checking
$sql = "update " . DB_PREFIX . "configuration set configuration_value = '".($this->configInfo['check_for_updates'] ? 'true' : 'false' ) ."' where configuration_key = 'SHOW_VERSION_UPDATE_IN_HEADER'";
$this->db->Execute($sql) or die("Error in query: $sql".$this->db->ErrorMsg());
$this->db->Close();
}
function verifyAdminCredentials($admin_name, $admin_pass) {
// security check
if ($admin_name == '' || $admin_name == 'demo' || $admin_pass == '') {
$this->setError(ERROR_TEXT_ADMIN_PWD_REQUIRED, ERROR_CODE_ADMIN_PWD_REQUIRED, true);
} else {
$admin_name = zen_db_prepare_input($admin_name);
$admin_pass = zen_db_prepare_input($admin_pass);
$sql = "select admin_id, admin_name, admin_pass from " . DB_PREFIX . "admin where admin_name = '" . $admin_name . "'";
//open database connection to run queries against it
$this->dbActivate();
$result = $this->db->Execute($sql);
if ($admin_name != $result->fields['admin_name']) {
$this->setError(ERROR_TEXT_ADMIN_PWD_REQUIRED, ERROR_CODE_ADMIN_PWD_REQUIRED, true);
}
if (!zen_validate_password($admin_pass, $result->fields['admin_pass'])) {
$this->setError(ERROR_TEXT_ADMIN_PWD_REQUIRED, ERROR_CODE_ADMIN_PWD_REQUIRED, true);
}
$this->db->Close();
}
}
function doPrefixRename($newprefix, $db_prefix_rename_from) {
$this->test_admin_configure(ERROR_TEXT_ADMIN_CONFIGURE,ERROR_CODE_ADMIN_CONFIGURE, true);
$this->test_store_configure(ERROR_TEXT_STORE_CONFIGURE,ERROR_CODE_STORE_CONFIGURE);
$this->test_admin_configure_write(ERROR_TEXT_ADMIN_CONFIGURE_WRITE,ERROR_CODE_ADMIN_CONFIGURE_WRITE);
$this->test_store_configure_write(ERROR_TEXT_STORE_CONFIGURE_WRITE,ERROR_CODE_STORE_CONFIGURE_WRITE);
$this->functionExists(DB_TYPE, ERROR_TEXT_DB_NOTSUPPORTED, ERROR_CODE_DB_NOTSUPPORTED);
$this->dbConnect(DB_TYPE, DB_SERVER, DB_DATABASE, DB_SERVER_USERNAME, DB_SERVER_PASSWORD, ERROR_TEXT_DB_CONNECTION_FAILED, ERROR_CODE_DB_CONNECTION_FAILED,ERROR_TEXT_DB_NOTEXIST, ERROR_CODE_DB_NOTEXIST);
// security check
if ((!isset($_POST['adminid']) && !isset($_POST['adminpwd'])) || $_POST['adminid']=='' || $_POST['adminid']=='demo') {
$this->setError(ERROR_TEXT_ADMIN_PWD_REQUIRED, ERROR_CODE_ADMIN_PWD_REQUIRED, true);
} else {
$this->verifyAdminCredentials($_POST['adminid'], $_POST['adminpwd']);
}
// end admin verification
if (ZC_UPG_DEBUG2==true) echo 'Processing prefix updates...<br />';
if ($this->error == false && $nothing_to_process==false) {
$this->dbActivate();
$tables = $this->db->Execute("SHOW TABLES"); // get a list of tables to compare against
$tables_list = array();
while (!$tables->EOF) {
$tables_list[] = $tables->fields['Tables_in_' . DB_DATABASE];
$tables->MoveNext();
} //end while
//read the "database_tables.php" files, and loop through the table names
foreach($database_tablenames_array as $filename) {
if (!file_exists($filename)) continue;
$lines = file($filename);
foreach ($lines as $line) {
$line = trim($line);
if (substr($line,0,1) != '<' && substr($line,0,2) != '?'.'>' && substr($line,0,2) != '//' && $line != '') {
// echo 'line='.$line.'<br>';
$def_string=array();
$def_string=explode("'",$line);
//define('TABLE_CONSTANT',DB_PREFIX.'tablename');
//[1]=TABLE_CONSTANT
//[2]=,DB_PREFIX.
//[3]=tablename
//[4]=);
//[5]=
//echo '[1]->'.$def_string[1].'<br>';
//echo '[2]->'.$def_string[2].'<br>';
//echo '[3]->'.$def_string[3].'<br>';
//echo '[4]->'.$def_string[4].'<br>';
//echo '[5]->'.$def_string[5].'<br>';
if (strtoupper($def_string[1]) != 'DB_PREFIX' // the define of DB_PREFIX is not a tablename
&& str_replace('PHPBB','',strtoupper($def_string[1]) ) == strtoupper($def_string[1]) // this is not a phpbb table
&& str_replace(' ','',$def_string[2]) == ',DB_PREFIX.') { // this is a Zen Cart-related table (vs phpbb)
$tablename_read = $def_string[3];
foreach($tables_list as $existing_table) {
if ($tablename_read == str_replace($db_prefix_rename_from,'',$existing_table)) {
//echo $tablename_read.'<br>';
$sql_command = 'alter table '. $db_prefix_rename_from . $tablename_read . ' rename ' . $newprefix.$tablename_read;
//echo $sql_command .'<br>';
$this->db->Execute($sql_command);
$tables_updated++;
$tablename_read = '';
$sql_command = '';
}//endif $tablename_read == existing
}//end foreach $tables_list
} //endif is "DEFINE"?
} // endif substring not < or ? or // etc
} //end foreach $lines
}//end foreach $database_tablenames array
$this->db->Close();
} // end if zc_install-error
//echo $tables_updated;
if ($tables_updated <50) $this->setError(ERROR_TEXT_TABLE_RENAME_INCOMPLETE, ERROR_CODE_TABLE_RENAME_INCOMPLETE, false);
if ($tables_updated >50) {
//update the configure.php files with the new prefix.
$configure_files_updated = 0;
foreach($configure_files_array as $filename) {
$lines = file($filename);
$full_file = '';
foreach ($lines as $line) {
$def_string=explode("'",$line);
if (strtoupper($def_string[1]) == 'DB_PREFIX') {
// check to see if prefix found matches what we've been processing... for safety to be sure we have the right line
$old_prefix_from_file = $def_string[3];
if ($old_prefix_from_file == DB_PREFIX || $old_prefix_from_file == $db_prefix_rename_from) {
$line = ' define(\'DB_PREFIX\', \'' . $newprefix. '\');' . "\n";
$configure_files_updated++;
}
} // endif DEFINE DB_PREFIX found;
$full_file .= $line;
} //end foreach $lines
$fp = fopen($filename, 'w');
fputs($fp, $full_file);
fclose($fp);
@chmod($filename, 0644);
} //end foreach array to update configure.php files
if ($configure_files_updated <2) $this->setError(ERROR_TEXT_TABLE_RENAME_CONFIGUREPHP_FAILED, ERROR_CODE_TABLE_RENAME_CONFIGUREPHP_FAILED, false);
} //endif $tables_updated count sufficient
}
} // end class
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -