27 function import($doc,
$tx);
87 $default_charset =
$config[
"default_charset"];
88 if (!$default_charset) $default_charset =
"iso-8859-1";
90 $xml =
"<?xml version=\"1.0\" encoding=\"{$default_charset}\"?>";
99 $xml .=
"\n</Fakoli>";
135 $xml = file_get_contents(
$process->get(
"xml_import_file_path"));
138 trace(
"Importing $components from $xml", 3);
139 $process->setProgress(
"Running",
"Starting import", 0);
147 $doc =
new DOMDocument();
148 if (!$doc->loadXML($xml))
154 $tx =
new DataTransaction();
195 trace(
"== Instantiating $class Records", 3);
203 $lists = $doc->getElementsByTagName(
$class .
"List");
204 if ($lists->length == 0)
return;
206 $nodes = $doc->getElementsByTagName(
$class);
213 $process->setProgress(
"Running", pluralize(
"Reading $count {$class}",
$count), 0);
220 foreach($nodes as $node)
223 $object->fromXML($node);
224 $objects[] = $object;
229 $process->setProgress(
"Running", pluralize(
"Reading $c of $count {$class}",
$count), intval((100*
$c)/
$count));
237 $o->joinTransaction(
$tx);
242 foreach($objects as $object)
244 $object->_disablePK =
true;
245 $object->joinTransaction(
$tx);
250 $process->setProgress(
"Running", pluralize(
"Imported $c of $count {$class}",
$count), intval((100*
$c)/
$count));
262 trace(
"== Instantiating $class Records", 3);
270 $lists = $doc->getElementsByTagName(
$class .
"List");
271 if ($lists->length == 0)
return;
273 $nodes = $doc->getElementsByTagName(
$class);
279 $process->setProgress(
"Running", pluralize(
"Reading $count {$class}",
$count), 0);
288 foreach($nodes as $node)
290 $object->fromXML($node);
291 $object->_disablePK =
true;
292 $object->joinTransaction(
$tx);
297 $process->setProgress(
"Running", pluralize(
"Imported $c of $count {$class}",
$count), intval((100*
$c)/
$count));
312 return toXML(
$class.
"List", $objects,
"");
337 return implode(
",",
$_POST[
"content_type"]);
348 if ($this->
mode ==
"Import")
350 $onsubmit =
" onsubmit=\"return confirm('WARNING! Importing site content WILL overwrite existing content in your database.\\nThis CANNOT be undone.\\nDo you wish to continue?');\"";
354 <form method=
"POST" action=
"<?echo $this->action?>" enctype=
"multipart/form-data"<?echo $onsubmit?>>
359 <input type=
"checkbox" value=
"<?echo $component?>" name=
"content_type[]"/>&
nbsp;<?echo
$handler[
'title'];?><br/>
365 if ($this->
mode ==
"Import")
368 <label
for=
"import_file">Import File </label><input type=
"file" name=
"import_file"/><br/><br/>
373 $file = codify(
$config[
"sitename"].
"_".date(
"Ymd")).
".xml";
375 <label
for=
"export_file">Export File Name </label><input type=
"text" size=
"50" name=
"export_file" value=
"<?echo $file?>"/><br/><br/>
379 <input type=
"submit" class=
"button" value=
"<?echo $this->mode?> Configuration"/>
403 $this->
class = $class;
412 $this->constraint =
"ORDER BY ".$obj->getPrimaryKey();
430 function import($doc,
$tx)
436 $process->setProgress(
"Completed",
"Import successful", 100);
471 throw new FakoliException(
"No group tag specified for compound serialization handler");
475 for($i = 1; $i < func_num_args(); ++$i)
477 $arg = func_get_arg($i);
480 $this->classes[] = $arg;
484 $this->classes[] = array($arg,
"");
505 $xml =
"\n<{$this->groupTag}>";
506 foreach($this->classes as
$class)
511 $xml .=
"\n</{$this->groupTag}>";
520 function import($doc,
$tx)
524 foreach($this->classes as
$class)
531 $process->setProgress(
"Completed",
"Import successful", 100);
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
Provides serialization for a number of DataItem classes, grouped under a common tag in the serialized...
addTarget($class, $constraint="")
Add a target DataItem with optional constraint.
retrieve($doc, $class)
Retrieves serialized objects from the provided XML document, but does not store them in the database.
__construct($groupTag)
Creates the CompoundSerializationHandler.
export()
Exports the target DataItems to XML.
FakoliException is the base exception class for all Fakoli errors.
static using()
Import the datamodels, views and manifest for the specified component(s).
SerializationManager handles import/export of DataItems via an XML file.
export($components)
Exports data for the specified components.
exportAll()
Export data for all registered components.
__construct()
Creates a SerializationManager, building the serialization map from the registered components via the...
static serialize($class, $constraint="")
Serializes the specified DataItems to XML.
importAll($xml)
Import data for all registered components.
registerHandler($component, $title, $handler)
Registers a serialization handler for a component.
static unserialize($class, $doc, $tx, $save=true)
Instantiates DataItems from the supplied XML document and stores them in the database.
static store($class, $doc, $tx)
Provides a simple implementation of a SerializationHandler that can serialize a single DataItem class...
export()
Exports the DataItems to XML.
__construct($class, $constraint="")
Creates a new SimpleSerializationHandler.
if(!checkRole("admin")) $c
Defines the basic interface contract for a SerializationHandler.
export()
Export the serialized objects.