Skip to content

Commit

Permalink
BUGFIX: Delete workspace details when user is deleted
Browse files Browse the repository at this point in the history
Resolves: #34
  • Loading branch information
Sebobo committed Jan 8, 2024
1 parent f7d6f06 commit 210adca
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions Classes/Domain/Model/WorkspaceDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class WorkspaceDetails

/**
* @ORM\OneToOne
* @ORM\JoinColumn(onDelete="CASCADE")
* @Flow\Identity
* @var Workspace
*/
Expand Down
32 changes: 32 additions & 0 deletions Migrations/Mysql/Version20240108102400.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240108102400 extends AbstractMigration
{
public function getDescription(): string
{
return 'Delete workspace details when user including their workspaces are deleted';
}

public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails DROP FOREIGN KEY FK_923CCEA8D940019');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ADD CONSTRAINT FK_923CCEA8D940019 FOREIGN KEY (workspace) REFERENCES neos_contentrepository_domain_model_workspace (name) ON DELETE CASCADE');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.');

$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails DROP FOREIGN KEY FK_923CCEA8D940019');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ADD CONSTRAINT FK_923CCEA8D940019 FOREIGN KEY (workspace) REFERENCES neos_contentrepository_domain_model_workspace (name)');
}
}
34 changes: 34 additions & 0 deletions Migrations/Postgresql/Version20240108102821.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace Neos\Flow\Persistence\Doctrine\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20240108102821 extends AbstractMigration
{
public function getDescription(): string
{
return 'Delete workspace details when user including their workspaces are deleted';
}

public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on "postgresql".');

$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails DROP CONSTRAINT FK_923CCEA8D940019');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ALTER workspace DROP NOT NULL');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ADD CONSTRAINT FK_923CCEA8D940019 FOREIGN KEY (workspace) REFERENCES neos_contentrepository_domain_model_workspace (name) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE');
}

public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on "postgresql".');

$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails DROP CONSTRAINT fk_923ccea8d940019');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ALTER workspace SET NOT NULL');
$this->addSql('ALTER TABLE shel_neos_workspacemodule_domain_model_workspacedetails ADD CONSTRAINT fk_923ccea8d940019 FOREIGN KEY (workspace) REFERENCES neos_contentrepository_domain_model_workspace (name) NOT DEFERRABLE INITIALLY IMMEDIATE');
}
}

0 comments on commit 210adca

Please sign in to comment.