/** * Sends a subtree starting to $locationId to the trash * and returns a Trashed object corresponding to $locationId. * * Moves all locations in the subtree to the Trash. The associated content * objects are left untouched. * * @param mixed $locationId * * @todo Handle field types actions * * @return null|\eZ\Publish\SPI\Persistence\Content\Location\Trashed null if location was deleted, otherwise Trashed object */ public function trashSubtree($locationId) { $locationRows = $this->locationGateway->getSubtreeContent($locationId); $isLocationRemoved = false; $parentLocationId = null; foreach ($locationRows as $locationRow) { if ($locationRow["node_id"] == $locationId) { $parentLocationId = $locationRow["parent_node_id"]; } if ($this->locationGateway->countLocationsByContentId($locationRow["contentobject_id"]) == 1) { $this->locationGateway->trashLocation($locationRow["node_id"]); } else { if ($locationRow["node_id"] == $locationId) { $isLocationRemoved = true; } $this->locationGateway->removeLocation($locationRow["node_id"]); if ($locationRow["node_id"] == $locationRow["main_node_id"]) { $newMainLocationRow = $this->locationGateway->getFallbackMainNodeData($locationRow["contentobject_id"], $locationRow["node_id"]); $this->locationHandler->changeMainLocation($locationRow["contentobject_id"], $newMainLocationRow["node_id"], $newMainLocationRow["contentobject_version"], $newMainLocationRow["parent_node_id"]); } } } if (isset($parentLocationId)) { $this->locationHandler->markSubtreeModified($parentLocationId, time()); } return $isLocationRemoved ? null : $this->loadTrashItem($locationId); }
/** * @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Trash\Handler::trashSubtree */ public function testTrashSubtreeUpdatesMainLocation() { $handler = $this->getTrashHandler(); $this->locationGateway->expects($this->at(0))->method('getSubtreeContent')->with(20)->will($this->returnValue(array(array('contentobject_id' => 10, 'node_id' => 20, 'main_node_id' => 30, 'parent_node_id' => 40), array('contentobject_id' => 11, 'node_id' => 21, 'main_node_id' => 21, 'parent_node_id' => 41)))); $this->locationGateway->expects($this->at(1))->method('countLocationsByContentId')->with(10)->will($this->returnValue(1)); $this->locationGateway->expects($this->at(2))->method('trashLocation')->with(20); $this->locationGateway->expects($this->at(3))->method('countLocationsByContentId')->with(11)->will($this->returnValue(2)); $this->locationGateway->expects($this->at(4))->method('removeLocation')->with(21); $this->locationGateway->expects($this->at(5))->method('getFallbackMainNodeData')->with(11, 21)->will($this->returnValue(array('node_id' => 100, 'contentobject_version' => 101, 'parent_node_id' => 102))); $this->locationHandler->expects($this->once())->method('changeMainLocation')->with(11, 100, 101, 102); $this->locationHandler->expects($this->once())->method('markSubtreeModified')->with(40); $this->locationGateway->expects($this->at(6))->method('loadTrashByLocation')->with(20)->will($this->returnValue($array = array('data…'))); $this->locationMapper->expects($this->once())->method('createLocationFromRow')->with($array, null, new Trashed())->will($this->returnValue(new Trashed(array('id' => 20)))); $trashedObject = $handler->trashSubtree(20); self::assertInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Location\\Trashed', $trashedObject); self::assertSame(20, $trashedObject->id); }