60 private $REQUEST =
'CopyController.request';
61 private $OBJECT_MAP =
'CopyController.objectmap';
62 private $ITERATOR_ID =
'CopyController.iteratorid';
64 private $_targetNode = null;
67 private $_NODES_PER_CALL = 50;
73 parent::initialize($request, $response);
76 if ($request->
getAction() !=
'continue') {
80 if (!$request->
hasValue(
'nodesPerCall')) {
81 $request->
setValue(
'nodesPerCall', $this->_NODES_PER_CALL);
83 if (!$request->
hasValue(
'recursive')) {
84 $request->
setValue(
'recursive',
true);
88 $session->set($this->REQUEST, $request);
90 $session->set($this->OBJECT_MAP, $map);
100 if ($request->getAction() !=
'continue') {
105 array(
'invalidOids' => array($request->getValue(
'oid')))));
108 if($request->hasValue(
'targetoid')) {
112 array(
'invalidOids' => array($request->getValue(
'targetoid')))));
119 if ($request->hasValue(
'targetoid')) {
125 $nodeType = $nodeOID->getType();
126 $targetType = $targetOID->getType();
128 $tplNode = $persistenceFacade->create($targetType, 1);
129 $possibleChildren = NodeUtil::getPossibleChildren($targetNode, $tplNode);
130 if (!in_array($nodeType, array_keys($possibleChildren))) {
135 $template = $possibleChildren[$nodeType];
136 if (!$template->getProperty(
'canCreate')) {
147 return parent::validate();
157 if ($request->getAction() ==
'move') {
158 $name = $message->getText(
'Moving');
160 else if ($request->getAction() ==
'copy') {
161 $name = $message->getText(
'Copying');
163 $name .=
': '.$request->getValue(
'oid');
166 return array(
'name' => $name,
'size' => 1,
'oids' => array(1),
'callback' =>
'startProcess');
182 $request = $session->get($this->REQUEST);
183 $action = $request->getAction();
188 if ($action ==
'move') {
190 $transaction = $persistenceFacade->getTransaction();
191 $transaction->begin();
194 $nodeCopy = $persistenceFacade->load($nodeOID);
196 if ($targetOID != null) {
199 $parentNode->addNode($nodeCopy);
208 if ($logger->isInfoEnabled()) {
209 $logger->info(
"Moved: ".$nodeOID.
" to ".$parentNode->getOID());
212 $transaction->commit();
214 else if ($action ==
'copy') {
219 $iteratorID = $iterator->save();
220 $session->set($this->ITERATOR_ID, $iteratorID);
223 $nodeCopy = $this->
copyNode($iterator->current());
225 if ($targetOID != null) {
228 $parentNode->addNode($nodeCopy);
236 if ($request->getBooleanValue(
'recursive') && $iterator->valid()) {
237 $iteratorID = $iterator->save();
238 $session->set($this->ITERATOR_ID, $iteratorID);
240 $name = $this->
getMessage()->getText(
'Copying tree: continue with %0%',
241 array($iterator->current()));
261 $request = $session->get($this->REQUEST);
262 $action = $request->getAction();
268 $iteratorID = $session->get($this->ITERATOR_ID);
269 if ($iteratorID != null) {
274 if ($iterator == null) {
281 while ($iterator->valid() && $counter < $request->getValue(
'nodesPerCall')) {
282 $currentOID = $iterator->current();
290 if ($iterator->valid()) {
292 $iteratorID = $iterator->save();
293 $session->set($this->ITERATOR_ID, $iteratorID);
295 $name = $this->
getMessage()->getText(
'Copying tree: continue with %0%',
296 array($iterator->current()));
311 $response->setValue(
'oid', $oid);
317 $session->set($this->REQUEST, $tmp);
318 $session->set($this->OBJECT_MAP, $tmp);
319 $session->set($this->ITERATOR_ID, $tmp);
330 if ($logger->isDebugEnabled()) {
331 $logger->debug(
"Copying node ".$oid);
334 $transaction = $persistenceFacade->getTransaction();
335 $transaction->begin();
338 $node = $persistenceFacade->load($oid);
344 $nodeCopy = $this->
getCopy($node->getOID());
345 if ($nodeCopy == null) {
347 $nodeCopy = $persistenceFacade->create($node->getType());
348 $node->copyValues($nodeCopy,
false);
354 if ($logger->isInfoEnabled()) {
355 $logger->info(
"Copied: ".$node->getOID().
" to ".$nodeCopy->getOID());
357 if ($logger->isDebugEnabled()) {
358 $logger->debug($nodeCopy->__toString());
363 $mapper = $node->getMapper();
364 $relations = $mapper->getRelations();
365 foreach ($relations as $relation) {
366 if ($relation->getOtherNavigability()) {
367 $otherRole = $relation->getOtherRole();
368 $relativeValue = $node->getValue($otherRole);
369 $relatives = $relation->isMultiValued() ? $relativeValue :
370 ($relativeValue != null ? array($relativeValue) : array());
371 foreach ($relatives as $relative) {
372 $copiedRelative = $this->
getCopy($relative->getOID());
373 if ($copiedRelative != null) {
374 $nodeCopy->addNode($copiedRelative, $otherRole);
375 if ($logger->isDebugEnabled()) {
376 $logger->debug(
"Added ".$copiedRelative->getOID().
" to ".$nodeCopy->getOID());
377 $logger->debug($copiedRelative->__toString());
383 $changedOids = $transaction->commit();
395 if ($this->_targetNode == null) {
398 $targetNode = $persistenceFacade->load($targetOID);
399 $this->_targetNode = $targetNode;
401 return $this->_targetNode;
411 $registry = $session->get($this->OBJECT_MAP);
413 $registry[$origNode->
getOID()->__toString()] = $copyNode->
getOID()->__toString();
414 $session->set($this->OBJECT_MAP, $registry);
423 $registry = $session->get($this->OBJECT_MAP);
426 $flippedRegistry = array_flip($registry);
427 foreach ($oidMap as $oldOid => $newOid) {
428 if (isset($flippedRegistry[$oldOid])) {
429 $key = $flippedRegistry[$oldOid];
430 unset($flippedRegistry[$oldOid]);
431 $flippedRegistry[$newOid] = $key;
434 $registry = array_flip($flippedRegistry);
435 $session->set($this->OBJECT_MAP, $registry);
446 $registry = $session->get($this->OBJECT_MAP);
450 if (!isset($registry[$oidStr])) {
452 if ($logger->isDebugEnabled()) {
453 $logger->debug(
"Copy of ".$oidStr.
" not found.");
469 if ($copyOID != null) {
471 $nodeCopy = $persistenceFacade->load($copyOID);
Response holds the response values that are used as output from Controller instances.
getRequest()
Get the Request instance.
copyNode(ObjectId $oid)
Create a copy of the node with the given object id.
getOID()
Get the object id of the PersistentObject.
getCopyOID(ObjectId $origOID)
Get the object id of the copied node for a node id.
getMessage()
Get the Message instance.
static load($persistenceFacade, $session, $uid)
Load an iterator state from the session.
addWorkPackage($name, $size, $oids, $callback, $args=null)
Add a work package to session.
endProcess(ObjectId $oid)
Finish the process and set the result.
ObjectId is the unique identifier of an object.
registerCopy(PersistentObject $origNode, PersistentObject $copyNode)
Register a copied node in the session for later reference.
initialize(Request $request, Response $response)
getAction()
Get the name of the action.
updateCopyOIDs(array $oidMap)
Update the copied oids in the registry.
modify(PersistentObject $node)
Modify the given Node before save action (Called only for the copied root Node, not for its children)...
Request holds the request values that are used as input to Controller instances.
BatchController is used to process complex, longer running actions, that need to be divided into seve...
copyNodes($oids)
Copy nodes provided by the persisted iterator (oids parameter will be ignored)
static parse($oid)
Parse a serialized object id string into an ObjectId instance.
hasValue($name)
Check for existance of a value.
PersistenceException signals an exception in the persistence service.
__toString()
Get a string representation of the object id.
CopyController is used to copy or move Node instances.
setValue($name, $value)
Set a value.
startProcess($oids)
Copy/Move the first node (oids parameter will be ignored)
static get($code, $data=null)
Factory method for retrieving a predefind error instance.
PersistentIterator is used to iterate over a tree/list built of oids using a Depth-First-Algorithm.
getLogger()
Get the Logger instance.
getResponse()
Get the Response instance.
getSession()
Get the Session instance.
getCopy(ObjectId $origOID)
Get the copied node for a node id.
getTargetNode(ObjectId $targetOID)
Get the target node from the request parameter targetoid.
getPersistenceFacade()
Get the PersistenceFacade instance.
PersistentObject defines the interface of all persistent objects.