mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-23 21:20:28 +01:00
added work-in-progress organization folder occ commands
This commit is contained in:
parent
840fd70c37
commit
851fa0a1cc
5 changed files with 175 additions and 0 deletions
|
@ -19,6 +19,8 @@
|
|||
<nextcloud min-version="29" max-version="30"/>
|
||||
</dependencies>
|
||||
<commands>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolder\ListOrganizationFolders</command>
|
||||
<command>OCA\OrganizationFolders\Command\OrganizationFolder\CreateOrganizationFolder</command>
|
||||
<command>OCA\OrganizationFolders\Command\Resource\CreateResource</command>
|
||||
<command>OCA\OrganizationFolders\Command\Resource\ListResources</command>
|
||||
</commands>
|
||||
|
|
36
lib/Command/OrganizationFolder/CreateOrganizationFolder.php
Normal file
36
lib/Command/OrganizationFolder/CreateOrganizationFolder.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Command\OrganizationFolder;
|
||||
|
||||
use OCP\DB\Exception;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use OCA\OrganizationFolders\Command\BaseCommand;
|
||||
|
||||
class CreateOrganizationFolder extends BaseCommand {
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->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');
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$name = $input->getOption('name');
|
||||
$quota = $input->getOption('quota');
|
||||
|
||||
try {
|
||||
$organizationFolder = $this->organizationFolderService->create($name, $quota);
|
||||
|
||||
$output->writeln(json_encode($organizationFolder));
|
||||
return 0;
|
||||
} catch (Exception $e) {
|
||||
$output->writeln("<error>Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}</error>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
31
lib/Command/OrganizationFolder/ListOrganizationFolders.php
Normal file
31
lib/Command/OrganizationFolder/ListOrganizationFolders.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Command\OrganizationFolder;
|
||||
|
||||
use OCP\DB\Exception;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
use OCA\OrganizationFolders\Command\BaseCommand;
|
||||
|
||||
class ListOrganizationFolders extends BaseCommand {
|
||||
protected function configure(): void {
|
||||
$this
|
||||
->setName('organization-folders:list')
|
||||
->setDescription('List all organization folders');
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
try {
|
||||
$organizationFolderGroupfolders = $this->organizationFolderService->getAll();
|
||||
|
||||
$this->writeTableInOutputFormat($input, $output, $this->formatOrganizationFolders($organizationFolderGroupfolders));
|
||||
return 0;
|
||||
} catch (Exception $e) {
|
||||
$output->writeln("<error>Exception \"{$e->getMessage()}\" at {$e->getFile()} line {$e->getLine()}</error>");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
43
lib/Model/OrganizationFolder.php
Normal file
43
lib/Model/OrganizationFolder.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Model;
|
||||
|
||||
use \JsonSerializable;
|
||||
use OCA\OrganizationFolders\Interface\TableSerializable;
|
||||
|
||||
class OrganizationFolder implements JsonSerializable, TableSerializable {
|
||||
public function __construct(
|
||||
private int $id,
|
||||
private string $name,
|
||||
private int $quota,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getId(): int {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function getQuota(): int {
|
||||
return $this->quota;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'quota' => $this->quota,
|
||||
];
|
||||
}
|
||||
|
||||
public function tableSerialize(): array {
|
||||
return [
|
||||
'Id' => $this->id,
|
||||
'Name' => $this->name,
|
||||
'Quota' => $this->quota,
|
||||
];
|
||||
}
|
||||
}
|
63
lib/Service/OrganizationFolderService.php
Normal file
63
lib/Service/OrganizationFolderService.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\OrganizationFolders\Service;
|
||||
|
||||
use OCP\AppFramework\Db\TTransactional;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
use OCA\GroupFolders\Folder\FolderManager;
|
||||
use OCA\GroupfolderTags\Service\TagService;
|
||||
|
||||
use OCA\OrganizationFolders\Model\OrganizationFolder;
|
||||
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
|
||||
|
||||
class OrganizationFolderService {
|
||||
use TTransactional;
|
||||
|
||||
public function __construct(
|
||||
private IDBConnection $db,
|
||||
private FolderManager $folderManager,
|
||||
private TagService $tagService,
|
||||
private OrganizationProviderManager $organizationProviderManager,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getAll() {
|
||||
$result = [];
|
||||
|
||||
$tags = $this->tagService->findAllIncludingGroupfolder("organization_folder");
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
$result[] = new OrganizationFolder($tag["group_folder_id"], $tag["mount_point"], $tag["quota"]);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function create(string $name, int $quota, ?string $organizationProvider = null,?int $organizationId = null) {
|
||||
$this->atomic(function () use ($name, $quota) {
|
||||
$groupfolderId = $this->folderManager->createFolder($name);
|
||||
$this->folderManager->setFolderQuota($groupfolderId, $quota);
|
||||
$this->folderManager->setFolderACL($groupfolderId, true);
|
||||
|
||||
$this->tagService->update($groupfolderId, "organization_folder");
|
||||
|
||||
if(isset($organizationProvider) && $this->organizationProviderManager->hasOrganizationProvider($organizationProvider) && isset($organizationId)) {
|
||||
$organization = $this->organizationProviderManager->getOrganizationProvider($organizationProvider)->getOrganization($organizationId);
|
||||
|
||||
$this->tagService->update($groupfolderId, "organization_provider", $organizationProvider);
|
||||
$this->tagService->update($groupfolderId, "organization_id", $organization->getId());
|
||||
}
|
||||
|
||||
// TODO: return Model object
|
||||
|
||||
}, $this->db);
|
||||
}
|
||||
|
||||
public function applyPermissions(int $id) {
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue