36 if ( !is_a($this,
'Dataface_ConfigTool') ){
37 throw new Exception(
'ConfigWriter methods are only to be used via the Dataface_ConfigTool class.', E_USER_ERROR);
40 $config = file_get_contents(DATAFACE_PATH.
'/install/dbconfig.sql');
41 foreach ( explode(
';',$config) as $query){
42 if (!trim($query))
continue;
43 $res = mysql_query($query,
$app->db());
45 throw new Exception(
"Could not set up configuration database: ".mysql_error(
$app->db()), E_USER_ERROR);
52 if ( !is_a($this,
'Dataface_ConfigTool') ){
53 throw new Exception(
'ConfigWriter methods are only to be used via the Dataface_ConfigTool class.', E_USER_ERROR);
56 $this->loadAllConfig();
59 if ( $storage === null ) $storage =
$app->_conf[
'config_storage'];
61 switch (strtolower($storage)){
67 return $this->writeConfigToINI();
73 import(
'Dataface/Table.php');
74 import(
'Dataface/Record.php');
75 import(
'Dataface/IO.php');
76 if ( !is_a($this,
'Dataface_ConfigTool') ){
77 throw new Exception(
'ConfigWriter methods are only to be used via the Dataface_ConfigTool class.', E_USER_ERROR);
79 $this->loadAllConfig();
83 foreach ( $this->configTypes as $type ){
84 $res = mysql_query(
"CREATE TABLE `__".addslashes($type).
"__".$timestamp.
"` SELECT * FROM `__".addslashes($type).
"__`",
$app->db());
86 throw new Exception(
"Failed to make backup of table '__".$type.
"__'.". mysql_error(
$app->db()), E_USER_ERROR);
90 $res = mysql_query(
"CREATE TABLE `__properties__".$timestamp.
"` SELECT * FROM `__properties__`",
$app->db());
92 throw new Exception(
"Failed to make backup of table '__properties__'.",
$app->db());
97 foreach ( $this->configTypes as $type ){
99 $res = mysql_query(
"DELETE FROM `__".addslashes($type).
"__`",
$app->db());
101 throw new Exception(
"Failed to delete all records from table '__".$type.
"__'",
$app->db());
105 foreach ( $this->config[$type] as
$tablename=>$tableConfig ){
106 foreach ( $tableConfig as $sectionname=>$section){
109 $record->useMetaData =
false;
112 foreach ( array_keys($tableObj->fields()) as
$fieldname ){
113 $record->setValue($fieldname, @$section[$fieldname]);
114 unset($section[$fieldname]);
116 $record->setValue(
'name',$sectionname);
121 echo nl2br(
"\nWriting section: $sectionname : ");
122 print_r($record->strvals());
126 $res = $io->write($record);
128 throw new Exception($res->toString(), E_USER_ERROR);
130 throw new Exception(
"Failure to write to database for unknown reason.", E_USER_ERROR);
134 foreach ( $section as $propertyName=>$propertyValue ){
138 (`parent_id`,`parent_type`,`property_name`,`property_value`)
140 ('".$record->val($type.
'_id').
"',
141 '".addslashes($type).
"',
142 '".addslashes($propertyName).
"',
143 '".addslashes($propertyValue).
"')",
$app->db());
145 throw new Exception(
"Failed to add property '$propertyName' to table '__properties__' with value '$propertyValue'".mysql_error(
$app->db()), E_USER_ERROR);