* Refactory the importDemoData.

This commit is contained in:
chencongzhi520@gmail.com
2012-07-03 00:51:38 +00:00
parent fdec83821d
commit b357ac39ac
6 changed files with 46 additions and 48 deletions
+4
View File
@@ -123,6 +123,10 @@ class install extends control
{
$this->install->grantPriv();
if(dao::isError()) die(js::error(dao::getError()));
if($this->post->importDemoData) $this->install->importDemoData();
if(dao::isError()) echo js::alert($this->lang->install->errorImportDemoData);
$this->loadModel('setting')->updateVersion($this->config->version);
$this->setting->setSN();
die(js::locate(inlink('step5'), 'parent'));
+31 -40
View File
@@ -227,16 +227,6 @@ class installModel extends model
return $return;
}
if($this->post->importDemoData)
{
if(!$this->importDemoData())
{
$return->result = 'fail';
$return->error = $this->lang->install->errorImportDemoData;
return $return;
}
}
return $return;
}
@@ -350,36 +340,6 @@ class installModel extends model
return true;
}
/**
* Import demo data.
*
* @access public
* @return void
*/
public function importDemoData()
{
$demoDataFile = $this->app->getAppRoot() . 'db' . $this->app->getPathFix() . 'demo.sql';
$insertTables = explode(";\n", file_get_contents($demoDataFile));
foreach($insertTables as $table)
{
$table = trim($table);
if(empty($table)) continue;
$table = str_replace('`zt_', $this->config->db->name . '.`zt_', $table);
$table = str_replace('zt_', $this->config->db->prefix, $table);
if(!$this->dbh->query($table)) return false;
}
$config->company = '1';
$config->module = 'common';
$config->owner = 'system';
$config->section = 'global';
$config->key = 'showDemoUsers';
$config->value = '1';
$this->dao->replace(TABLE_CONFIG)->data($config, false)->exec(false);
return true;
}
/**
* Create a comapny, set admin.
*
@@ -411,4 +371,35 @@ class installModel extends model
$this->dao->update(TABLE_GROUPPRIV)->set('company')->eq($companyID)->exec($autoCompany = false);
}
}
/**
* Import demo data.
*
* @access public
* @return void
*/
public function importDemoData()
{
$demoDataFile = $this->app->getAppRoot() . 'db' . $this->app->getPathFix() . 'demo.sql';
$insertTables = explode(";\n", file_get_contents($demoDataFile));
foreach($insertTables as $table)
{
$table = trim($table);
if(empty($table)) continue;
$table = str_replace('`zt_', $this->config->db->name . '.`zt_', $table);
$table = str_replace('zt_', $this->config->db->prefix, $table);
if(!$this->dbh->query($table)) return false;
}
$config->company = '1';
$config->module = 'common';
$config->owner = 'system';
$config->section = 'global';
$config->key = 'showDemoUsers';
$config->value = '1';
$this->dao->replace(TABLE_CONFIG)->data($config, false)->exec(false);
return true;
}
}
-1
View File
@@ -56,7 +56,6 @@
<?php
echo html::input('dbPrefix', 'zt_', 'class=text-3');
echo html::checkBox('clearDB', $lang->install->clearDB);
echo html::checkBox('importDemoData', $lang->install->importDemoData);
?>
</td>
</tr>
+1 -1
View File
@@ -41,7 +41,7 @@
</tr>
<tr>
<th class='rowhead'><?php echo $lang->install->password;?></th>
<td><?php echo html::input('password');?></td>
<td><?php echo html::input('password') . html::checkBox('importDemoData', $lang->install->importDemoData);?></td>
</tr>
<tr class='a-center'>
<td colspan='2'><?php echo html::submitButton();?></td>
+4
View File
@@ -19,3 +19,7 @@ table, tr, td, th, input{ border:none;}
#updater {width:500px; height:30px; border:none; overflow:hidden;}
.hidden{display:none} /* Add it to avoid the white flash when load css later for the updater. */
#demoUsers {margin:25px 0px -15px 0px;}
#demoUsers span{color:white}
#demoUsers a{color:yellow}
+6 -6
View File
@@ -40,12 +40,12 @@ include '../../common/view/colorbox.html.php';
<?php if($showDemoUsers):?>
<div id='demoUsers'>
<?php
echo $lang->user->loginWithDemoUser;
if(isset($demoUsers['productManager'])) echo html::a($this->inLink('login', "account=productManager&password=123456"), $demoUsers['productManager'], 'hiddenwin', "class='yellow'");
if(isset($demoUsers['projectManager'])) echo html::a($this->inLink('login', "account=projectManager&password=123456"), $demoUsers['projectManager'], 'hiddenwin', "class='yellow'");
if(isset($demoUsers['testManager'])) echo html::a($this->inLink('login', "account=testManager&password=123456"), $demoUsers['testManager'], 'hiddenwin', "class='yellow'");
if(isset($demoUsers['dev1'])) echo html::a($this->inLink('login', "account=dev1&password=123456"), $demoUsers['dev1'], 'hiddenwin', "class='yellow'");
if(isset($demoUsers['tester1'])) echo html::a($this->inLink('login', "account=tester1&password=123456"), $demoUsers['tester1'], 'hiddenwin', "class='yellow'");
echo "<span>" . $lang->user->loginWithDemoUser . "</span>";
if(isset($demoUsers['productManager'])) echo html::a($this->inLink('login', "account=productManager&password=123456"), $demoUsers['productManager'], 'hiddenwin');
if(isset($demoUsers['projectManager'])) echo html::a($this->inLink('login', "account=projectManager&password=123456"), $demoUsers['projectManager'], 'hiddenwin');
if(isset($demoUsers['testManager'])) echo html::a($this->inLink('login', "account=testManager&password=123456"), $demoUsers['testManager'], 'hiddenwin');
if(isset($demoUsers['dev1'])) echo html::a($this->inLink('login', "account=dev1&password=123456"), $demoUsers['dev1'], 'hiddenwin');
if(isset($demoUsers['tester1'])) echo html::a($this->inLink('login', "account=tester1&password=123456"), $demoUsers['tester1'], 'hiddenwin');
?>
</div>
<?php endif;?>