/**
  * Update object state links from $oldStateId to $newStateId.
  *
  * @param int $oldStateId
  * @param int $newStateId
  */
 public function updateObjectStateLinks($oldStateId, $newStateId)
 {
     try {
         return $this->innerGateway->updateObjectStateLinks($oldStateId, $newStateId);
     } catch (DBALException $e) {
         throw new RuntimeException('Database error', 0, $e);
     } catch (PDOException $e) {
         throw new RuntimeException('Database error', 0, $e);
     }
 }
 /**
  * Deletes a object state. The state of the content objects is reset to the
  * first object state in the group.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If state with $stateId doesn't exist
  *
  * @param mixed $stateId
  */
 public function delete($stateId)
 {
     // Get the object state first as we need group ID
     // to reorder the priorities and reassign content to another state in the group
     $objectState = $this->load($stateId);
     $this->objectStateGateway->deleteObjectState($objectState->id);
     $remainingStates = $this->loadObjectStates($objectState->groupId);
     if (empty($remainingStates)) {
         // If there are no more states in the group, just remove the state links
         $this->objectStateGateway->deleteObjectStateLinks($objectState->id);
         return;
     }
     $priority = 0;
     foreach ($remainingStates as $remainingState) {
         $this->objectStateGateway->updateObjectStatePriority($remainingState->id, $priority);
         $priority++;
     }
     $remainingStates = $this->loadObjectStates($objectState->groupId);
     $this->objectStateGateway->updateObjectStateLinks($objectState->id, current($remainingStates)->id);
 }