diff --git a/lib/Db/FolderResource.php b/lib/Db/FolderResource.php index fdb8307..0007bbf 100644 --- a/lib/Db/FolderResource.php +++ b/lib/Db/FolderResource.php @@ -19,7 +19,7 @@ class FolderResource extends Resource { $instance->setId($row["id"]); $instance->setParentResource($row["parent_resource"]); - $instance->setGroupFolderId($row["group_folder_id"]); + $instance->setOrganizationFolderId($row["organization_folder_id"]); $instance->setName($row["name"]); $instance->setActive($row["active"]); $instance->setLastUpdatedTimestamp($row["last_updated_timestamp"]); @@ -36,7 +36,7 @@ class FolderResource extends Resource { return [ 'id' => $this->id, 'parentResource' => $this->parentResource, - 'groupFolderId' => $this->groupFolderId, + 'organizationFolderId' => $this->organizationFolderId, 'type' => "folder", 'name' => $this->name, 'active' => $this->active, diff --git a/lib/Db/Resource.php b/lib/Db/Resource.php index 47afbff..8bd3bce 100644 --- a/lib/Db/Resource.php +++ b/lib/Db/Resource.php @@ -7,14 +7,14 @@ use JsonSerializable; use OCP\AppFramework\Db\Entity; abstract class Resource extends Entity implements JsonSerializable { - protected $groupFolderId; + protected $organizationFolderId; protected $parentResource; protected $name; protected $active; protected $lastUpdatedTimestamp; public function __construct() { - $this->addType('groupFolderId','integer'); + $this->addType('organizationFolderId','integer'); $this->addType('parentResource','integer'); $this->addType('active','bool'); $this->addType('lastUpdatedTimestamp','integer'); diff --git a/lib/Db/ResourceMapper.php b/lib/Db/ResourceMapper.php index af49321..a21be76 100644 --- a/lib/Db/ResourceMapper.php +++ b/lib/Db/ResourceMapper.php @@ -52,17 +52,17 @@ class ResourceMapper extends QBMapper { } /** - * @param int $groupfolderId + * @param int $organizationFolderId * @param int $parentResourceId * @return array */ - public function findAll(int $groupfolderId, ?int $parentResourceId = null): array { + public function findAll(int $organizationFolderId, ?int $parentResourceId = null): array { /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->select('resource.*', 'folder.members_acl_permission', 'folder.managers_acl_permission', 'folder.inherited_acl_permission') ->from(self::RESOURCES_TABLE, "resource") - ->where($qb->expr()->eq('group_folder_id', $qb->createNamedParameter($groupfolderId, IQueryBuilder::PARAM_INT))); + ->where($qb->expr()->eq('organization_folder_id', $qb->createNamedParameter($organizationFolderId, IQueryBuilder::PARAM_INT))); if(is_null($parentResourceId)) { $qb->andWhere($qb->expr()->isNull('parent_resource')); diff --git a/lib/Migration/Version000000Date20241014120000.php b/lib/Migration/Version000000Date20241014120000.php index 8f327bf..0d18385 100644 --- a/lib/Migration/Version000000Date20241014120000.php +++ b/lib/Migration/Version000000Date20241014120000.php @@ -34,7 +34,7 @@ class Version000000Date20241014120000 extends SimpleMigrationStep { $table->addColumn('parent_resource', Types::INTEGER, [ 'notnull' => false, ]); - $table->addColumn('group_folder_id', Types::BIGINT, [ + $table->addColumn('organization_folder_id', Types::BIGINT, [ 'length' => 20, 'notnull' => true, ]); @@ -62,10 +62,14 @@ class Version000000Date20241014120000 extends SimpleMigrationStep { 'organizationfolders_resources_parent_resource_id_fk'); $table->addForeignKeyConstraint( $schema->getTable(self::GROUP_FOLDERS_TABLE), - ['group_folder_id'], + ['organization_folder_id'], ['folder_id'], ['onDelete' => 'CASCADE'], - 'organizationfolders_resources_group_folder_id_fk'); + 'organizationfolders_resources_organization_folder_id_fk'); + + // WARNING: CONSTRAINT CURRENTLY DOES NOT WORK FOR TOP LEVEL RESOURCES, AS ROWS WITH A NULL IN ONE OF THE UNIQUE COLUMNS WILL NOT BE CHECKED BY THIS + // TODO: use NULLS NOT DISTINCT (postgres supported only) + $table->addUniqueConstraint(['organization_folder_id', 'parent_resource', 'name'], "organizationfolders_resources_name_unique"); } if (!$schema->hasTable(self::FOLDER_RESOURCES_TABLE)) { diff --git a/lib/Service/ResourceService.php b/lib/Service/ResourceService.php index 71d92cb..dce805d 100644 --- a/lib/Service/ResourceService.php +++ b/lib/Service/ResourceService.php @@ -39,7 +39,7 @@ class ResourceService { /* Use named arguments to call this function */ public function create( string $type, - int $groupFolderId, + int $organizationFolderId, ?int $parentResource = null, bool $active = true,