PHPackages                             i-kadar/cascading-deletion - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. i-kadar/cascading-deletion

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

i-kadar/cascading-deletion
==========================

Package that provides cascading deletion service

v1.0.4(2y ago)022PHP

Since Dec 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ikadar/cascading-deletion)[ Packagist](https://packagist.org/packages/i-kadar/cascading-deletion)[ RSS](/packages/i-kadar-cascading-deletion/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (6)Used By (0)

Cascading Deletion Service
==========================

[](#cascading-deletion-service)

Overview
--------

[](#overview)

The Cascading Deletion Service is designed to manage and execute the deletion of entities within a system, focusing on the interdependencies between entities. The system is structured to ensure data integrity by comprehensively checking the eligibility for deletion of both primary and dependent entities, and by managing the cascading effect of deletions across related entities.

Core Components
---------------

[](#core-components)

### 1. CascadingDeletionService (`CascadingDeletionService.php`)

[](#1-cascadingdeletionservice-cascadingdeletionservicephp)

**Purpose**: Manages the initiation and orchestration of the cascading deletion process. Provides a simple interface for deleting entities within the system.

#### Key Functionalities:

[](#key-functionalities)

- **Entity Deletion Handling**: Manages the deletion of entities, ensuring eligibility for both primary and dependent entities.
- **Data Integrity**: Performs comprehensive checks prior to deletion and aborts the process if any entity in the deletion chain cannot be deleted.
- **Deletion Process Execution**: Collects all entities to be deleted, verifies their eligibility, and executes the deletion process if all are eligible.

### 2. Entity Repository (`EntityRepository.php` and `EntityRepositoryInterface.php`)

[](#2-entity-repository-entityrepositoryphp-and-entityrepositoryinterfacephp)

**EntityRepository**: An abstract class implementing `EntityRepositoryInterface`. Provides the core logic for managing the deletion of entities. Subclasses implement the abstract methods to handle the specific relationships between entities. **EntityRepositoryInterface**: Defines the contract for repository operations. Outlines essential methods for managing deletion targets.

#### Key Functionalities:

[](#key-functionalities-1)

- **Reference Entity Retrieval**: Identifies and retrieves entities referenced by a given entity, managing entity relationships and dependencies. Includes abstract methods `getReferencedDeletionTargets` and `getReferencedDeletionTargets`. These methods are implemented in subclasses to handle the specific relationships between entities.
- **Deletability Checks**: Determines if a given entity can be deleted, including abstract methods `getReferencedDeletionTargets` and `checkDeletability`.
- **Unalterable Core Logic**: The `final` designation of key methods ensures the consistency and integrity of the cascading deletion logic across the system.

#### Unalterable Core Logic:

[](#unalterable-core-logic)

- **Final Methods**: The following key methods are declared as `final` to preserve the central logic of the cascading deletion process across all subclasses and ensure the consistency and integrity of the cascading deletion logic across the system:
    - `final public function getUnDeletableTargets(int $entityId, array $deletionTargets): array`
    - `final public function addTargetToUndeletables(DeletionTargetInterface $target, array $undeletableTargets): void`

### 3. Deletion Targets (`DeletionTargetInterface.php` and `DeletionTarget.php`)

[](#3-deletion-targets-deletiontargetinterfacephp-and-deletiontargetphp)

**DeletionTargetInterface**: Outlines essential methods for managing deletion targets. **DeletionTarget**: Implements `DeletionTargetInterface`, representing entities within the system.

#### Properties and Methods:

[](#properties-and-methods)

- **Entity Identification**: Includes methods for getting entity ID and associated repository.
- **Deletion Status Management**: Methods for setting/getting `isDeletable` status and a message to explain deletion status.
- **State Tracking**: Incorporates a `checkingStarted` property to track the state of deletion eligibility checking, crucial for managing dependencies. Includes methods for setting/getting the checking state.

System Functionality
--------------------

[](#system-functionality)

The system is tailored to handle complex entity relationships, especially focusing on scenarios where deleting one entity triggers the deletion of related entities. The designation of certain methods as `final` in `EntityRepository` underscores the system's commitment to maintaining a consistent and robust deletion process. This cascading deletion process is meticulously designed to maintain data integrity, handle dependencies efficiently, and avoid issues like infinite loops in dependency checks.

Usage Examples of CascadingDeletionService::deleteEntity Method
===============================================================

[](#usage-examples-of-cascadingdeletionservicedeleteentity-method)

Example of Implementing a Basic Repository Class
------------------------------------------------

[](#example-of-implementing-a-basic-repository-class)

In the following example, we demonstrate how to create a simple repository class that extends the abstract `EntityRepository`. This class is responsible for managing a specific type of entity in the context of cascading deletions.

### BasicEntityRepository Example:

[](#basicentityrepository-example)

```
class BasicEntityRepository extends EntityRepository {

    // Implementing the abstract method from EntityRepository
    public function getReferencedDeletionTargets(int $entityId): array {
        // Example logic: Retrieve IDs of entities referenced by the entity with the given ID
        // This is typically where you would query your database or data source
        // For simplicity, we're returning a static array of sample data
        return [
            new DeletionTarget(101, $this), // Assuming entity ID 101 is a dependent entity
            new DeletionTarget(102, $this)  // Assuming entity ID 102 is another dependent entity
        ];
    }

    // Implementing the abstract method from EntityRepository
    public function checkDeletability(DeletionTargetInterface $target, array $targets): bool {
        // Example logic: Check if the entity is deletable
        // This might involve checking certain conditions or rules
        // Returning true for simplicity
        return true;
    }

    // Implementing the abstract method from EntityRepository
    public function performDeletion(int $entityId): void {
        // Example logic: Perform the actual deletion of the entity
        // This is where you would typically delete the entity from your database or data source
        echo "Deleting entity with ID: " . $entityId . "\n";
    }
}
```

Example: Deleting an Entity from the BasicEntityRepository
----------------------------------------------------------

[](#example-deleting-an-entity-from-the-basicentityrepository)

```
$cascadingDeletionService = new CascadingDeletionService();
$basicEntityRepository = new BasicEntityRepository();
$entity = new DeletionTarget(200, $basicEntityRepository);
list($deletionSuccessful, $undeletableEntities) = $cascadingDeletionService->deleteEntity($entity);

if ($deletionSuccessful) {
    echo "Entity was deleted successfully.\n";
} else {
    echo "Deletion was aborted due to undeletable dependents.\n";
    echo "Undeletable entities: \n";
    foreach ($undeletableEntities as $undeletableEntity) {
        echo "Entity ID: " . $undeletableEntity->getEntityId() . "\n";
        echo "Repository: " . get_class($undeletableEntity->getRepository()) . "\n";
        echo "Message: " . $undeletableEntity->getMessage() . "\n";
    }
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance30

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

882d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5572695d9553901a350e68e5402ab800d2d03137ee623ddde9c0743290fc8164?d=identicon)[ikadar](/maintainers/ikadar)

---

Top Contributors

[![ikadar](https://avatars.githubusercontent.com/u/2832767?v=4)](https://github.com/ikadar "ikadar (31 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/i-kadar-cascading-deletion/health.svg)

```
[![Health](https://phpackages.com/badges/i-kadar-cascading-deletion/health.svg)](https://phpackages.com/packages/i-kadar-cascading-deletion)
```

###  Alternatives

[crodas/text-rank

Extract relevant keywords from a given text

10458.6k1](/packages/crodas-text-rank)[kunststube/rison

A PHP encoder and decoder for Rison, the compact JSON-like data format optimized for URIs.

2464.5k3](/packages/kunststube-rison)[evoweb/extender

Extending extbase domain models like a pro with extender

11260.3k6](/packages/evoweb-extender)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
