Skip to content

[Grid config & Saved search] Set owner to NULL on user delete instead of cascading#1940

Merged
wwidergoldpimcore merged 1 commit into
2025.4from
1918-config-owner-set-null-on-user-delete
Jul 6, 2026
Merged

[Grid config & Saved search] Set owner to NULL on user delete instead of cascading#1940
wwidergoldpimcore merged 1 commit into
2025.4from
1918-config-owner-set-null-on-user-delete

Conversation

@wwidergoldpimcore

Copy link
Copy Markdown
Contributor

Changes in this pull request

Resolves #1918

Deleting a user cascaded to their grid configurations and saved searches, removing them even when they were shared with or made global for other users. Those users silently lost the shared configurations.

This switches the owner foreign key from ON DELETE CASCADE to ON DELETE SET NULL on both configuration tables so the configurations survive owner deletion, and surfaces an orphaned configuration through the Entity Ownership management as owner id 0 (ownerDeleted = true), as requested in the issue.

Details

  • Schema (Installer.php + new migration Version20260703120000): owner FK CASCADESET NULL on bundle_studio_grid_configurations and bundle_studio_saved_search_configurations; the saved-search owner column is made nullable (grid's already was). Matches the SET NULL pattern already used by other bundles' owner FKs (job run, bookmark list, copilot).
  • Entities / interface: owner becomes ?int on both entities and ShareableConfigurationInterface::getOwner() (a NULL owner would otherwise fatal on Doctrine hydration). Owner-based permission checks remain correct (null === userId → false).
  • Ownership management: GridConfigurationProvider / SavedSearchConfigurationProvider map a NULL owner to ownerId: 0 / ownerName: nullownerDeleted: true.
  • API: Search\Schema\DetailedConfiguration::ownerId is now nullable, mirroring Grid\Schema\DetailedConfiguration (a shared config's owner can now be null). Minor, backward-tolerant OpenAPI change — worth a heads-up to the frontend.
  • Shares/favorites keep CASCADE (a share pointing at a deleted user is meaningless).

Additional info

  • Verified locally: php -l + PHPStan clean on changed dirs; full Unit suite (417 tests) passes plus 2 new regression tests in GridConfigurationProviderTest; migration applied to a dev DB and confirmed (SET NULL + nullable owner).
  • Will need forward-merging into 2026.1 / 2026.x per the branching workflow.

… of cascading

Deleting a user cascaded to their grid configurations and saved searches,
removing them even when they were shared with or made global for other users.

Switch the owner foreign key from ON DELETE CASCADE to ON DELETE SET NULL on
both bundle_studio_grid_configurations and bundle_studio_saved_search_configurations,
make the owner column nullable, and surface a NULL owner through the Entity
Ownership management as owner id 0 (ownerDeleted = true).

Resolves #1918

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Jul 6, 2026

Copy link
Copy Markdown

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 12 minor

Results:
12 new issues

Category Results
BestPractice 1 minor
CodeStyle 11 minor

View in Codacy

🟢 Metrics 18 complexity

Metric Results
Complexity 18

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@wwidergoldpimcore wwidergoldpimcore self-assigned this Jul 6, 2026
@wwidergoldpimcore wwidergoldpimcore added this to the 2025.4.7 milestone Jul 6, 2026
@wwidergoldpimcore wwidergoldpimcore marked this pull request as ready for review July 6, 2026 13:08
@martineiber martineiber requested a review from Copilot July 6, 2026 13:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request resolves #1918 by preventing shared/grid and saved-search configurations from being deleted when their owning user is deleted. Instead of cascading deletions, the schema now preserves configurations and represents “deleted owner” consistently (DB owner NULL, surfaced as owner id 0 + ownerDeleted = true in ownership management; API owner id nullable).

Changes:

  • Database schema update: switch owner FK from ON DELETE CASCADE to ON DELETE SET NULL for grid + saved-search configuration tables (and make saved-search owner nullable).
  • Domain/API alignment: owner becomes ?int in entities + ShareableConfigurationInterface, and saved-search DetailedConfiguration::ownerId becomes nullable.
  • Ownership management mapping: providers translate NULL owner to ownerId = 0 and ownerName = null, which results in ownerDeleted = true.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Unit/OwnershipManagement/Provider/GridConfigurationProviderTest.php Adds regression coverage for surfacing deleted owners as owner id 0.
src/Search/Schema/DetailedConfiguration.php Makes saved-search ownerId nullable in the OpenAPI schema + PHP type.
src/OwnershipManagement/Provider/SavedSearchConfigurationProvider.php Maps NULL owner to ownership-management “deleted owner” representation.
src/OwnershipManagement/Provider/GridConfigurationProvider.php Same “deleted owner” mapping for grid configurations.
src/Migrations/Version20260703120000.php New migration to switch owner FK behavior to SET NULL and ensure nullable owner column.
src/Installer.php Updates fresh-install schema for both tables to use SET NULL and nullable owner (saved search).
src/Entity/Search/SavedSearchConfiguration.php Makes owner nullable (?int) to support SET NULL hydration.
src/Entity/Grid/GridConfiguration.php Fixes owner type to ?int to match nullable column and avoid hydration issues.
src/Configuration/Share/ShareableConfigurationInterface.php Updates getOwner() return type to ?int to support nullable owners.

Comment on lines +118 to +119
$ownerId ?? 0,
$ownerId === null ? null : ($ownerNames[$ownerId] ?? null),
Comment on lines +61 to +62
// SET NULL requires a nullable column; CASCADE keeps it nullable as well (harmless superset).
$table->getColumn('owner')->setNotnull(false);
@wwidergoldpimcore wwidergoldpimcore merged commit e51f496 into 2025.4 Jul 6, 2026
14 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2026
@wwidergoldpimcore wwidergoldpimcore deleted the 1918-config-owner-set-null-on-user-delete branch July 6, 2026 13:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants