コード例 #1
0
 public function updateShareInfo(AbstractEyeosPrincipal $currentOwner, array $partialShareInfo)
 {
     try {
         $partialShareInfo['old_' . SharingManager::SHAREINFO_KEY_OWNERID] = $currentOwner->getId();
         $dbHandler = $this->getConnection($currentOwner->getName());
         //this array contains the columns names of which values are not updatable
         $fixedColumns = array(SharingManager::SHAREINFO_KEY_SHAREABLEID => '', SharingManager::SHAREINFO_KEY_COLLABORATORID => '', SharingManager::SHAREINFO_KEY_HANDLERCLASSNAME => '');
         //in the following $variableColumns array, only the editable columns are present
         $variableColumns = array_diff_key($partialShareInfo, $fixedColumns);
         $sqlQuery = 'UPDATE ' . self::SHAREINFO_TABLE_NAME . ' SET ';
         $i = 0;
         foreach ($variableColumns as $key => $value) {
             if ($key != 'old_' . SharingManager::SHAREINFO_KEY_OWNERID) {
                 $sqlQuery .= $key . ' = :' . $key . ', ';
             }
         }
         $sqlQuery = substr($sqlQuery, 0, -2);
         $sqlQuery .= ' WHERE ' . SharingManager::SHAREINFO_KEY_OWNERID . ' = :old_' . SharingManager::SHAREINFO_KEY_OWNERID . ' AND ' . SharingManager::SHAREINFO_KEY_SHAREABLEID . ' = :' . SharingManager::SHAREINFO_KEY_SHAREABLEID . ' AND ' . SharingManager::SHAREINFO_KEY_HANDLERCLASSNAME . ' = :' . SharingManager::SHAREINFO_KEY_HANDLERCLASSNAME;
         if (isset($partialShareInfo[SharingManager::SHAREINFO_KEY_COLLABORATORID])) {
             $sqlQuery .= ' AND ' . SharingManager::SHAREINFO_KEY_COLLABORATORID . ' = :' . SharingManager::SHAREINFO_KEY_COLLABORATORID;
         }
         $stmt = $dbHandler->prepare($sqlQuery);
         $stmt->execute($partialShareInfo);
         //in case we updated the owner, reverse the relation owner/collaborator if it exists (the former owner becomes a collaborator)
         if ($currentOwner->getId() != $partialShareInfo[SharingManager::SHAREINFO_KEY_OWNERID]) {
             $partialShareInfo[SharingManager::SHAREINFO_KEY_COLLABORATORID] = $partialShareInfo[SharingManager::SHAREINFO_KEY_OWNERID];
             $sqlQuery = 'UPDATE ' . self::SHAREINFO_TABLE_NAME . ' SET ' . SharingManager::SHAREINFO_KEY_COLLABORATORID . ' = :old_' . SharingManager::SHAREINFO_KEY_OWNERID;
             $sqlQuery .= ' WHERE ' . SharingManager::SHAREINFO_KEY_OWNERID . ' = :' . SharingManager::SHAREINFO_KEY_OWNERID . ' AND ' . SharingManager::SHAREINFO_KEY_SHAREABLEID . ' = :' . SharingManager::SHAREINFO_KEY_SHAREABLEID . ' AND ' . SharingManager::SHAREINFO_KEY_COLLABORATORID . ' = :' . SharingManager::SHAREINFO_KEY_COLLABORATORID . ' AND ' . SharingManager::SHAREINFO_KEY_HANDLERCLASSNAME . ' = :' . SharingManager::SHAREINFO_KEY_HANDLERCLASSNAME;
             $stmt = $dbHandler->prepare($sqlQuery);
             $stmt->execute($partialShareInfo);
         }
     } catch (PDOException $e) {
         $this->destroyConnection();
         throw new EyeDBException('An error occured while attempting to update share info data.', 0, $e);
     }
     $this->destroyConnection();
 }
コード例 #2
0
 public function updateCollaboratorPermission(IShareable $object, AbstractEyeosPrincipal $collaborator, IPermission $permission)
 {
     try {
         if ($object->getId() === null) {
             throw new EyeNullPointerException('$object ID cannot be null.');
         }
         $handlerClassName = null;
         foreach (self::getAllShareableObjectsHandlers() as $handler) {
             if ($handler->checkType($object)) {
                 $handlerClassName = get_class($handler);
                 break;
             }
         }
         if ($handlerClassName === null) {
             throw new EyeHandlerNotFoundException('Unable to find a ShareableObjectHandler for object of class ' . get_class($object) . '.');
         }
         $owner = $object->getShareOwner();
         SecurityManager::getInstance()->checkPermission($object, new SharePermission(array('updatecollaborator'), $collaborator));
         //prepare query array
         $shareInfoQuery = array(self::SHAREINFO_KEY_OWNERID => $owner->getId(), self::SHAREINFO_KEY_SHAREABLEID => $object->getId(), self::SHAREINFO_KEY_COLLABORATORID => $collaborator->getId(), self::SHAREINFO_KEY_PERMISSIONACTIONS => $permission->getActionsAsString(), self::SHAREINFO_KEY_HANDLERCLASSNAME => $handlerClassName);
         $this->getProvider()->updateShareInfo($owner, $shareInfoQuery);
         // TODO: we could also add the ShareInfo object containing the old permission as a
         // "related source" of the event
         $event = new SharingEvent(new BasicShareInfo($owner, $object, $collaborator, $permission, $handlerClassName));
         foreach ($this->listeners as $listener) {
             $listener->collaboratorPermissionUpdated($event);
         }
     } catch (Exception $e) {
         self::$Logger->warn('Unable to update collaborator ' . $collaborator->getName() . ' permissions for object of class ' . get_class($object) . '.');
         if (self::$Logger->isDebugEnabled()) {
             self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false));
         }
         throw $e;
     }
 }