19 require_once(BASE.
"wcmf/application/controller/class.BatchController.php");
20 require_once(BASE.
"wcmf/lib/persistence/class.PersistenceFacade.php");
21 require_once(BASE.
"wcmf/lib/model/class.PersistentIterator.php");
22 require_once(BASE.
"wcmf/lib/util/class.InifileParser.php");
23 require_once(BASE.
"wcmf/lib/util/class.FileUtil.php");
72 parent::initialize($request, $response);
75 if ($request->getAction() !=
'continue')
79 $docFile = $this->_request->hasValue(
'docfile') ? $this->_request->getValue(
'docfile') :
$this->_DOCFILE;
80 $docType = $this->_request->hasValue(
'doctype') ? $this->_request->getValue(
'doctype') :
$this->_DOCTYPE;
81 $dtd = $this->_request->hasValue(
'dtd') ? $this->_request->getValue(
'dtd') :
$this->_DTD;
82 $docRootElement = $this->_request->hasValue(
'docrootelement') ? $this->_request->getValue(
'docrootelement') :
$this->_DOCROOTELEMENT;
83 $docLinebreak = $this->_request->hasValue(
'doclinebreak') ? $this->_request->getValue(
'doclinebreak') :
$this->_DOCLINEBREAK;
84 $docIndent = $this->_request->hasValue(
'docindent') ? $this->_request->getValue(
'docindent') :
$this->_DOCINDENT;
85 $nodesPerCall = $this->_request->hasValue(
'nodes_per_call') ? $this->_request->getValue(
'nodes_per_call') :
$this->_NODES_PER_CALL;
87 $documentInfo = array(
'docFile' => $docFile,
'docType' => $docType,
'dtd' => $dtd,
'docRootElement' => $docRootElement,
88 'docLinebreak' => $docLinebreak,
'docIndent' => $docIndent,
'nodesPerCall' => $nodesPerCall,
89 'lastIndent' => 0,
'tagsToClose' => array());
92 $session->set($this->DOCUMENT_INFO, $documentInfo);
101 return array(
'name' =>
Message::get(
'Initialization'),
'size' => 1,
'oids' => array(1),
'callback' =>
'initExport');
110 return $this->_workPackages[$step-1][
'name'].
" ...";
121 $documentInfo = $session->get($this->DOCUMENT_INFO);
124 unlink($documentInfo[
'docFile']);
127 $fileHandle = fopen($documentInfo[
'docFile'],
"a");
128 FileUtil::fputsUnicode($fileHandle,
'<?xml version="1.0" encoding="UTF-8"?>'.$documentInfo[
'docLinebreak']);
129 if ($documentInfo[
'docType'] !=
"")
130 FileUtil::fputsUnicode($fileHandle,
'<!DOCTYPE '.$documentInfo[
'docType'].
' SYSTEM "'.$documentInfo[
'dtd'].
'">'.$documentInfo[
'docLinebreak']);
131 FileUtil::fputsUnicode($fileHandle,
'<'.$documentInfo[
'docRootElement'].
'>'.$documentInfo[
'docLinebreak']);
137 $rootTypes = $parser->getValue(
'rootTypes',
'cms');
139 if (is_array($rootTypes))
142 foreach($rootTypes as $rootType)
143 $rootOIDs = array_merge($rootOIDs, $persistenceFacade->getOIDs($rootType));
147 $nextOID = array_shift($rootOIDs);
148 $session->set($this->ROOT_OIDS, $rootOIDs);
169 $documentInfo = $session->get($this->DOCUMENT_INFO);
173 $iteratorID = $session->get($this->ITERATOR_ID);
174 if ($iteratorID != null)
178 if ($iterator == null && $oids[0] != null)
182 if ($iterator == null)
189 $fileHandle = fopen($documentInfo[
'docFile'],
"a");
191 $documentInfo[
'endTag'] =
false;
192 while (!$iterator->isEnd() && $counter < $documentInfo[
'nodesPerCall'])
195 $documentInfo = $this->
writeNode($fileHandle, $iterator->getCurrentOID(), $iterator->getCurrentDepth()+1, $documentInfo);
196 $iterator->proceed();
202 $session->set($this->DOCUMENT_INFO, $documentInfo);
205 $rootOIDs = $session->get($this->ROOT_OIDS);
206 if ($iterator->isEnd() &&
sizeof($rootOIDs) > 0)
209 $nextOID = array_shift($rootOIDs);
212 $session->set($this->ROOT_OIDS, $rootOIDs);
215 $session->set($this->ITERATOR_ID, $tmp);
217 $name =
Message::get(
'Exporting tree: start with %1%', array($nextOID));
220 elseif (!$iterator->isEnd())
223 $iteratorID = $iterator->save();
224 $session->set($this->ITERATOR_ID, $iteratorID);
226 $name =
Message::get(
'Exporting tree: continue with %1%', array($iterator->getCurrentOID()));
244 $documentInfo = $session->get($this->DOCUMENT_INFO);
247 $fileHandle = fopen($documentInfo[
'docFile'],
"a");
248 $this->
endTags($fileHandle, 1, $documentInfo);
249 FileUtil::fputsUnicode($fileHandle,
'</'.$documentInfo[
'docRootElement'].
'>'.$documentInfo[
'docLinebreak']);
254 $session->set($this->ROOT_OIDS, $tmp);
255 $session->set($this->ITERATOR_ID, $tmp);
256 $session->set($this->DOCUMENT_INFO, $tmp);
264 function endTags($fileHandle, $curIndent, $documentInfo)
266 $lastIndent = $documentInfo[
'lastIndent'];
269 if ($curIndent < $lastIndent)
271 for ($i=$lastIndent-$curIndent;$i>0;$i--)
273 $closeTag = array_shift($documentInfo[
'tagsToClose']);
274 FileUtil::fputsUnicode($fileHandle, str_repeat($documentInfo[
'docIndent'], $closeTag[
"indent"]).
'</'.$closeTag[
"name"].
'>'.$documentInfo[
'docLinebreak']);
286 function writeNode($fileHandle, $oid, $depth, $documentInfo)
290 $numChildren =
sizeof($node->getProperty(
'childoids'));
292 $lastIndent = $documentInfo[
'lastIndent'];
294 $this->
endTags($fileHandle, $curIndent, $documentInfo);
296 if (!$documentInfo[
'endTag'])
298 if ($numChildren > 0)
300 $closeTag = array(
"name" => $node->getType(),
"indent" => $curIndent);
301 array_unshift($documentInfo[
'tagsToClose'], $closeTag);
302 $documentInfo[
'endTag'] =
true;
308 FileUtil::fputsUnicode($fileHandle, str_repeat($documentInfo[
'docIndent'], $curIndent).
'<'.$node->getType());
313 foreach ($attributeNames as $curAttribute)
314 if ($node->getValue($curAttribute) !=
'')
315 FileUtil::fputsUnicode($fileHandle,
' '.$curAttribute.
'="'.$this->formatValue($node->getValue($curAttribute,
DATATYPE_ATTRIBUTE)).
'"');
318 if ($numChildren > 0)
322 foreach ($elementNames as $curElement)
324 if ($node->getValue($curElement) !=
'')
329 if ($numChildren > 0)
331 $closeTag = array(
"name" => $node->getType(),
"indent" => $curIndent);
332 array_unshift($documentInfo[
'tagsToClose'], $closeTag);
337 $documentInfo[
'lastIndent'] = $curIndent;
340 return $documentInfo;
350 return htmlentities(str_replace(array(
"\r",
"\n"), array(
"",
""), nl2br($value)), ENT_QUOTES);
writeNode($fileHandle, $oid, $depth, $documentInfo)
get($message, $parameters=null, $domain='', $lang='')
initialize(&$request, &$response)
XMLExportController exports the content tree into an XML file.
endTags($fileHandle, $curIndent, $documentInfo)
addWorkPackage($name, $size, $oids, $callback, $args=null)
PersistentIterator is used to iterate over a tree/list build of oids using a Depth-First-Algorithm. To persist its state use the PersistentIterator::save() method, to restore its state use the static PersistentIterator::load() method, which returns the loaded instance. States are identified by an unique id, which is provided after saving. PersistentIterator implements the 'Iterator Pattern'.
BatchController allows to define work packages that will be processed in a sequence. It simplifies the usage of LongTaskController functionality for splitting different bigger tasks into many smaller (similar) tasks where the whole number of tasks isn't known at designtime.