* Import demo data when install.

* Code for task#808.
This commit is contained in:
chencongzhi520@gmail.com
2012-06-07 01:51:05 +00:00
parent ebd55b86b9
commit 55b02649cb
9 changed files with 421 additions and 32 deletions
+39
View File
@@ -226,6 +226,17 @@ class installModel extends model
$return->error = $this->lang->install->errorCreateTable;
return $return;
}
if($this->post->importDemoData)
{
if(!$this->importDemoData())
{
$return->result = 'fail';
$return->error = $this->lang->install->errorImportDemoData;
return $return;
}
}
return $return;
}
@@ -339,6 +350,34 @@ 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->owner = 'system';
$config->section = 'global';
$config->key = 'showDemoUsers';
$config->value = '1';
$this->dao->insert(TABLE_CONFIG)->data($config)->exec();
return true;
}
/**
* Create a comapny, set admin.
*