mirror of
https://github.com/verdigado/organization_folders.git
synced 2024-11-23 21:20:28 +01:00
improved organization folder service: added function to find by id, return model entity after creation, added function to remove
This commit is contained in:
parent
79a1c1e9f3
commit
9487ddc910
3 changed files with 45 additions and 5 deletions
9
lib/Errors/OrganizationFolderNotFound.php
Normal file
9
lib/Errors/OrganizationFolderNotFound.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\OrganizationFolders\Errors;
|
||||
|
||||
class OrganizationFolderNotFound extends NotFoundException {
|
||||
public function __construct($id) {
|
||||
parent::__construct(\OCA\OrganizationFolders\Model\OrganizationFolder::class, ["id" => $id]);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,6 @@ namespace OCA\OrganizationFolders\Errors;
|
|||
|
||||
class OrganizationNotFound extends NotFoundException {
|
||||
public function __construct($provider, $id) {
|
||||
parent::__construct(OCA\OrganizationFolders\Model\Organization::class, ["provider" => $provider, "id" => $id]);
|
||||
parent::__construct(\OCA\OrganizationFolders\Model\Organization::class, ["provider" => $provider, "id" => $id]);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ use OCP\IDBConnection;
|
|||
use OCA\GroupFolders\Folder\FolderManager;
|
||||
use OCA\GroupfolderTags\Service\TagService;
|
||||
|
||||
use OCA\OrganizationFolders\Errors\OrganizationFolderNotFound;
|
||||
use OCA\OrganizationFolders\Model\OrganizationFolder;
|
||||
use OCA\OrganizationFolders\OrganizationProvider\OrganizationProviderManager;
|
||||
|
||||
|
@ -44,8 +45,26 @@ class OrganizationFolderService {
|
|||
return $result;
|
||||
}
|
||||
|
||||
public function create(string $name, int $quota, ?string $organizationProvider = null,?int $organizationId = null) {
|
||||
$this->atomic(function () use ($name, $quota) {
|
||||
public function find(int $id): OrganizationFolder {
|
||||
$groupfolder = $this->tagService->findGroupfolderWithTags($id,[
|
||||
["key" => "organization_folder"],
|
||||
], ["organization_provider", "organization_id"]);
|
||||
|
||||
if(is_null($groupfolder)) {
|
||||
throw new OrganizationFolderNotFound($id);
|
||||
}
|
||||
|
||||
return new OrganizationFolder(
|
||||
id: $groupfolder["id"],
|
||||
name: $groupfolder["mount_point"],
|
||||
quota: $groupfolder["quota"],
|
||||
organizationProvider: $groupfolder["organization_provider"],
|
||||
organizationId: $groupfolder["organization_id"],
|
||||
);
|
||||
}
|
||||
|
||||
public function create(string $name, int $quota, ?string $organizationProvider = null,?int $organizationId = null): OrganizationFolder {
|
||||
return $this->atomic(function () use ($name, $quota, $organizationProvider, $organizationId) {
|
||||
$groupfolderId = $this->folderManager->createFolder($name);
|
||||
$this->folderManager->setFolderQuota($groupfolderId, $quota);
|
||||
$this->folderManager->setFolderACL($groupfolderId, true);
|
||||
|
@ -58,9 +77,16 @@ class OrganizationFolderService {
|
|||
$this->tagService->update($groupfolderId, "organization_provider", $organizationProvider);
|
||||
$this->tagService->update($groupfolderId, "organization_id", $organization->getId());
|
||||
}
|
||||
|
||||
// TODO: return Model object
|
||||
|
||||
$organizationFolder = new OrganizationFolder(
|
||||
id: $groupfolderId,
|
||||
name: $name,
|
||||
quota: $quota,
|
||||
organizationProvider: $organizationProvider,
|
||||
organizationId: $organizationId,
|
||||
);
|
||||
|
||||
return $organizationFolder;
|
||||
}, $this->db);
|
||||
}
|
||||
|
||||
|
@ -68,4 +94,9 @@ class OrganizationFolderService {
|
|||
|
||||
}
|
||||
|
||||
public function remove($id): void {
|
||||
$organizationFolder = $this->find($id);
|
||||
$this->folderManager->removeFolder($organizationFolder->getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue