Ejemplo n.º 1
0
 /**
  * Creates a new location rooted at $location->parentId.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location\CreateStruct $createStruct
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location
  */
 public function create(CreateStruct $createStruct)
 {
     $parentNodeData = $this->locationGateway->getBasicNodeData($createStruct->parentId);
     $locationStruct = $this->locationGateway->create($createStruct, $parentNodeData);
     $this->locationGateway->createNodeAssignment($createStruct, $parentNodeData['node_id'], LocationGateway::NODE_ASSIGNMENT_OP_CODE_CREATE_NOP);
     return $locationStruct;
 }
Ejemplo n.º 2
0
 /**
  * Triggers delete operations for $trashItem.
  * If there is no more locations for corresponding content, then it will be deleted as well.
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Location\Trashed $trashItem
  *
  * @return void
  */
 protected function delete(Trashed $trashItem)
 {
     $this->locationGateway->removeElementFromTrash($trashItem->id);
     if ($this->locationGateway->countLocationsByContentId($trashItem->contentId) < 1) {
         $this->contentHandler->deleteContent($trashItem->contentId);
     }
 }
Ejemplo n.º 3
0
 /**
  * Changes main location of content identified by given $contentId to location identified by given $locationId.
  *
  * Updates ezcontentobject_tree and eznode_assignment tables (eznode_assignment for content current version number).
  *
  * @param mixed $contentId
  * @param mixed $locationId
  */
 public function changeMainLocation($contentId, $locationId)
 {
     $parentLocationId = $this->loadLocation($locationId)->parentId;
     // Update ezcontentobject_tree and eznode_assignment tables
     $this->locationGateway->changeMainLocation($contentId, $locationId, $this->loadContentInfo($contentId)->currentVersionNo, $parentLocationId);
     // Update subtree section to the one of the new main location parent location content
     $this->setSectionForSubtree($locationId, $this->loadContentInfo($this->loadLocation($parentLocationId)->contentId)->sectionId);
 }
Ejemplo n.º 4
0
 /**
  * Deletes given version, its fields, node assignment, relations and names.
  *
  * Removes the relations, but not the related objects.
  *
  * @param int $contentId
  * @param int $versionNo
  *
  * @return bool
  */
 public function deleteVersion($contentId, $versionNo)
 {
     $versionInfo = $this->loadVersionInfo($contentId, $versionNo);
     $this->locationGateway->deleteNodeAssignment($contentId, $versionNo);
     $this->fieldHandler->deleteFields($contentId, $versionInfo);
     $this->contentGateway->deleteRelations($contentId, $versionNo);
     $this->contentGateway->deleteVersions($contentId, $versionNo);
     $this->contentGateway->deleteNames($contentId, $versionNo);
 }
Ejemplo n.º 5
0
 /**
  * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::deleteTrashItem
  */
 public function testDeleteTrashItemStillHaveLocations()
 {
     $handler = $this->getTrashHandler();
     $this->locationGateway->expects($this->once())->method('loadTrashByLocation')->with(69)->will($this->returnValue(array('node_id' => 69, 'contentobject_id' => 67, 'path_string' => '/1/2/69')));
     $this->locationMapper->expects($this->once())->method('createLocationFromRow')->will($this->returnValue(new Trashed(array('id' => 69, 'contentId' => 67, 'pathString' => '/1/2/69'))));
     $this->locationGateway->expects($this->once())->method('removeElementFromTrash')->with(69);
     $this->locationGateway->expects($this->once())->method('countLocationsByContentId')->with(67)->will($this->returnValue(1));
     $this->contentHandler->expects($this->never())->method('deleteContent');
     $handler->deleteTrashItem(69);
 }
Ejemplo n.º 6
0
 /**
  * Changes main location of content identified by given $contentId to location identified by given $locationId
  *
  * Updates ezcontentobject_tree table for the given $contentId and eznode_assignment table for the given
  * $contentId, $parentLocationId and $versionNo
  *
  * @param mixed $contentId
  * @param mixed $locationId
  * @param mixed $versionNo version number, needed to update eznode_assignment table
  * @param mixed $parentLocationId parent location of location identified by $locationId, needed to update
  *        eznode_assignment table
  *
  * @return void
  */
 public function changeMainLocation($contentId, $locationId, $versionNo, $parentLocationId)
 {
     try {
         return $this->innerGateway->changeMainLocation($contentId, $locationId, $versionNo, $parentLocationId);
     } catch (DBALException $e) {
         throw new RuntimeException('Database error', 0, $e);
     } catch (PDOException $e) {
         throw new RuntimeException('Database error', 0, $e);
     }
 }
