* Import demo data when install.
* Code for task#808.
This commit is contained in:
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user