src/Extension/FluentExtension.php
public function updateDeleteTables(&$queriedTables)
    {
        // Ensure a locale exists
        $locale = Locale::getCurrentLocale();
        if (!$locale) {
            return;
        }

        // Fluent takes over deletion of objects
        $queriedTables = [];
        $localisedTables = $this->getLocalisedTables();
        $tableClasses = ClassInfo::ancestry($this->owner, true);
        foreach ($tableClasses as $class) {
            // Check main table name
            $table = DataObject::getSchema()->tableName($class);

            // Create root table delete
            $rootTable = $this->getDeleteTableTarget($table);
            $rootDelete = SQLDelete::create("\"{$rootTable}\"")
                ->addWhere(["\"{$rootTable}\".\"ID\"" => $this->owner->ID]);

            // If table isn't localised, simple delete
            if (!isset($localisedTables[$table])) {
                $baseTable = $this->getDeleteTableTarget($this->owner->baseTable());

                // The base table isn't localised? Delete the record then.
                if ($baseTable === $rootTable) {
                    $rootDelete->execute();
                    continue;
                }

                $rootDelete
                    ->setDelete("\"{$rootTable}\"")
                    ->addLeftJoin(
                        $baseTable,
                        "\"{$rootTable}\".\"ID\" = \"{$baseTable}\".\"ID\""
                    )
                    // Only when join matches no localisations is it safe to delete
                    ->addWhere("\"{$baseTable}\".\"ID\" IS NULL")
                    ->execute();

                continue;
            }

            // Remove _Localised record
            $localisedTable = $this->getDeleteTableTarget($table, $locale);
            $localisedDelete = SQLDelete::create(
                "\"{$localisedTable}\"",
                [
                    '"Locale"' => $locale->Locale,
                    '"RecordID"' => $this->owner->ID,
                ]
            );
            $localisedDelete->execute();

            // Remove orphaned ONLY base table (delete after deleting last localised row)
            // Note: No "Locale" filter as we are excluding any tables that have any localised records
            $rootDelete
                ->setDelete("\"{$rootTable}\"")
                ->addLeftJoin(
                    $localisedTable,
                    "\"{$rootTable}\".\"ID\" = \"{$localisedTable}\".\"RecordID\""
                )
                // Only when join matches no localisations is it safe to delete
                ->addWhere("\"{$localisedTable}\".\"ID\" IS NULL")
                ->execute();
        }
    }
public function updateDeleteTables(&$queriedTables)
    {
        // Ensure a locale exists
        $locale = Locale::getCurrentLocale();
        if (!$locale) {
            return;
        }

        // Fluent takes over deletion of objects
        $queriedTables = [];
        $localisedTables = $this->getLocalisedTables();
        $tableClasses = ClassInfo::ancestry($this->owner, true);
        foreach ($tableClasses as $class) {
            // Check main table name
            $table = DataObject::getSchema()->tableName($class);

            // Create root table delete
            $rootTable = $this->getDeleteTableTarget($table);
            $rootDelete = SQLDelete::create("\"{$rootTable}\"")
                ->addWhere(["\"{$rootTable}\".\"ID\"" => $this->owner->ID]);

            // If table isn't localised, simple delete
            if (!isset($localisedTables[$table])) {
                $baseTable = $this->getDeleteTableTarget($this->owner->baseTable());

                // The base table isn't localised? Delete the record then.
                if ($baseTable === $rootTable) {
                    $rootDelete->execute();
                    continue;
                }

                $rootDelete
                    ->setDelete("\"{$rootTable}\"")
                    ->addLeftJoin(
                        $baseTable,
                        "\"{$rootTable}\".\"ID\" = \"{$baseTable}\".\"ID\""
                    )
                    // Only when join matches no localisations is it safe to delete
                    ->addWhere("\"{$baseTable}\".\"ID\" IS NULL")
                    ->execute();

                continue;
            }

            // Remove _Localised record
            $localisedTable = $this->getDeleteTableTarget($table, $locale);
            $localisedDelete = SQLDelete::create(
                "\"{$localisedTable}\"",
                [
                    '"Locale"' => $locale->Locale,
                    '"RecordID"' => $this->owner->ID,
                ]
            );
            $localisedDelete->execute();

            // Remove orphaned ONLY base table (delete after deleting last localised row)
            // Note: No "Locale" filter as we are excluding any tables that have any localised records
            $rootDelete
                ->setDelete("\"{$rootTable}\"")
                ->addLeftJoin(
                    $localisedTable,
                    "\"{$rootTable}\".\"ID\" = \"{$localisedTable}\".\"RecordID\""
                )
                // Only when join matches no localisations is it safe to delete
                ->addWhere("\"{$localisedTable}\".\"ID\" IS NULL")
                ->execute();
        }
    }
public function updateDeleteTables ( & $ queriedTables ) { // Ensure a locale exists $ locale = Locale :: getCurrentLocale ( ) ; if ( ! $ locale ) { return ; } // Fluent takes over deletion of objects $ queriedTables = [ ] ; $ localisedTables = $ this -> getLocalisedTables ( ) ; $ tableClasses = ClassInfo :: ancestry ( $ this -> owner , true ) ; foreach ( $ tableClasses as $ class ) { // Check main table name $ table = DataObject :: getSchema ( ) -> tableName ( $ class ) ; // Create root table delete $ rootTable = $ this -> getDeleteTableTarget ( $ table ) ; $ rootDelete = SQLDelete :: create ( "\"{$rootTable}\"" ) -> addWhere ( [ "\"{$rootTable}\".\"ID\"" => $ this -> owner -> ID ] ) ; // If table isn't localised, simple delete if ( ! isset ( $ localisedTables [ $ table ] ) ) { $ baseTable = $ this -> getDeleteTableTarget ( $ this -> owner -> baseTable ( ) ) ; // The base table isn't localised? Delete the record then. if ( $ baseTable === $ rootTable ) { $ rootDelete -> execute ( ) ; continue ; } $ rootDelete -> setDelete ( "\"{$rootTable}\"" ) -> addLeftJoin ( $ baseTable , "\"{$rootTable}\".\"ID\" = \"{$baseTable}\".\"ID\"" ) // Only when join matches no localisations is it safe to delete -> addWhere ( "\"{$baseTable}\".\"ID\" IS NULL" ) -> execute ( ) ; continue ; } // Remove _Localised record $ localisedTable = $ this -> getDeleteTableTarget ( $ table , $ locale ) ; $ localisedDelete = SQLDelete :: create ( "\"{$localisedTable}\"" , [ '"Locale"' => $ locale -> Locale , '"RecordID"' => $ this -> owner -> ID , ] ) ; $ localisedDelete -> execute ( ) ; // Remove orphaned ONLY base table (delete after deleting last localised row) // Note: No "Locale" filter as we are excluding any tables that have any localised records $ rootDelete -> setDelete ( "\"{$rootTable}\"" ) -> addLeftJoin ( $ localisedTable , "\"{$rootTable}\".\"ID\" = \"{$localisedTable}\".\"RecordID\"" ) // Only when join matches no localisations is it safe to delete -> addWhere ( "\"{$localisedTable}\".\"ID\" IS NULL" ) -> execute ( ) ; } }
Override delete behaviour

@param array $queriedTables
Override delete behaviour