src = WBClass::create('WBConfig_Loader_File');
$this->des = WBClass::create('WBConfig_Loader_ConfigTable');
}
public function prepareRoot()
{
$this->des->prepareRoot();
}
public function copy($file)
{
$data = '';
$expire = array();
if (!$this->src->load($file, $data, $expire, true)) {
echo "failed to load $file
";
return false;
}
echo "copy $file
\n";
$this->des->save($file, $data);
return true;
}
public function copyPages()
{
$this->copy('site');
$this->create('site/page');
$this->copy('site/content');
$this->copyDir('site/page');
}
private function copyDir($dir)
{
$base = WBParam::get('wb/dir/base');
if ($dir[0] != '/') {
$base .= '/etc-default/';
}
echo "dir $dir
";
$di = new DirectoryIterator($base . $dir);
foreach ($di as $i) {
if ($i->isDot()) {
continue;
}
$name = $i->getFilename();
if ($name[0] == '.') {
continue;
}
// recursion
if ($i->isDir()) {
$this->create($dir . '/'. $name);
$this->copyDir($dir . '/' . $name);
}
$name = explode('.', $name);
$ext = array_pop($name);
if ($ext != 'xml') {
continue;
}
$name = implode('.', $name);
$this->copy($dir . '/' . $name);
}
}
private function create($file)
{
try{
$data = '';
$expore = array();
$this->des->load($file, $data, $expire);
} catch (WBException $e) {
echo "create $file
\n";
$this->des->save($file, "\n\n");
}
}
}
$cc = new ConfigCloner();
if (isset($_GET['root'])) {
$cc->prepareRoot();
}
$cc->copyPages();
?>