Ejemplo n.º 1
0
 public function testRemoveApplicable()
 {
     $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
     $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
     $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
     $mount = $this->dbConfig->getMountById($id);
     $this->assertEquals([], $mount['applicable']);
 }
Ejemplo n.º 2
0
 public function testRemoveApplicableGlobal()
 {
     $id = $this->addMount('/test', 'foo', 'bar', 100, DBConfigService::MOUNT_TYPE_ADMIN);
     $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
     $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
     $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, 'test');
     $mount = $this->dbConfig->getMountById($id);
     $this->assertEquals([['type' => DBConfigService::APPLICABLE_TYPE_USER, 'value' => 'test', 'mount_id' => $id]], $mount['applicable']);
 }
Ejemplo n.º 3
0
 /**
  * Update storage to the configuration
  *
  * @param StorageConfig $updatedStorage storage attributes
  *
  * @return StorageConfig storage config
  * @throws NotFoundException if the given storage does not exist in the config
  */
 public function updateStorage(StorageConfig $updatedStorage)
 {
     $id = $updatedStorage->getId();
     $existingMount = $this->dbConfig->getMountById($id);
     if (!is_array($existingMount)) {
         throw new NotFoundException('Storage with id "' . $id . '" not found while updating storage');
     }
     $oldStorage = $this->getStorageConfigFromDBMount($existingMount);
     $removedUsers = array_diff($oldStorage->getApplicableUsers(), $updatedStorage->getApplicableUsers());
     $removedGroups = array_diff($oldStorage->getApplicableGroups(), $updatedStorage->getApplicableGroups());
     $addedUsers = array_diff($updatedStorage->getApplicableUsers(), $oldStorage->getApplicableUsers());
     $addedGroups = array_diff($updatedStorage->getApplicableGroups(), $oldStorage->getApplicableGroups());
     $oldUserCount = count($oldStorage->getApplicableUsers());
     $oldGroupCount = count($oldStorage->getApplicableGroups());
     $newUserCount = count($oldStorage->getApplicableUsers());
     $newGroupCount = count($oldStorage->getApplicableGroups());
     $wasGlobal = $oldUserCount + $oldGroupCount === 0;
     $isGlobal = $newUserCount + $newGroupCount === 0;
     foreach ($removedUsers as $user) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
     }
     foreach ($removedGroups as $group) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
     }
     foreach ($addedUsers as $user) {
         $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_USER, $user);
     }
     foreach ($addedGroups as $group) {
         $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GROUP, $group);
     }
     if ($wasGlobal && !$isGlobal) {
         $this->dbConfig->removeApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
     } else {
         if (!$wasGlobal && $isGlobal) {
             $this->dbConfig->addApplicable($id, DBConfigService::APPLICABLE_TYPE_GLOBAL, null);
         }
     }
     $changedConfig = array_diff_assoc($updatedStorage->getBackendOptions(), $oldStorage->getBackendOptions());
     $changedOptions = array_diff_assoc($updatedStorage->getMountOptions(), $oldStorage->getMountOptions());
     foreach ($changedConfig as $key => $value) {
         $this->dbConfig->setConfig($id, $key, $value);
     }
     foreach ($changedOptions as $key => $value) {
         $this->dbConfig->setOption($id, $key, $value);
     }
     if ($updatedStorage->getMountPoint() !== $oldStorage->getMountPoint()) {
         $this->dbConfig->setMountPoint($id, $updatedStorage->getMountPoint());
     }
     if ($updatedStorage->getAuthMechanism()->getIdentifier() !== $oldStorage->getAuthMechanism()->getIdentifier()) {
         $this->dbConfig->setAuthBackend($id, $updatedStorage->getAuthMechanism()->getIdentifier());
     }
     $this->triggerChangeHooks($oldStorage, $updatedStorage);
     return $this->getStorage($id);
 }