Beispiel #1
0
 /**
  * @see \eZ\Publish\SPI\Search\Handler::findLocations
  */
 public function findLocations(LocationQuery $query, array $languageFilter = array())
 {
     if (!isset($languageFilter['languages'])) {
         $languageFilter['languages'] = array();
     }
     if (!isset($languageFilter['useAlwaysAvailable'])) {
         $languageFilter['useAlwaysAvailable'] = true;
     }
     $start = microtime(true);
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $query->query = $query->query ?: new Criterion\MatchAll();
     if (count($query->facetBuilders)) {
         throw new NotImplementedException('Facets are not supported by the legacy search engine.');
     }
     // The legacy search does not know about scores, so we just
     // combine the query with the filter
     $data = $this->locationGateway->find(new Criterion\LogicalAnd(array($query->query, $query->filter)), $query->offset, $query->limit, $query->sortClauses, $languageFilter, $query->performCount);
     $result = new SearchResult();
     $result->time = microtime(true) - $start;
     $result->totalCount = $data['count'];
     $locationList = $this->locationMapper->createLocationsFromRows($data['rows']);
     foreach ($locationList as $index => $location) {
         $searchHit = new SearchHit();
         $searchHit->valueObject = $location;
         $searchHit->matchedTranslation = $this->extractMatchedLanguage($data['rows'][$index]['language_mask'], $data['rows'][$index]['initial_language_id'], $languageFilter);
         $result->searchHits[] = $searchHit;
     }
     return $result;
 }
Beispiel #2
0
 /**
  * Copy location object identified by $sourceId, into destination identified by $destinationParentId.
  *
  * Performs a deep copy of the location identified by $sourceId and all of
  * its child locations, copying the most recent published content object
  * for each location to a new content object without any additional version
  * information. Relations are not copied. URLs are not touched at all.
  *
  * @todo update subtree modification time, optionally retain dates and set creator
  *
  * @param mixed $sourceId
  * @param mixed $destinationParentId
  *
  * @return Location the newly created Location.
  */
 public function copySubtree($sourceId, $destinationParentId)
 {
     $children = $this->locationGateway->getSubtreeContent($sourceId);
     $destinationParentData = $this->locationGateway->getBasicNodeData($destinationParentId);
     $defaultObjectStates = $this->getDefaultContentStates();
     $contentMap = array();
     $locationMap = array($children[0]["parent_node_id"] => array("id" => $destinationParentId, "hidden" => (bool) $destinationParentData["is_hidden"], "invisible" => (bool) $destinationParentData["is_invisible"], "path_identification_string" => $destinationParentData["path_identification_string"]));
     $locations = array();
     foreach ($children as $child) {
         $locations[$child["contentobject_id"]][$child["node_id"]] = true;
     }
     $time = time();
     $mainLocations = array();
     $mainLocationsUpdate = array();
     foreach ($children as $index => $child) {
         // Copy content
         if (!isset($contentMap[$child["contentobject_id"]])) {
             $content = $this->contentHandler->copy($child["contentobject_id"], $child["contentobject_version"]);
             $this->setContentStates($content, $defaultObjectStates);
             $content = $this->contentHandler->publish($content->versionInfo->contentInfo->id, $content->versionInfo->contentInfo->currentVersionNo, new MetadataUpdateStruct(array("publicationDate" => $time, "modificationDate" => $time)));
             $contentMap[$child["contentobject_id"]] = $content->versionInfo->contentInfo->id;
         }
         $createStruct = $this->locationMapper->getLocationCreateStruct($child);
         $createStruct->contentId = $contentMap[$child["contentobject_id"]];
         $parentData = $locationMap[$child["parent_node_id"]];
         $createStruct->parentId = $parentData["id"];
         $createStruct->invisible = $createStruct->hidden || $parentData["hidden"] || $parentData["invisible"];
         $pathString = explode("/", $child["path_identification_string"]);
         $pathString = end($pathString);
         $createStruct->pathIdentificationString = strlen($pathString) > 0 ? $parentData["path_identification_string"] . "/" . $pathString : null;
         // Use content main location if already set, otherwise create location as main
         if (isset($mainLocations[$child["contentobject_id"]])) {
             $createStruct->mainLocationId = $locationMap[$mainLocations[$child["contentobject_id"]]]["id"];
         } else {
             $createStruct->mainLocationId = true;
             $mainLocations[$child["contentobject_id"]] = $child["node_id"];
             // If needed mark for update
             if (isset($locations[$child["contentobject_id"]][$child["main_node_id"]]) && count($locations[$child["contentobject_id"]]) > 1 && $child["node_id"] !== $child["main_node_id"]) {
                 $mainLocationsUpdate[$child["contentobject_id"]] = $child["main_node_id"];
             }
         }
         $newLocation = $this->create($createStruct);
         $locationMap[$child["node_id"]] = array("id" => $newLocation->id, "hidden" => $newLocation->hidden, "invisible" => $newLocation->invisible, "path_identification_string" => $newLocation->pathIdentificationString);
         if ($index === 0) {
             $copiedSubtreeRootLocation = $newLocation;
         }
     }
     // Update main locations
     foreach ($mainLocationsUpdate as $contentId => $mainLocationId) {
         $this->changeMainLocation($contentMap[$contentId], $locationMap[$mainLocationId]["id"]);
     }
     // If subtree root is main location for its content, update subtree section to the one of the
     // parent location content
     $subtreeRootContentInfo = $this->contentHandler->loadContentInfo($copiedSubtreeRootLocation->contentId);
     if ($subtreeRootContentInfo->mainLocationId === $copiedSubtreeRootLocation->id) {
         $this->setSectionForSubtree($copiedSubtreeRootLocation->id, $this->contentHandler->loadContentInfo($this->load($destinationParentId)->contentId)->sectionId);
     }
     return $copiedSubtreeRootLocation;
 }
 /**
  * @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);
 }
 /**
  * @see \eZ\Publish\SPI\Persistence\Content\Location\Search\Handler::findLocations
  */
 public function findLocations(LocationQuery $query)
 {
     $start = microtime(true);
     $query->filter = $query->filter ?: new Criterion\MatchAll();
     $query->query = $query->query ?: new Criterion\MatchAll();
     if (count($query->facetBuilders)) {
         throw new NotImplementedException("Facets are not supported by the legacy search engine.");
     }
     // The legacy search does not know about scores, so we just
     // combine the query with the filter
     $data = $this->gateway->find(new Criterion\LogicalAnd(array($query->query, $query->filter)), $query->offset, $query->limit, $query->sortClauses);
     $result = new SearchResult();
     $result->time = microtime(true) - $start;
     $result->totalCount = $data['count'];
     foreach ($this->locationMapper->createLocationsFromRows($data['rows']) as $location) {
         $result->searchHits[] = new SearchHit(array("valueObject" => $location));
     }
     return $result;
 }
