src/ElementBase.php
public function deleteLocalisedRecords()
    {
        if ($this->hasExtension(self::FLUENT_CLASS))
        {
            $localisedTables = $this->getLocalisedTables();
            $tableClasses = ClassInfo::ancestry($this->owner, true);

            foreach ($tableClasses as $class)
            {
                $table = DataObject::getSchema()->tableName($class);

                $rootTable = $this->getLocalisedTable($table);
                $rootDelete = SQLDelete::create("\"{$rootTable}\"")
                    ->addWhere(["\"{$rootTable}\".\"ID\"" => $this->ID]);

                // If table isn't localised, simple delete
                if (!isset($localisedTables[$table]))
                {
                    $baseTable = $this->getLocalisedTable($this->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;
                }

                $localisedTable = $this->getLocalisedTable($table);
                $localisedDelete = SQLDelete::create(
                    "\"{$localisedTable}\"",
                    [
                        '"RecordID"' => $this->ID,
                    ]
                );
                $localisedDelete->execute();
            }
        }

        return $this;
    }
public function deleteLocalisedRecords()
    {
        if ($this->hasExtension(self::FLUENT_CLASS))
        {
            $localisedTables = $this->getLocalisedTables();
            $tableClasses = ClassInfo::ancestry($this->owner, true);

            foreach ($tableClasses as $class)
            {
                $table = DataObject::getSchema()->tableName($class);

                $rootTable = $this->getLocalisedTable($table);
                $rootDelete = SQLDelete::create("\"{$rootTable}\"")
                    ->addWhere(["\"{$rootTable}\".\"ID\"" => $this->ID]);

                // If table isn't localised, simple delete
                if (!isset($localisedTables[$table]))
                {
                    $baseTable = $this->getLocalisedTable($this->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;
                }

                $localisedTable = $this->getLocalisedTable($table);
                $localisedDelete = SQLDelete::create(
                    "\"{$localisedTable}\"",
                    [
                        '"RecordID"' => $this->ID,
                    ]
                );
                $localisedDelete->execute();
            }
        }

        return $this;
    }
public function deleteLocalisedRecords ( ) { if ( $ this -> hasExtension ( self :: FLUENT_CLASS ) ) { $ localisedTables = $ this -> getLocalisedTables ( ) ; $ tableClasses = ClassInfo :: ancestry ( $ this -> owner , true ) ; foreach ( $ tableClasses as $ class ) { $ table = DataObject :: getSchema ( ) -> tableName ( $ class ) ; $ rootTable = $ this -> getLocalisedTable ( $ table ) ; $ rootDelete = SQLDelete :: create ( "\"{$rootTable}\"" ) -> addWhere ( [ "\"{$rootTable}\".\"ID\"" => $ this -> ID ] ) ; // If table isn't localised, simple delete if ( ! isset ( $ localisedTables [ $ table ] ) ) { $ baseTable = $ this -> getLocalisedTable ( $ this -> 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 ; } $ localisedTable = $ this -> getLocalisedTable ( $ table ) ; $ localisedDelete = SQLDelete :: create ( "\"{$localisedTable}\"" , [ '"RecordID"' => $ this -> ID , ] ) ; $ localisedDelete -> execute ( ) ; } } return $ this ; }
Execute record deletion, even when localised records in non-current locale exist.
@return ElementBase
Execute record deletion even when localised records in non - current locale exist .