Ejemplo n.º 7
0
 /**
  * @param mixed $oldParentId
  * @param mixed $newParentId
  *
  * @return array
  */
 protected function getCopiedLocationsMap($oldParentId, $newParentId)
 {
     $originalLocations = $this->locationGateway->getSubtreeContent($oldParentId);
     $copiedLocations = $this->locationGateway->getSubtreeContent($newParentId);
     $map = array();
     foreach ($originalLocations as $index => $originalLocation) {
         $map['eznode:' . $originalLocation['node_id']] = 'eznode:' . $copiedLocations[$index]['node_id'];
     }
     return $map;
 }
Ejemplo n.º 8
0
 /**
  * Test for the copySubtree() method.
  *
  * @covers eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler::copySubtree
  *
  * @return void
  */
 public function testCopySubtree()
 {
     $handler = $this->getPartlyMockedHandler(array("load", "changeMainLocation", "setSectionForSubtree", "create"));
     $subtreeContentRows = array(array("node_id" => 10, "main_node_id" => 1, "parent_node_id" => 3, "contentobject_id" => 21, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_10", "sort_field" => 2, "sort_order" => 1), array("node_id" => 11, "main_node_id" => 11, "parent_node_id" => 10, "contentobject_id" => 211, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_11", "sort_field" => 2, "sort_order" => 1), array("node_id" => 12, "main_node_id" => 15, "parent_node_id" => 10, "contentobject_id" => 215, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_12", "sort_field" => 2, "sort_order" => 1), array("node_id" => 13, "main_node_id" => 2, "parent_node_id" => 10, "contentobject_id" => 22, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_13", "sort_field" => 2, "sort_order" => 1), array("node_id" => 14, "main_node_id" => 11, "parent_node_id" => 13, "contentobject_id" => 211, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_14", "sort_field" => 2, "sort_order" => 1), array("node_id" => 15, "main_node_id" => 15, "parent_node_id" => 13, "contentobject_id" => 215, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_15", "sort_field" => 2, "sort_order" => 1), array("node_id" => 16, "main_node_id" => 16, "parent_node_id" => 15, "contentobject_id" => 216, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 0, "priority" => 0, "path_identification_string" => "test_16", "sort_field" => 2, "sort_order" => 1));
     $destinationData = array("node_id" => 5, "main_node_id" => 5, "parent_node_id" => 4, "contentobject_id" => 200, "contentobject_version" => 1, "is_hidden" => 0, "is_invisible" => 1, "path_identification_string" => "test_destination");
     $mainLocationsMap = array(true, true, true, true, 1011, 1012, true);
     $updateMainLocationsMap = array(1215 => 1015);
     $offset = 1000;
     $this->locationGateway->expects($this->once())->method("getSubtreeContent")->with($subtreeContentRows[0]["node_id"])->will($this->returnValue($subtreeContentRows));
     $this->locationGateway->expects($this->once())->method("getBasicNodeData")->with($destinationData["node_id"])->will($this->returnValue($destinationData));
     $objectStateHandlerCall = 0;
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method("loadAllGroups")->will($this->returnValue(array(new ObjectStateGroup(array("id" => 10)), new ObjectStateGroup(array("id" => 20)))));
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method("loadObjectStates")->with($this->equalTo(10))->will($this->returnValue(array(new ObjectState(array("id" => 11, "groupId" => 10)), new ObjectState(array("id" => 12, "groupId" => 10)))));
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method("loadObjectStates")->with($this->equalTo(20))->will($this->returnValue(array(new ObjectState(array("id" => 21, "groupId" => 20)), new ObjectState(array("id" => 22, "groupId" => 20)))));
     $defaultObjectStates = array(new ObjectState(array("id" => 11, "groupId" => 10)), new ObjectState(array("id" => 21, "groupId" => 20)));
     $contentIds = array_values(array_unique(array_map(function ($row) {
         return $row["contentobject_id"];
     }, $subtreeContentRows)));
     foreach ($contentIds as $index => $contentId) {
         $this->contentHandler->expects($this->at($index * 2))->method("copy")->with($contentId, 1)->will($this->returnValue(new Content(array("versionInfo" => new VersionInfo(array("contentInfo" => new ContentInfo(array("id" => $contentId + $offset, "currentVersionNo" => 1))))))));
         foreach ($defaultObjectStates as $objectState) {
             $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method("setContentState")->with($contentId + $offset, $objectState->groupId, $objectState->id);
         }
         $this->contentHandler->expects($this->at($index * 2 + 1))->method("publish")->with($contentId + $offset, 1, $this->isInstanceOf("eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct"))->will($this->returnValue(new Content(array("versionInfo" => new VersionInfo(array("contentInfo" => new ContentInfo(array("id" => $contentId + $offset))))))));
     }
     $lastContentHandlerIndex = $index * 2 + 1;
     $pathStrings = array($destinationData["node_id"] => $destinationData["path_identification_string"]);
     foreach ($subtreeContentRows as $index => $row) {
         $mapper = new Mapper();
         $createStruct = $mapper->getLocationCreateStruct($row);
         $this->locationMapper->expects($this->at($index))->method("getLocationCreateStruct")->with($row)->will($this->returnValue($createStruct));
         $createStruct = clone $createStruct;
         $createStruct->contentId = $createStruct->contentId + $offset;
         $createStruct->parentId = $index === 0 ? $destinationData["node_id"] : $createStruct->parentId + $offset;
         $createStruct->invisible = true;
         $createStruct->mainLocationId = $mainLocationsMap[$index];
         $createStruct->pathIdentificationString = $pathStrings[$createStruct->parentId] . "/" . $row["path_identification_string"];
         $pathStrings[$row["node_id"] + $offset] = $createStruct->pathIdentificationString;
         $handler->expects($this->at($index))->method('create')->with($createStruct)->will($this->returnValue(new Location(array("id" => $row["node_id"] + $offset, "contentId" => $row["contentobject_id"], "hidden" => false, "invisible" => true, "pathIdentificationString" => $createStruct->pathIdentificationString))));
     }
     foreach ($updateMainLocationsMap as $contentId => $locationId) {
         $handler->expects($this->any())->method("changeMainLocation")->with($contentId, $locationId);
     }
     $this->contentHandler->expects($this->at($lastContentHandlerIndex + 1))->method("loadContentInfo")->with(21)->will($this->returnValue(new ContentInfo(array("mainLocationId" => 1010))));
     $handler->expects($this->once())->method("load")->with($destinationData["node_id"])->will($this->returnValue(new Location(array("contentId" => $destinationData["contentobject_id"]))));
     $this->contentHandler->expects($this->at($lastContentHandlerIndex + 2))->method("loadContentInfo")->with($destinationData["contentobject_id"])->will($this->returnValue(new ContentInfo(array("sectionId" => 12345))));
     $handler->expects($this->once())->method("setSectionForSubtree")->with($subtreeContentRows[0]["node_id"] + $offset, 12345);
     $handler->copySubtree($subtreeContentRows[0]["node_id"], $destinationData["node_id"]);
 }
