diff --git a/appinfo/info.xml b/appinfo/info.xml index c6baa37..463e736 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -22,6 +22,7 @@ OCA\OrganizationFolders\Command\OrganizationFolder\GetOrganizationFolder OCA\OrganizationFolders\Command\OrganizationFolder\ListOrganizationFolders OCA\OrganizationFolders\Command\OrganizationFolder\CreateOrganizationFolder + OCA\OrganizationFolders\Command\OrganizationFolder\UpdateOrganizationFolder OCA\OrganizationFolders\Command\OrganizationFolder\RemoveOrganizationFolder OCA\OrganizationFolders\Command\Resource\CreateResource OCA\OrganizationFolders\Command\Resource\ListResources diff --git a/lib/Command/OrganizationFolder/CreateOrganizationFolder.php b/lib/Command/OrganizationFolder/CreateOrganizationFolder.php index 9ae0399..5f89f07 100644 --- a/lib/Command/OrganizationFolder/CreateOrganizationFolder.php +++ b/lib/Command/OrganizationFolder/CreateOrganizationFolder.php @@ -15,16 +15,25 @@ class CreateOrganizationFolder extends BaseCommand { ->setName('organization-folders:create') ->setDescription('Create a new organization folder') ->addOption('name', null, InputOption::VALUE_REQUIRED, 'Name of the new organization folder') - ->addOption('quota', null, InputOption::VALUE_REQUIRED, 'Storage Quota of the new organization folder'); + ->addOption('quota', null, InputOption::VALUE_REQUIRED, 'Storage Quota of the new organization folder') + ->addOption('organization-provider', null, InputOption::VALUE_OPTIONAL, 'Organization provider of the organization this folder is part of') + ->addOption('organization-id', null, InputOption::VALUE_OPTIONAL, 'Organization id of the organization this folder is part of'); parent::configure(); } protected function execute(InputInterface $input, OutputInterface $output): int { $name = $input->getOption('name'); $quota = $input->getOption('quota'); + $organizationProviderId = $input->getOption('organization-provider'); + $organizationId = $input->getOption('organization-id'); try { - $organizationFolder = $this->organizationFolderService->create($name, $quota); + $organizationFolder = $this->organizationFolderService->create( + name: $name, + quota: $quota, + organizationProvider: $organizationProviderId, + organizationId: $organizationId, + ); $this->writeTableInOutputFormat($input, $output, [$this->formatTableSerializable($organizationFolder)]); return 0; diff --git a/lib/Command/OrganizationFolder/UpdateOrganizationFolder.php b/lib/Command/OrganizationFolder/UpdateOrganizationFolder.php new file mode 100644 index 0000000..826d458 --- /dev/null +++ b/lib/Command/OrganizationFolder/UpdateOrganizationFolder.php @@ -0,0 +1,52 @@ +setName('organization-folders:update') + ->setDescription('Update a organization folder') + ->addArgument('id', InputArgument::REQUIRED, 'Id of the organization folder to update') + ->addOption('name', null, InputOption::VALUE_OPTIONAL, 'New name of the organization folder') + ->addOption('quota', null, InputOption::VALUE_OPTIONAL, 'New storage quota of the organization folder') + ->addOption('organization-provider', null, InputOption::VALUE_OPTIONAL, 'New organization provider of the organization this folder will be part of') + ->addOption('organization-id', null, InputOption::VALUE_OPTIONAL, 'New Organization id of the organization this folder will be part of'); + parent::configure(); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + $id = (int)$input->getArgument('id'); + $name = $input->getOption('name'); + $quota = $input->getOption('quota'); + $organizationProviderId = $input->getOption('organization-provider'); + + if(ctype_digit($input->getOption('organization-id'))) { + $organizationId = (int)$input->getOption('organization-id'); + } + + try { + $organizationFolder = $this->organizationFolderService->update( + id: $id, + name: $name, + quota: $quota, + organizationProviderId: $organizationProviderId, + organizationId: $organizationId, + ); + + $this->writeTableInOutputFormat($input, $output, [$this->formatTableSerializable($organizationFolder)]); + return 0; + } catch (Exception $e) { + $output->writeln("Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}"); + return 1; + } + } +} diff --git a/lib/Service/OrganizationFolderService.php b/lib/Service/OrganizationFolderService.php index 9c3f87b..e691fde 100644 --- a/lib/Service/OrganizationFolderService.php +++ b/lib/Service/OrganizationFolderService.php @@ -75,7 +75,7 @@ class OrganizationFolderService { $organization = $this->organizationProviderManager->getOrganizationProvider($organizationProvider)->getOrganization($organizationId); $this->tagService->update($groupfolderId, "organization_provider", $organizationProvider); - $this->tagService->update($groupfolderId, "organization_id", $organization->getId()); + $this->tagService->update($groupfolderId, "organization_id", (string)$organization->getId()); } $organizationFolder = new OrganizationFolder( @@ -90,6 +90,47 @@ class OrganizationFolderService { }, $this->db); } + public function update( + int $id, + ?string $name = null, + ?int $quota = null, + ?string $organizationProviderId = null, + ?int $organizationId = null + ): OrganizationFolder { + return $this->atomic(function () use ($id, $name, $quota, $organizationProviderId, $organizationId) { + if(isset($name)) { + $this->folderManager->renameFolder($id, $name); + } + + if(isset($quota)) { + $this->folderManager->setFolderQuota($id, $quota); + } + + if(isset($organizationProviderId) || isset($organizationId)) { + if(!isset($organizationProviderId)) { + $organizationProviderId = $this->tagService->find($id, "organization_provider")->getTagValue(); + } + + if(!$this->organizationProviderManager->hasOrganizationProvider($organizationProviderId)) { + throw new \Exception("organization provider not found"); + } + + $organizationProvider = $this->organizationProviderManager->getOrganizationProvider($organizationProviderId); + + if(!isset($organizationId)) { + $organizationId = (int)$this->tagService->find($id, "organization_id")->getTagValue(); + } + + $organization = $organizationProvider->getOrganization($organizationId); + + $this->tagService->update($id, "organization_provider", $organizationProviderId); + $this->tagService->update($id, "organization_id", (string)$organization->getId()); + } + + return $this->find($id); + }, $this->db); + } + public function applyPermissions(int $id) { }