public function delete(): void
    {
        $aConfig = $this->getConfig();
        if (!$aConfig['CAN_DELETE']) {
            show404();
        } elseif (!static::userCan('delete')) {
            unauthorised();
        }

        $oDb    = Factory::service('Database');
        $oModel = $this->getModel();
        $oItem  = $this->getItem();

        if (empty($oItem)) {
            show404();
        }

        try {

            $oDb->trans_begin();
            $this->beforeDelete($oItem);

            if (classUses($oModel, Localised::class)) {
                $oModel->delete($oItem->id, $oItem->locale);
            } elseif (!$oModel->delete($oItem->id)) {
                throw new NailsException(static::DELETE_ERROR_MESSAGE . ' ' . $oModel->lastError());
            }

            $this->afterDelete($oItem);
            $oDb->trans_commit();

            if ($aConfig['CAN_RESTORE'] && static::userCan('restore')) {
                if (classUses($oModel, Localised::class)) {
                    $sRestoreLink = anchor(
                        $aConfig['BASE_URL'] . '/restore/' . $oItem->id . '/' . $oItem->locale,
                        'Restore?'
                    );
                } else {
                    $sRestoreLink = anchor(
                        $aConfig['BASE_URL'] . '/restore/' . $oItem->id,
                        'Restore?'
                    );
                }
            } else {
                $sRestoreLink = '';
            }

            $oSession = Factory::service('Session', 'nails/module-auth');
            $oSession->setFlashData('success', static::DELETE_SUCCESS_MESSAGE . ' ' . $sRestoreLink);
            $this->returnToIndex();

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $oSession = Factory::service('Session', 'nails/module-auth');
            $oSession->setFlashData('error', static::DELETE_ERROR_MESSAGE . ' ' . $e->getMessage());
            $this->returnToIndex();
        }
    }
public function delete(): void
    {
        $aConfig = $this->getConfig();
        if (!$aConfig['CAN_DELETE']) {
            show404();
        } elseif (!static::userCan('delete')) {
            unauthorised();
        }

        $oDb    = Factory::service('Database');
        $oModel = $this->getModel();
        $oItem  = $this->getItem();

        if (empty($oItem)) {
            show404();
        }

        try {

            $oDb->trans_begin();
            $this->beforeDelete($oItem);

            if (classUses($oModel, Localised::class)) {
                $oModel->delete($oItem->id, $oItem->locale);
            } elseif (!$oModel->delete($oItem->id)) {
                throw new NailsException(static::DELETE_ERROR_MESSAGE . ' ' . $oModel->lastError());
            }

            $this->afterDelete($oItem);
            $oDb->trans_commit();

            if ($aConfig['CAN_RESTORE'] && static::userCan('restore')) {
                if (classUses($oModel, Localised::class)) {
                    $sRestoreLink = anchor(
                        $aConfig['BASE_URL'] . '/restore/' . $oItem->id . '/' . $oItem->locale,
                        'Restore?'
                    );
                } else {
                    $sRestoreLink = anchor(
                        $aConfig['BASE_URL'] . '/restore/' . $oItem->id,
                        'Restore?'
                    );
                }
            } else {
                $sRestoreLink = '';
            }

            $oSession = Factory::service('Session', 'nails/module-auth');
            $oSession->setFlashData('success', static::DELETE_SUCCESS_MESSAGE . ' ' . $sRestoreLink);
            $this->returnToIndex();

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $oSession = Factory::service('Session', 'nails/module-auth');
            $oSession->setFlashData('error', static::DELETE_ERROR_MESSAGE . ' ' . $e->getMessage());
            $this->returnToIndex();
        }
    }
public function delete ( ) : void { $ aConfig = $ this -> getConfig ( ) ; if ( ! $ aConfig [ 'CAN_DELETE' ] ) { show404 ( ) ; } elseif ( ! static :: userCan ( 'delete' ) ) { unauthorised ( ) ; } $ oDb = Factory :: service ( 'Database' ) ; $ oModel = $ this -> getModel ( ) ; $ oItem = $ this -> getItem ( ) ; if ( empty ( $ oItem ) ) { show404 ( ) ; } try { $ oDb -> trans_begin ( ) ; $ this -> beforeDelete ( $ oItem ) ; if ( classUses ( $ oModel , Localised :: class ) ) { $ oModel -> delete ( $ oItem -> id , $ oItem -> locale ) ; } elseif ( ! $ oModel -> delete ( $ oItem -> id ) ) { throw new NailsException ( static :: DELETE_ERROR_MESSAGE . ' ' . $ oModel -> lastError ( ) ) ; } $ this -> afterDelete ( $ oItem ) ; $ oDb -> trans_commit ( ) ; if ( $ aConfig [ 'CAN_RESTORE' ] && static :: userCan ( 'restore' ) ) { if ( classUses ( $ oModel , Localised :: class ) ) { $ sRestoreLink = anchor ( $ aConfig [ 'BASE_URL' ] . '/restore/' . $ oItem -> id . '/' . $ oItem -> locale , 'Restore?' ) ; } else { $ sRestoreLink = anchor ( $ aConfig [ 'BASE_URL' ] . '/restore/' . $ oItem -> id , 'Restore?' ) ; } } else { $ sRestoreLink = '' ; } $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oSession -> setFlashData ( 'success' , static :: DELETE_SUCCESS_MESSAGE . ' ' . $ sRestoreLink ) ; $ this -> returnToIndex ( ) ; } catch ( \ Exception $ e ) { $ oDb -> trans_rollback ( ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oSession -> setFlashData ( 'error' , static :: DELETE_ERROR_MESSAGE . ' ' . $ e -> getMessage ( ) ) ; $ this -> returnToIndex ( ) ; } }
Delete an item

@return void
Delete an item