Beispiel #5
0
 /**
  * Returns an array of all trashed locations satisfying the $criterion (if provided),
  * sorted with SortClause objects contained in $sort (if any).
  * If no criterion is provided (null), no filter is applied
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion
  * @param int $offset Offset to start listing from, 0 by default
  * @param int $limit Limit for the listing. Null by default (no limit)
  * @param \eZ\Publish\API\Repository\Values\Content\Query\SortClause[] $sort
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location\Trashed[]
  */
 public function findTrashItems(Criterion $criterion = null, $offset = 0, $limit = null, array $sort = null)
 {
     // CBA: Ignore criterion for now.
     $rows = $this->locationGateway->listTrashed($offset, $limit, $sort);
     $items = array();
     foreach ($rows as $row) {
         $items[] = $this->locationMapper->createLocationFromRow($row, null, new Trashed());
     }
     return $items;
 }
Beispiel #6
0
 /**
  * Loads the data for the location identified by $locationId.
  *
  * @param int $locationId
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Location
  */
 public function loadLocation($locationId)
 {
     $data = $this->locationGateway->getBasicNodeData($locationId);
     return $this->locationMapper->createLocationFromRow($data);
 }
Beispiel #7
0
 /**
  * @covers eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper::getLocationCreateStruct
  */
 public function testGetLocationCreateStruct()
 {
     $mapper = new Mapper();
     $createStruct = $mapper->getLocationCreateStruct($this->locationRow);
     $this->assertNotEquals($this->locationRow["remote_id"], $createStruct->remoteId);
     $this->assertPropertiesCorrect($this->locationCreateStructValues, $createStruct);
 }
 /**
  * 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"]);
 }
 /**
  * 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']);
 }