/** * (non-PHPdoc) * @see \oat\taoRevision\model\Repository::restore() */ public function restore(Revision $revision) { $lockManager = LockManager::getImplementation(); $resource = new \core_kernel_classes_Resource($revision->getResourceId()); if ($lockManager->isLocked($resource)) { $userId = \common_session_SessionManager::getSession()->getUser()->getIdentifier(); $lockManager->releaseLock($resource, $userId); } return $this->getInner()->restore($revision); }
/** * If you want strictly to check if the resource is locked, * you should use LockManager::getImplementation()->isLocked($resource) * Controller level convenience method to check if @resource is being locked, prepare data ans sets view, * * @param core_kernel_classes_Resource $resource * @param $view * * @return boolean */ protected function isLocked($resource, $view = null) { $lock = LockManager::getImplementation()->getLockData($resource); if (!is_null($lock) && $lock->getOwnerId() != common_session_SessionManager::getSession()->getUser()->getIdentifier()) { //if (LockManager::getImplementation()->isLocked($resource)) { $params = array('id' => $resource->getUri(), 'topclass-label' => $this->getRootClass()->getLabel()); if (!is_null($view)) { $params['view'] = $view; $params['ext'] = Context::getInstance()->getExtensionName(); } $this->forward('locked', 'Lock', 'tao', $params); } return false; }
/** * * @param core_kernel_classes_Resource $resource * @param string $oldVersion * @param string $message * @param string $newVersion * @return \oat\taoRevision\model\Revision */ public static function restore(core_kernel_classes_Resource $resource, $oldVersion, $message, $newVersion = null) { $lockManager = LockManager::getImplementation(); if ($lockManager->isLocked($resource)) { $userId = common_session_SessionManager::getSession()->getUser()->getIdentifier(); $lockManager->releaseLock($resource, $userId); } $oldRevision = RepositoryProxy::getRevision($resource->getUri(), $oldVersion); $success = RepositoryProxy::restore($oldRevision); if ($success) { $newVersion = is_null($newVersion) ? self::getNextVersion($resource->getUri()) : $newVersion; $newRevision = RevisionService::commit($resource, $message, $newVersion); return $newRevision; } else { throw \common_exception_Error('Unable to restore version ' . $oldVersion . ' of resource ' . $resource->getUri()); } }
public function forceRelease($uri) { $success = LockManager::getImplementation()->forceReleaseLock(new core_kernel_classes_Resource($uri)); return $this->returnJson(array('success' => $success)); }
/** * delete an item * @param core_kernel_classes_Resource $resource * @throws common_exception_Unauthorized * @return boolean */ public function deleteResource(core_kernel_classes_Resource $resource) { if (LockManager::getImplementation()->isLocked($resource)) { $userId = common_session_SessionManager::getSession()->getUser()->getIdentifier(); LockManager::getImplementation()->releaseLock($resource, $userId); } return $this->deleteItemContent($resource) && parent::deleteResource($resource); }
private static function hasWritePrivilege(User $user, $resourceId) { $resource = new \core_kernel_classes_Resource($resourceId); $lock = LockManager::getImplementation()->getLockData($resource); return is_null($lock) || $lock->getOwnerId() == $user->getIdentifier(); }
/** * Redirect the test's authoring * @requiresRight id WRITE */ public function authoring() { $test = new core_kernel_classes_Resource($this->getRequestParameter('id')); if (!$this->isLocked($test)) { $testModel = $this->service->getTestModel($test); if (!is_null($testModel)) { $testModelImpl = $this->service->getTestModelImplementation($testModel); $authoringUrl = $testModelImpl->getAuthoringUrl($test); if (!empty($authoringUrl)) { $userId = common_session_SessionManager::getSession()->getUser()->getIdentifier(); LockManager::getImplementation()->setLock($test, $userId); return $this->forwardUrl($authoringUrl); } } throw new common_exception_NoImplementation(); } }
/** * Item Authoring tool loader action * @requiresRight id WRITE */ public function authoring() { $item = new core_kernel_classes_Resource($this->getRequestParameter('id')); if (!$this->isLocked($item, 'item_locked.tpl')) { $this->setData('error', false); try { $itemModel = $this->getClassService()->getItemModel($item); if (!is_null($itemModel)) { $itemModelImpl = $this->getClassService()->getItemModelImplementation($itemModel); $authoringUrl = $itemModelImpl->getAuthoringUrl($item); if (!empty($authoringUrl)) { LockManager::getImplementation()->setLock($item, common_session_SessionManager::getSession()->getUser()->getIdentifier()); return $this->forwardUrl($authoringUrl); } } throw new common_exception_NoImplementation(); $this->setData('instanceUri', tao_helpers_Uri::encode($item->getUri(), false)); } catch (Exception $e) { $this->setData('error', true); //build clear error or warning message: if (!empty($itemModel) && $itemModel instanceof core_kernel_classes_Resource) { $errorMsg = __('No item authoring tool available for the selected type of item: %s' . $itemModel->getLabel()); } else { $errorMsg = __('No item type selected for the current item.') . " {$item->getLabel()} " . __('Please select first the item type!'); } $this->setData('errorMsg', $errorMsg); } } }
/** * delete an item * @param core_kernel_classes_Resource $resource * @throws common_exception_Unauthorized * @return boolean */ public function deleteResource(core_kernel_classes_Resource $resource) { if (LockManager::getImplementation()->isLocked($resource)) { $userId = common_session_SessionManager::getSession()->getUser()->getIdentifier(); LockManager::getImplementation()->releaseLock($resource, $userId); } $result = $this->deleteItemContent($resource) && parent::deleteResource($resource); if ($result) { $this->getEventManager()->trigger(new ItemRemovedEvent($resource->getUri())); } return $result; }