0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-11-21 20:28:11 +01:00

reference organization folder by id not groupfolder id (same id, different nomenclature)

This commit is contained in:
Jonathan Treffler 2024-10-30 01:49:41 +01:00
parent efca199c7f
commit 949e1a42d1
5 changed files with 15 additions and 11 deletions

View file

@ -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,

View file

@ -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');

View file

@ -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'));

View file

@ -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)) {

View file

@ -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,