Partage d'export enregistré et génération asynchrone des exports

This commit is contained in:
2025-07-08 13:53:25 +00:00
parent c4cc0baa8e
commit 8bc16dadb0
447 changed files with 14134 additions and 3854 deletions

View File

@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250219130532 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add a table for storing export generation';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_main_export_generation (id UUID NOT NULL, deleteAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, exportAlias TEXT DEFAULT \'\' NOT NULL, options JSON DEFAULT \'[]\' NOT NULL, createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL, storedObject_id INT NOT NULL, createdBy_id INT DEFAULT NULL, PRIMARY KEY(id))');
$this->addSql('CREATE INDEX IDX_E644B77D6C99C13A ON chill_main_export_generation (storedObject_id)');
$this->addSql('CREATE INDEX IDX_E644B77D3174800F ON chill_main_export_generation (createdBy_id)');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.id IS \'(DC2Type:uuid)\'');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.deleteAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.createdAt IS \'(DC2Type:datetime_immutable)\'');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D6C99C13A FOREIGN KEY (storedObject_id) REFERENCES chill_doc.stored_object (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77D3174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('DROP TABLE chill_main_export_generation');
}
}

View File

@@ -0,0 +1,38 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250313165611 extends AbstractMigration
{
public function getDescription(): string
{
return 'Associate an export generation with eventual saved export';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_export_generation ADD savedExport_id UUID DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN chill_main_export_generation.savedExport_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77DA61D6F69 FOREIGN KEY (savedExport_id) REFERENCES chill_main_saved_export (id) NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('CREATE INDEX IDX_E644B77DA61D6F69 ON chill_main_export_generation (savedExport_id)');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_export_generation DROP CONSTRAINT FK_E644B77DA61D6F69');
$this->addSql('DROP INDEX IDX_E644B77DA61D6F69');
$this->addSql('ALTER TABLE chill_main_export_generation DROP savedExport_id');
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Chill\MainBundle\Export\Migrator\SavedExportOptionsMigrator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
final class Version20250404123326 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update option representation of saved exports';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_saved_export ADD COLUMN options_backup JSONB default \'[]\'');
$this->addSql('UPDATE chill_main_saved_export SET options_backup = options');
$result = $this->connection->executeQuery('SELECT id, options FROM chill_main_saved_export');
foreach ($result->iterateAssociative() as $row) {
$options = json_decode((string) $row['options'], true, 512, JSON_THROW_ON_ERROR);
$this->addSql(
'UPDATE chill_main_saved_export SET options = :new_options WHERE id = :id',
['id' => $row['id'], 'new_options' => SavedExportOptionsMigrator::migrate($options)],
['id' => Types::STRING, 'new_options' => Types::JSON],
);
}
}
public function down(Schema $schema): void
{
$this->addSql('UPDATE chill_main_saved_export SET options = options_backup');
$this->addSql('ALTER TABLE chill_main_saved_export DROP COLUMN options_backup');
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250410145342 extends AbstractMigration
{
public function getDescription(): string
{
return 'share saved_exports with users and groups';
}
public function up(Schema $schema): void
{
$this->addSql('CREATE TABLE chill_main_saved_export_users (savedexport_id UUID NOT NULL, user_id INT NOT NULL, PRIMARY KEY(savedexport_id, user_id))');
$this->addSql('CREATE INDEX IDX_4A2B71EC24ECEDCA ON chill_main_saved_export_users (savedexport_id)');
$this->addSql('CREATE INDEX IDX_4A2B71ECA76ED395 ON chill_main_saved_export_users (user_id)');
$this->addSql('COMMENT ON COLUMN chill_main_saved_export_users.savedexport_id IS \'(DC2Type:uuid)\'');
$this->addSql('CREATE TABLE chill_main_saved_export_usergroups (savedexport_id UUID NOT NULL, usergroup_id INT NOT NULL, PRIMARY KEY(savedexport_id, usergroup_id))');
$this->addSql('CREATE INDEX IDX_A12F30824ECEDCA ON chill_main_saved_export_usergroups (savedexport_id)');
$this->addSql('CREATE INDEX IDX_A12F308D2112630 ON chill_main_saved_export_usergroups (usergroup_id)');
$this->addSql('COMMENT ON COLUMN chill_main_saved_export_usergroups.savedexport_id IS \'(DC2Type:uuid)\'');
$this->addSql('ALTER TABLE chill_main_saved_export_users ADD CONSTRAINT FK_4A2B71EC24ECEDCA FOREIGN KEY (savedexport_id) REFERENCES chill_main_saved_export (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_saved_export_users ADD CONSTRAINT FK_4A2B71ECA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_saved_export_usergroups ADD CONSTRAINT FK_A12F30824ECEDCA FOREIGN KEY (savedexport_id) REFERENCES chill_main_saved_export (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
$this->addSql('ALTER TABLE chill_main_saved_export_usergroups ADD CONSTRAINT FK_A12F308D2112630 FOREIGN KEY (usergroup_id) REFERENCES chill_main_user_group (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_main_saved_export_users DROP CONSTRAINT FK_4A2B71EC24ECEDCA');
$this->addSql('ALTER TABLE chill_main_saved_export_users DROP CONSTRAINT FK_4A2B71ECA76ED395');
$this->addSql('ALTER TABLE chill_main_saved_export_usergroups DROP CONSTRAINT FK_A12F30824ECEDCA');
$this->addSql('ALTER TABLE chill_main_saved_export_usergroups DROP CONSTRAINT FK_A12F308D2112630');
$this->addSql('DROP TABLE chill_main_saved_export_users');
$this->addSql('DROP TABLE chill_main_saved_export_usergroups');
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250417135712 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add the role CHILL_MAIN_COMPOSE_EXPORT to the existing permissions groups which contains already a permission related to list or stat';
}
public function up(Schema $schema): void
{
$this->addSql(
<<<'SQL'
CREATE TEMPORARY TABLE to_create AS (
SELECT DISTINCT permissionsgroup_rolescope.permissionsgroup_id, 'CHILL_MAIN_COMPOSE_EXPORT' AS role
FROM permissionsgroup_rolescope
JOIN public.role_scopes rs on permissionsgroup_rolescope.rolescope_id = rs.id
WHERE role LIKE '%STATS%' or role LIKE '%LIST%'
)
SQL
);
$this->addSql(
<<<'SQL'
INSERT INTO role_scopes(id, scope_id, role)
SELECT nextval('role_scopes_id_seq'), null, 'CHILL_MAIN_COMPOSE_EXPORT'
WHERE NOT EXISTS (SELECT 1 FROM role_scopes s WHERE role like 'CHILL_MAIN_COMPOSE_EXPORT')
SQL
);
$this->addSql('ALTER TABLE to_create ADD COLUMN rolescope_id INT');
$this->addSql(
<<<'SQL'
UPDATE to_create SET rolescope_id = (
SELECT id FROM role_scopes
WHERE to_create.role = role_scopes.role)
SQL
);
$this->addSql(
<<<'SQL'
INSERT INTO permissionsgroup_rolescope (permissionsgroup_id, rolescope_id)
SELECT to_create.permissionsgroup_id, to_create.rolescope_id FROM to_create
SQL
);
}
public function down(Schema $schema): void
{
$this->throwIrreversibleMigrationException();
}
}

View File

@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250425093948 extends AbstractMigration
{
public function getDescription(): string
{
return 'Create a relation between usergroup and user job';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_user_group ADD userJob_id INT DEFAULT NULL
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_user_group ADD CONSTRAINT FK_6576E74D64B65C5B FOREIGN KEY (userJob_id) REFERENCES chill_main_user_job (id) NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
$this->addSql(<<<'SQL'
CREATE INDEX IDX_6576E74D64B65C5B ON chill_main_user_group (userJob_id)
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_user_group DROP CONSTRAINT FK_6576E74D64B65C5B
SQL);
$this->addSql(<<<'SQL'
DROP INDEX IDX_6576E74D64B65C5B
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_user_group DROP userJob_id
SQL);
}
}

View File

@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\Migrations\Main;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20250617141354 extends AbstractMigration
{
public function getDescription(): string
{
return 'When a row in chill_main_saved_export is deleted, set the references to NULL in chill_main_export_generation table';
}
public function up(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_export_generation DROP CONSTRAINT FK_E644B77DA61D6F69
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_export_generation ADD CONSTRAINT FK_E644B77DA61D6F69 FOREIGN KEY (savedExport_id) REFERENCES chill_main_saved_export (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
}
public function down(Schema $schema): void
{
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_export_generation DROP CONSTRAINT fk_e644b77da61d6f69
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE chill_main_export_generation ADD CONSTRAINT fk_e644b77da61d6f69 FOREIGN KEY (savedexport_id) REFERENCES chill_main_saved_export (id) NOT DEFERRABLE INITIALLY IMMEDIATE
SQL);
}
}