public function lockResource($userId, $resourceName)
    {
        $resource = $this->lockedResourceRepository->fromResourceNameByUser($userId, $resourceName);
        if (null === $resource) {
            if ( ! $this->isResourceFree($resourceName)) {
                throw new ResourceNotFreeException('exception_resource_locked');
            }

            $resourceClass = $this->lockedResourceRepository->getRepositoryObjectClassName();
            $resource = new $resourceClass();
            $values = array(
                'ResourceName' => $resourceName,
                'UserId' => $userId,
                'CreatedAt' => time(),
                'UpdatedAt' => time(),
            );
        } else {
            $values = array(
                'UpdatedAt' => time(),
            );
        }

        $result = $this->lockedResourceRepository
                       ->setRepositoryObject($resource)
                       ->save($values);
        if (false === $result) {
            throw new RuntimeException('exception_resource_locking_error');
        }
    }
public function lockResource($userId, $resourceName)
    {
        $resource = $this->lockedResourceRepository->fromResourceNameByUser($userId, $resourceName);
        if (null === $resource) {
            if ( ! $this->isResourceFree($resourceName)) {
                throw new ResourceNotFreeException('exception_resource_locked');
            }

            $resourceClass = $this->lockedResourceRepository->getRepositoryObjectClassName();
            $resource = new $resourceClass();
            $values = array(
                'ResourceName' => $resourceName,
                'UserId' => $userId,
                'CreatedAt' => time(),
                'UpdatedAt' => time(),
            );
        } else {
            $values = array(
                'UpdatedAt' => time(),
            );
        }

        $result = $this->lockedResourceRepository
                       ->setRepositoryObject($resource)
                       ->save($values);
        if (false === $result) {
            throw new RuntimeException('exception_resource_locking_error');
        }
    }
public function lockResource ( $ userId , $ resourceName ) { $ resource = $ this -> lockedResourceRepository -> fromResourceNameByUser ( $ userId , $ resourceName ) ; if ( null === $ resource ) { if ( ! $ this -> isResourceFree ( $ resourceName ) ) { throw new ResourceNotFreeException ( 'exception_resource_locked' ) ; } $ resourceClass = $ this -> lockedResourceRepository -> getRepositoryObjectClassName ( ) ; $ resource = new $ resourceClass ( ) ; $ values = array ( 'ResourceName' => $ resourceName , 'UserId' => $ userId , 'CreatedAt' => time ( ) , 'UpdatedAt' => time ( ) , ) ; } else { $ values = array ( 'UpdatedAt' => time ( ) , ) ; } $ result = $ this -> lockedResourceRepository -> setRepositoryObject ( $ resource ) -> save ( $ values ) ; if ( false === $ result ) { throw new RuntimeException ( 'exception_resource_locking_error' ) ; } }
Locks a resource for the current user when it is free or updates the expiring
time when it is locked by the same user

@param  int                      $userId
@param  string                   $resourceName
@throws ResourceNotFreeException
@throws \RuntimeException

@api
Locks a resource for the current user when it is free or updates the expiring time when it is locked by the same user