Ejemplo n.º 9
0
 /**
  * Test for the copySubtree() method.
  *
  * @covers eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler::copySubtree
  */
 public function testCopySubtree()
 {
     $handler = $this->getPartlyMockedHandler(array('load', 'changeMainLocation', 'setSectionForSubtree', 'create'));
     $subtreeContentRows = array(array('node_id' => 10, 'main_node_id' => 1, 'parent_node_id' => 3, 'contentobject_id' => 21, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_10', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 11, 'main_node_id' => 11, 'parent_node_id' => 10, 'contentobject_id' => 211, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_11', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 12, 'main_node_id' => 15, 'parent_node_id' => 10, 'contentobject_id' => 215, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_12', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 13, 'main_node_id' => 2, 'parent_node_id' => 10, 'contentobject_id' => 22, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_13', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 14, 'main_node_id' => 11, 'parent_node_id' => 13, 'contentobject_id' => 211, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_14', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 15, 'main_node_id' => 15, 'parent_node_id' => 13, 'contentobject_id' => 215, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_15', 'sort_field' => 2, 'sort_order' => 1), array('node_id' => 16, 'main_node_id' => 16, 'parent_node_id' => 15, 'contentobject_id' => 216, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_16', 'sort_field' => 2, 'sort_order' => 1));
     $destinationData = array('node_id' => 5, 'main_node_id' => 5, 'parent_node_id' => 4, 'contentobject_id' => 200, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 1, 'path_identification_string' => 'test_destination');
     $mainLocationsMap = array(true, true, true, true, 1011, 1012, true);
     $updateMainLocationsMap = array(1215 => 1015);
     $offset = 1000;
     $this->locationGateway->expects($this->once())->method('getSubtreeContent')->with($subtreeContentRows[0]['node_id'])->will($this->returnValue($subtreeContentRows));
     $this->locationGateway->expects($this->once())->method('getBasicNodeData')->with($destinationData['node_id'])->will($this->returnValue($destinationData));
     $objectStateHandlerCall = 0;
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method('loadAllGroups')->will($this->returnValue(array(new ObjectStateGroup(array('id' => 10)), new ObjectStateGroup(array('id' => 20)))));
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method('loadObjectStates')->with($this->equalTo(10))->will($this->returnValue(array(new ObjectState(array('id' => 11, 'groupId' => 10)), new ObjectState(array('id' => 12, 'groupId' => 10)))));
     $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method('loadObjectStates')->with($this->equalTo(20))->will($this->returnValue(array(new ObjectState(array('id' => 21, 'groupId' => 20)), new ObjectState(array('id' => 22, 'groupId' => 20)))));
     $defaultObjectStates = array(new ObjectState(array('id' => 11, 'groupId' => 10)), new ObjectState(array('id' => 21, 'groupId' => 20)));
     $contentIds = array_values(array_unique(array_map(function ($row) {
         return $row['contentobject_id'];
     }, $subtreeContentRows)));
     foreach ($contentIds as $index => $contentId) {
         $this->contentHandler->expects($this->at($index * 2))->method('copy')->with($contentId, 1)->will($this->returnValue(new Content(array('versionInfo' => new VersionInfo(array('contentInfo' => new ContentInfo(array('id' => $contentId + $offset, 'currentVersionNo' => 1))))))));
         foreach ($defaultObjectStates as $objectState) {
             $this->objectStateHandler->expects($this->at($objectStateHandlerCall++))->method('setContentState')->with($contentId + $offset, $objectState->groupId, $objectState->id);
         }
         $this->contentHandler->expects($this->at($index * 2 + 1))->method('publish')->with($contentId + $offset, 1, $this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\MetadataUpdateStruct'))->will($this->returnValue(new Content(array('versionInfo' => new VersionInfo(array('contentInfo' => new ContentInfo(array('id' => $contentId + $offset))))))));
     }
     $lastContentHandlerIndex = $index * 2 + 1;
     $pathStrings = array($destinationData['node_id'] => $destinationData['path_identification_string']);
     foreach ($subtreeContentRows as $index => $row) {
         $mapper = new Mapper();
         $createStruct = $mapper->getLocationCreateStruct($row);
         $this->locationMapper->expects($this->at($index))->method('getLocationCreateStruct')->with($row)->will($this->returnValue($createStruct));
         $createStruct = clone $createStruct;
         $createStruct->contentId = $createStruct->contentId + $offset;
         $createStruct->parentId = $index === 0 ? $destinationData['node_id'] : $createStruct->parentId + $offset;
         $createStruct->invisible = true;
         $createStruct->mainLocationId = $mainLocationsMap[$index];
         $createStruct->pathIdentificationString = $pathStrings[$createStruct->parentId] . '/' . $row['path_identification_string'];
         $pathStrings[$row['node_id'] + $offset] = $createStruct->pathIdentificationString;
         $handler->expects($this->at($index))->method('create')->with($createStruct)->will($this->returnValue(new Location(array('id' => $row['node_id'] + $offset, 'contentId' => $row['contentobject_id'], 'hidden' => false, 'invisible' => true, 'pathIdentificationString' => $createStruct->pathIdentificationString))));
     }
     foreach ($updateMainLocationsMap as $contentId => $locationId) {
         $handler->expects($this->any())->method('changeMainLocation')->with($contentId, $locationId);
     }
     $this->contentHandler->expects($this->at($lastContentHandlerIndex + 1))->method('loadContentInfo')->with(21)->will($this->returnValue(new ContentInfo(array('mainLocationId' => 1010))));
     $handler->expects($this->once())->method('load')->with($destinationData['node_id'])->will($this->returnValue(new Location(array('contentId' => $destinationData['contentobject_id']))));
     $this->contentHandler->expects($this->at($lastContentHandlerIndex + 2))->method('loadContentInfo')->with($destinationData['contentobject_id'])->will($this->returnValue(new ContentInfo(array('sectionId' => 12345))));
     $handler->expects($this->once())->method('setSectionForSubtree')->with($subtreeContentRows[0]['node_id'] + $offset, 12345);
     $handler->copySubtree($subtreeContentRows[0]['node_id'], $destinationData['node_id']);
 }