Skip to content

Commit

Permalink
加入SAE和BAE支持
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Oct 17, 2013
1 parent 6922286 commit ee60c7e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
24 changes: 18 additions & 6 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@

ob_start();

session_start();

//判断是否已经安装
if (!isset($_GET['finish']) && file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php') && !file_exists(sys_get_temp_dir() . '/install-typecho')) {
if (!isset($_GET['finish']) && file_exists(__TYPECHO_ROOT_DIR__ . '/config.inc.php') && empty($_SESSION['typecho'])) {
exit;
}

Expand Down Expand Up @@ -332,7 +334,7 @@ function _u()
$installDb->query($installDb->insert('table.users')->rows(array('name' => $config['userName'], 'password' => Typecho_Common::hash($password), 'mail' => $config['userMail'],
'url' => 'http://www.typecho.org', 'screenName' => $config['userName'], 'group' => 'administrator', 'created' => Typecho_Date::gmtTime())));

unlink(sys_get_temp_dir() . '/install-typecho');
unset($_SESSION['typecho']);
Typecho_Cookie::delete('__typecho_config');
header('Location: ./install.php?finish&user=' . urlencode($config['userName'])
. '&password=' . $password);
Expand Down Expand Up @@ -366,7 +368,7 @@ function _u()
//使用原有数据
//但是要更新用户网站
$installDb->query($installDb->update('table.options')->rows(array('value' => $config['siteUrl']))->where('name = ?', 'siteUrl'));
unlink(sys_get_temp_dir() . '/install-typecho');
unset($_SESSION['typecho']);
Typecho_Cookie::delete('__typecho_config');
header('Location: ./install.php?finish&use_old');
exit;
Expand Down Expand Up @@ -429,7 +431,17 @@ function _u()
$dbConfig[strtolower (substr($key, 2))] = $val;
}

if ($success && !_r('created')) {
// 在特殊服务器上的特殊安装过程处理
if (_r('config')) {
$replace = array_keys($dbConfig);
foreach ($replace as &$key) {
$key = '{' . $key . '}';
}

$config = str_replace($replace, array_values($dbConfig), _r('config'));
}

if (!isset($config) && $success && !_r('created')) {
$installDb = new Typecho_Db ($adapter, _r('dbPrefix'));
$installDb->addServer($dbConfig, Typecho_Db::READ | Typecho_Db::WRITE);

Expand Down Expand Up @@ -467,14 +479,14 @@ function _u()
$lines[] = "
/** 定义数据库参数 */
\$db = new Typecho_Db('{$adapter}', '" . _r('dbPrefix') . "');
\$db->addServer(" . var_export($dbConfig, true) . ", Typecho_Db::READ | Typecho_Db::WRITE);
\$db->addServer(" . (!isset($config) ? var_export($dbConfig, true) : $config) . ", Typecho_Db::READ | Typecho_Db::WRITE);
Typecho_Db::set(\$db);
";
$contents = implode('', $lines);
@file_put_contents('./config.inc.php', $contents);

// 创建一个用于标识的临时文件
file_put_contents(sys_get_temp_dir() . '/install-typecho', '');
$_SESSION['typecho'] = 1;

if (!file_exists('./config.inc.php')) {
?>
Expand Down
59 changes: 34 additions & 25 deletions install/Mysql.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
<?php if(!defined('__TYPECHO_ROOT_DIR__')) exit; ?>

<?php if (defined('SAE_ACCESSKEY') && defined('SAE_SECRETKEY')): ?>
<?php //这里是专门为Sina App Engine做的判断 ?>
<li>
<label class="typecho-label"><?php _e('数据库地址'); ?></label>
<input type="text" class="text" name="dbHost" value="<?php _v('dbHost', SAE_MYSQL_HOST_M); ?>" />
<p class="description"><?php _e('这里Sina App Engine自动分配的数据库地址,请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label"><?php _e('数据库端口'); ?></label>
<input type="text" class="text" name="dbPort" value="<?php _v('dbPort', SAE_MYSQL_PORT); ?>" />
<p class="description"><?php _e('如果您不知道此选项的意义, 请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label"><?php _e('数据库用户名'); ?></label>
<input type="text" class="text" name="dbUser" value="<?php _v('dbUser', SAE_MYSQL_USER); ?>" />
<p class="description"><?php _e('这里Sina App Engine自动分配的用户名,请保留默认设置'); ?></p>
</li>
<li>
<label class="typecho-label"><?php _e('数据库密码'); ?></label>
<input type="password" class="text" name="dbPassword" value="<?php _v('dbPassword', SAE_MYSQL_PASS); ?>" />
</li>
<?php if (defined('SAE_MYSQL_DB')): ?>
<!-- SAE -->
<h3><?php _e('系统将为你自动匹配 %s 环境的安装选项', 'SAE'); ?></h3>
<input type="hidden" name="config" value="array (
'host' => SAE_MYSQL_HOST_M,
'user' => SAE_MYSQL_USER,
'password' => SAE_MYSQL_PASS,
'charset' => '<?php _e('utf8'); ?>',
'port' => SAE_MYSQL_PORT,
'database' => SAE_MYSQL_DB
)" />
<input type="hidden" name="dbHost" value="<?php echo SAE_MYSQL_HOST_M; ?>" />
<input type="hidden" name="dbPort" value="<?php echo SAE_MYSQL_PORT; ?>" />
<input type="hidden" name="dbUser" value="<?php echo SAE_MYSQL_USER; ?>" />
<input type="hidden" name="dbPassword" value="<?php echo SAE_MYSQL_PASS; ?>" />
<input type="hidden" name="dbDatabase" value="<?php echo SAE_MYSQL_DB; ?>" />
<?php elseif (!!getenv('HTTP_BAE_ENV_ADDR_SQL_IP')): ?>
<!-- BAE -->
<h3><?php _e('系统将为你自动匹配 %s 环境的安装选项', 'BAE'); ?></h3>
<li>
<label class="typecho-label"><?php _e('数据库名'); ?></label>
<input type="text" class="text" name="dbDatabase" value="<?php _v('dbDatabase', SAE_MYSQL_DB); ?>" />
<input type="text" class="text" name="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
</li>
<?php //结束 ?>
<input type="hidden" name="config" value="array (
'host' => getenv('HTTP_BAE_ENV_ADDR_SQL_IP'),
'user' => getenv('HTTP_BAE_ENV_AK'),
'password' => getenv('HTTP_BAE_ENV_SK'),
'charset' => '<?php _e('utf8'); ?>',
'port' => getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'),
'database' => '{database}'
)" />
<input type="hidden" name="dbHost" value="<?php echo getenv('HTTP_BAE_ENV_ADDR_SQL_IP'); ?>" />
<input type="hidden" name="dbPort" value="<?php echo getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'); ?>" />
<input type="hidden" name="dbUser" value="<?php echo getenv('HTTP_BAE_ENV_AK'); ?>" />
<input type="hidden" name="dbPassword" value="<?php echo getenv('HTTP_BAE_ENV_SK'); ?>" />
<?php else: ?>
<li>
<label class="typecho-label"><?php _e('数据库地址'); ?></label>
Expand All @@ -52,7 +61,7 @@
<input type="text" class="text" name="dbDatabase" value="<?php _v('dbDatabase', 'typecho'); ?>" />
<p class="description"><?php _e('请您指定数据库名称'); ?></p>
</li>
<?php endif; ?>


<?php endif; ?>
<input type="hidden" name="dbCharset" value="<?php _e('utf8'); ?>" />

0 comments on commit ee60c7e

Please sign in to comment.