/**
  * @see eZ\Publish\SPI\Persistence\Content\Location\Trash\Handler
  * @todo Handle field types actions
  */
 public function trashSubtree($locationId)
 {
     $location = $this->handler->locationHandler()->load($locationId);
     $subtreeLocations = $this->backend->find('Content\\Location', array('pathString' => $location->pathString . '%'));
     $isLocationRemoved = false;
     $parentLocationId = null;
     $subtreeLocations[] = $location;
     foreach ($subtreeLocations as $location) {
         if ($location->id == $locationId) {
             $parentLocationId = $location->parentId;
         }
         if (count($this->backend->find('Content\\Location', array('contentId' => $location->contentId))) == 1) {
             $this->backend->delete('Content\\Location', $location->id);
             $this->backend->create('Content\\Location\\Trashed', (array) $location, false);
         } else {
             if ($location->id == $locationId) {
                 $isLocationRemoved = true;
             }
             $this->backend->delete('Content\\Location', $location->id);
             $remainingLocations = $this->backend->find('Content\\Location', array('contentId' => $location->contentId));
             $this->backend->update('Content\\ContentInfo', $location->contentId, array('mainLocationId' => $remainingLocations[0]->id));
         }
     }
     return $isLocationRemoved ? null : $this->loadTrashItem($locationId);
 }
 /**
  * Notifies the underlying engine that a location has moved.
  *
  * This method triggers the change of the autogenerated aliases
  *
  * @param mixed $locationId
  * @param mixed $oldParentId
  * @param mixed $newParentId
  */
 public function locationMoved($locationId, $oldParentId, $newParentId)
 {
     // Get url alias for old parent location
     $oldParentLocationAlias = $this->loadAutogeneratedAlias($oldParentId);
     if (!isset($oldParentLocationAlias)) {
         throw new \RuntimeException("Did not find any url alias for location: {$oldParentLocationAlias}");
     }
     // Get url alias for new parent location
     $newParentLocationAlias = $this->loadAutogeneratedAlias($newParentId);
     if (!isset($newParentLocationAlias)) {
         throw new \RuntimeException("Did not find any url alias for location: {$newParentLocationAlias}");
     }
     // Get url alias for old location
     $oldLocationAlias = $this->loadAutogeneratedAlias($locationId, $oldParentLocationAlias->id["link"]);
     if (!isset($oldLocationAlias)) {
         throw new \RuntimeException("Did not find any url alias for location: {$oldLocationAlias}");
     }
     // Mark as history and use pathData form existing location
     /** @var \eZ\Publish\SPI\Persistence\Content\UrlAlias[] $list */
     $this->backend->update('Content\\UrlAlias', $oldLocationAlias->id["id"], array('isHistory' => true));
     $pathItem = array_pop($oldLocationAlias->pathData);
     // Make path data based on new location and the original
     $pathData = $newParentLocationAlias->pathData;
     $pathData[] = $pathItem;
     $pathIndex = count($pathData) - 1;
     // Create the new url alias object
     $newAlias = $this->backend->create('Content\\UrlAlias', array('parent' => $newParentLocationAlias->id["link"], 'link' => $this->getNextLinkId(), 'type' => URLAlias::LOCATION, 'destination' => $locationId, 'pathData' => $pathData, 'languageCodes' => array_keys($pathData[$pathIndex]['translations']), 'alwaysAvailable' => $pathData[$pathIndex]['always-available'], 'isHistory' => false, 'isCustom' => false, 'forward' => false));
     // Fetch old location children
     $children = $this->backend->find('Content\\UrlAlias', array('parent' => $oldParentLocationAlias->id["link"], 'type' => URLAlias::LOCATION, 'isHistory' => false, 'isCustom' => false));
     // @todo: this needs to recursively historize and copy (with updated path data) the complete subtree
     // Reparent
     foreach ($children as $child) {
         $this->backend->update('Content\\UrlAlias', $child->id["id"], array('parent' => $newAlias->id["link"]));
     }
 }
 /**
  * Performs the publishing operations required to set the version identified by $updateStruct->versionNo and
  * $updateStruct->id as the published one.
  *
  * @param int $contentId
  * @param int $versionNo
  * @param \eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct $metaDataUpdateStruct
  *
  * @return \eZ\Publish\SPI\Persistence\Content The published Content
  */
 public function publish($contentId, $versionNo, MetadataUpdateStruct $metaDataUpdateStruct)
 {
     // Change Content currentVersionNo to the published version
     $this->backend->update('Content', $contentId, array('_currentVersionNo' => $versionNo));
     // Update ContentInfo published flag and change the currentVersionNo to the published version
     $contentInfoUpdateData = array("currentVersionNo" => $versionNo, "isPublished" => true);
     // Update ContentInfo with set properties in $metaDataUpdateStruct
     foreach ($metaDataUpdateStruct as $propertyName => $propertyValue) {
         if (isset($propertyValue)) {
             if ($propertyName === "alwaysAvailable") {
                 $contentInfoUpdateData["alwaysAvailable"] = $propertyValue;
             } else {
                 if ($propertyName === "mainLanguageId") {
                     $contentInfoUpdateData["mainLanguageCode"] = $this->handler->contentLanguageHandler()->load($propertyValue)->languageCode;
                 } else {
                     $contentInfoUpdateData[$propertyName] = $propertyValue;
                 }
             }
         }
     }
     $this->backend->update('Content\\ContentInfo', $contentId, $contentInfoUpdateData, true);
     // Update VersionInfo with modified timestamp and published status
     $this->backend->updateByMatch('Content\\VersionInfo', array('_contentId' => $contentId, 'versionNo' => $versionNo), array("modificationDate" => $metaDataUpdateStruct->modificationDate, "status" => VersionInfo::STATUS_PUBLISHED));
     return $this->load($contentId, $versionNo);
 }
 /**
  * Changes main location of content identified by given $contentId to location identified by given $locationId
  *
  * @param mixed $contentId
  * @param mixed $locationId
  *
  * @return void
  */
 public function changeMainLocation($contentId, $locationId)
 {
     $location = $this->backend->load("Content\\Location", $locationId);
     $this->backend->update('Content\\ContentInfo', $contentId, array('mainLocationId' => $locationId));
     $parentLocation = $this->backend->load("Content\\Location", $location->parentId);
     $parentContent = $this->backend->load("Content\\ContentInfo", $parentLocation->contentId);
     $this->setSectionForSubtree($locationId, $parentContent->sectionId);
 }
 /**
  * Sets the object-state of a state group to $stateId for the given content.
  *
  * @param mixed $contentId
  * @param mixed $groupId
  * @param mixed $stateId
  *
  * @return boolean
  */
 public function setContentState($contentId, $groupId, $stateId)
 {
     $groupStateIds = $this->getGroupStateList($groupId);
     if (empty($groupStateIds) || !in_array($stateId, $groupStateIds)) {
         return false;
     }
     $contentToStateMap = $this->getContentToStateMap();
     if (isset($contentToStateMap[(int) $contentId])) {
         // If the content was in one of the group states,
         // find all content for the old state and update the old state with excluded $contentId
         $existingStateIds = array_values(array_intersect($groupStateIds, $contentToStateMap[(int) $contentId]));
         if (!empty($existingStateIds)) {
             $this->backend->update("Content\\ObjectState", $existingStateIds[0], array("_contentId" => array_values(array_diff($this->getObjectStateContentList($existingStateIds[0]), array($contentId)))));
         }
     }
     // Find all content for the new state and update the new state with added $contentId
     $newStateContentList = $this->getObjectStateContentList($stateId);
     $newStateContentList[] = $contentId;
     $this->backend->update("Content\\ObjectState", $stateId, array("_contentId" => $newStateContentList));
     return true;
 }
 /**
  * Un-assign a role
  *
  * @param mixed $contentId The user or user group Id to un-assign the role from.
  * @param mixed $roleId
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If group or role is not found
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If group is not of user[_group] Content Type
  * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue If group does not contain role
  */
 public function unAssignRole($contentId, $roleId)
 {
     $content = $this->backend->load('Content\\ContentInfo', $contentId);
     if (!$content) {
         throw new NotFound('User Group', $contentId);
     }
     $role = $this->backend->load('User\\Role', $roleId);
     if (!$role) {
         throw new NotFound('Role', $roleId);
     }
     // @todo Use eZ Publish settings for this, and maybe a better exception
     if ($content->contentTypeId != 3 && $content->contentTypeId != 4) {
         throw new NotFound("3 or 4", $contentId);
     }
     $roleAssignments = $this->backend->find('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId));
     if (empty($roleAssignments)) {
         throw new InvalidArgumentValue('$roleId', $roleId);
     }
     $this->backend->deleteByMatch('User\\RoleAssignment', array('roleId' => $roleId, 'contentId' => $contentId));
     $role->groupIds = array_values(array_diff($role->groupIds, array($contentId)));
     $this->backend->update('User\\Role', $roleId, (array) $role);
 }
 /**
  * Test updating content with a null value
  *
  * @covers eZ\Publish\Core\Persistence\InMemory\Backend::update
  * @group inMemoryBackend
  */
 public function testUpdateWithNullValue()
 {
     $this->assertTrue($this->backend->update("Content\\VersionInfo", 3, array("names" => null)));
     $versionInfo = $this->backend->load("Content\\VersionInfo", 3);
     $this->assertEquals(null, $versionInfo->names);
 }
 /**
  * @see eZ\Publish\SPI\Persistence\Content\Section\Handler
  */
 public function assign($sectionId, $contentId)
 {
     $this->backend->update('Content\\ContentInfo', $contentId, array('sectionId' => $sectionId), true);
 }
 /**
  * @param \eZ\Publish\SPI\Persistence\Content\Type\Group\UpdateStruct $group
  */
 public function updateGroup(GroupUpdateStruct $group)
 {
     $groupArr = (array) $group;
     $this->backend->update('Content\\Type\\Group', $groupArr['id'], $groupArr);
 }
 /**
  * Update language
  *
  * @param \eZ\Publish\SPI\Persistence\Content\Language $struct
  */
 public function update(Language $struct)
 {
     $this->backend->update('Content\\Language', $struct->id, (array) $struct);
 }
 /**
  * Test updating content with a wrong type.
  *
  * @param mixed $type Wrong type to update
  *
  * @expectedException eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
  * @dataProvider providerForWrongType
  * @covers eZ\Publish\Core\Persistence\InMemory\Backend::update
  */
 public function testUpdateWrongType($type)
 {
     $this->backend->update($type, 1, array());
 }