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/model/class.Node.php");
23 require_once(BASE.
"wcmf/lib/model/class.NodeUtil.php");
66 parent::initialize($request, $response);
69 if ($request->getAction() !=
'continue')
74 if (!$request->hasValue(
'nodes_per_call')) {
75 $request->setValue(
'nodes_per_call', $this->_NODES_PER_CALL);
77 if (!$request->hasValue(
'recursive')) {
78 $request->setValue(
'recursive',
true);
82 $session->set($this->REQUEST, $request, array(BASE.
"wcmf/lib/presentation/class.ControllerMessage.php"));
84 $session->set($this->OBJECT_MAP, $map);
92 if ($this->_request->getAction() !=
'continue')
95 if(strlen($this->_request->getValue(
'oid')) == 0)
100 if($this->_request->hasValue(
'targetoid') &&
103 $this->
appendErrorMsg(
"Invalid 'targetoid' parameter given in data.");
109 if ($this->_request->hasValue(
'targetoid'))
112 $targetOID = $this->_request->getValue(
'targetoid');
113 $nodeOID = $this->_request->getValue(
'oid');
119 $tplNode = &$persistenceFacade->create($targetType, 1);
121 if (!in_array($nodeType, array_keys($possibleChildren)))
124 array($targetOID, $nodeType)));
129 $template = &$possibleChildren[$nodeType];
130 if (!$template->getProperty(
'canCreate'))
132 $this->
appendErrorMsg(
Message::get(
"%1% does not accept children of type %2%. The maximum number of children of that type is reached.",
133 array($targetOID, $nodeType)));
143 return parent::validate();
151 if ($this->_request->getAction() ==
'move') {
154 else if ($this->_request->getAction() ==
'copy') {
157 $name .=
': '.$this->_request->getValue(
'oid');
160 return array(
'name' => $name,
'size' => 1,
'oids' => array(1),
'callback' =>
'startProcess');
171 return $this->_workPackages[$step-1][
'name'].
" ...";
182 $request = $session->get($this->REQUEST);
183 $action = $request->getAction();
184 $targetOID = $request->getValue(
'targetoid');
185 $nodeOID = $request->getValue(
'oid');
188 if ($action ==
'move')
190 if ($request->hasValue(
'target_initparams')) {
191 WCMFException::throwEx(
"Moving nodes to a different store is not supported. Use the 'copy' action instead.", __FILE__, __LINE__);
201 $parentNode->addChild($nodeCopy);
211 Log::info(
"Moved: ".$nodeOID.
" to ".$parentNode->getOID(), __CLASS__);
215 else if ($action ==
'copy')
220 $iteratorID = $iterator->save();
221 $session->set($this->ITERATOR_ID, $iteratorID);
224 $nodeCopy = &$this->
copyNode($iterator->getCurrentOID());
229 $parentNode->addChild($nodeCopy);
235 $iterator->proceed();
238 if ($request->getBooleanValue(
'recursive') && !$iterator->isEnd())
240 $iteratorID = $iterator->save();
241 $session->set($this->ITERATOR_ID, $iteratorID);
243 $name =
Message::get(
'Copying tree: continue with %1%', array($iterator->getCurrentOID()));
263 $request = $session->get($this->REQUEST);
264 $action = $request->getAction();
265 $targetOID = $request->getValue(
'targetoid');
266 $nodeOID = $request->getValue(
'oid');
270 $iteratorID = $session->get($this->ITERATOR_ID);
271 if ($iteratorID != null) {
276 if ($iterator == null)
284 while (!$iterator->isEnd() && $counter < $request->getValue(
'nodes_per_call'))
286 $currentOID = $iterator->getCurrentOID();
289 $iterator->proceed();
294 if (!$iterator->isEnd())
297 $iteratorID = $iterator->save();
298 $session->set($this->ITERATOR_ID, $iteratorID);
300 $name =
Message::get(
'Copying tree: continue with %1%', array($iterator->getCurrentOID()));
315 $this->_response->setValue(
'oid', $oid);
321 $session->set($this->REQUEST, $tmp);
322 $session->set($this->OBJECT_MAP, $tmp);
323 $session->set($this->ITERATOR_ID, $tmp);
339 $node = &$persistenceFacade->load($oid, BUIDLDEPTH_SINGLE);
345 $nodeCopy = &$this->
getCopy($node->getOID());
346 if ($nodeCopy == null)
350 $node->copyValues($nodeCopy, array(),
false);
355 Log::debug(
"Parents: ".join(
', ', $node->getProperty(
'parentoids')), __CLASS__);
357 foreach ($node->getProperty(
'parentoids') as $parentOID)
359 $copiedParent = &$this->
getCopy($parentOID);
360 if ($copiedParent != null) {
361 $copiedParent->addChild($nodeCopy);
363 Log::debug(
"Added ".$nodeCopy->getOID().
" to ".$copiedParent->getOID(), __CLASS__);
373 Log::info(
"Copied: ".$node->getOID().
" to ".$nodeCopy->getOID(), __CLASS__);
382 Log::debug(
"Children: ".join(
', ', $node->getProperty(
'childoids')), __CLASS__);
384 foreach ($node->getProperty(
'childoids') as $childOID)
386 $copiedChild = &$this->
getCopy($childOID);
387 if ($copiedChild != null) {
388 $nodeCopy->addChild($copiedChild);
391 Log::debug(
"Added ".$copiedChild->getOID().
" to ".$nodeCopy->getOID(), __CLASS__);
392 Log::debug($copiedChild->toString(), __CLASS__);
406 if ($this->_targetNode == null)
409 if ($targetOID == null) {
410 $targetNode =
new Node(
'');
415 $this->_targetNode = &$targetNode;
427 $registry = $session->get($this->OBJECT_MAP);
429 $registry[$origNode->getOID()] = $copyNode->getOID();
430 $registry[$origNode->getBaseOID()] = $copyNode->getOID();
431 $session->set($this->OBJECT_MAP, $registry);
441 $registry = $session->get($this->OBJECT_MAP);
445 $requestedType = $origOIDParts[
'type'];
448 if (!isset($registry[$origOID])) {
453 if (!isset($registry[$baseOID]))
456 Log::debug(
"Copy of ".$oid.
" not found.", __CLASS__);
465 $copyOID = $registry[$oid];
469 if ($copyOIDParts[
'type'] != $requestedType) {
482 if ($copyOID != null)
498 $originalMapper = &$persistenceFacade->getMapper($node->getType());
501 $persistenceFacade->setMapper($node->getType(), $targetMapper);
504 $persistenceFacade->setMapper($node->getType(), $originalMapper);
515 $originalMapper = &$persistenceFacade->getMapper($type);
518 $persistenceFacade->setMapper($type, $targetMapper);
521 $persistenceFacade->setMapper($node->getType(), $originalMapper);
534 $request = $session->get($this->REQUEST);
535 if ($request->hasValue(
'target_initparams'))
538 $mapperClass = get_class($sourceMapper);
539 if (!isset($this->_targetMapper[$mapperClass]))
541 $initSection = $request->getValue(
'target_initparams');
543 if (($initParams = $parser->getSection($initSection)) ===
false)
548 $targetMapper =
new $mapperClass($initParams);
549 $this->_targetMapper[$mapperClass] = &$targetMapper;
551 return $this->_targetMapper[$mapperClass];
554 return $sourceMapper;
initialize(&$request, &$response)
debug($message, $category)
get($message, $parameters=null, $domain='', $lang='')
Node is the basic component for building trees (although a Node can have one than more parents)...
info($message, $category)
registerCopy(&$origNode, &$copyNode)
getPossibleChildren(&$realNode, &$tplNode, $resolveManyToMany=true)
CopyController is a controller that copies Nodes.
throwEx($message, $file='', $line='')
& getTargetNode($targetOID)
& getTargetMapper(&$sourceMapper)
decomposeOID($oid, $validate=true)
isDebugEnabled($category)
addWorkPackage($name, $size, $oids, $callback, $args=null)
getOIDParameter($oid, $param, $validate=true)
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.