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

        $oUri     = Factory::service('Uri');
        $oDb      = Factory::service('Database');
        $oSession = Factory::service('Session', 'nails/module-auth');
        $oModel   = $this->getModel();
        $oItem    = $this->getItem([], null, true);

        try {

            $oDb->trans_begin();
            if (classUses($oModel, Localised::class)) {
                $bResult = $oModel->restore($oItem->id, $oItem->locale);
            } else {
                $bResult = $oModel->restore($oItem->id);
            }

            if (!$bResult) {
                throw new NailsException(static::RESTORE_ERROR_MESSAGE . ' ' . $oModel->lastError());
            }

            $oDb->trans_commit();
            $oSession->setFlashData('success', static::RESTORE_SUCCESS_MESSAGE);
            $this->returnToIndex();

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $oSession->setFlashData('error', static::RESTORE_ERROR_MESSAGE . ' ' . $e->getMessage());
            $this->returnToIndex();
        }
    }
public function restore(): void
    {
        $aConfig = $this->getConfig();
        if (!$aConfig['CAN_RESTORE']) {
            show404();
        } elseif (!static::userCan('restore')) {
            unauthorised();
        }

        $oUri     = Factory::service('Uri');
        $oDb      = Factory::service('Database');
        $oSession = Factory::service('Session', 'nails/module-auth');
        $oModel   = $this->getModel();
        $oItem    = $this->getItem([], null, true);

        try {

            $oDb->trans_begin();
            if (classUses($oModel, Localised::class)) {
                $bResult = $oModel->restore($oItem->id, $oItem->locale);
            } else {
                $bResult = $oModel->restore($oItem->id);
            }

            if (!$bResult) {
                throw new NailsException(static::RESTORE_ERROR_MESSAGE . ' ' . $oModel->lastError());
            }

            $oDb->trans_commit();
            $oSession->setFlashData('success', static::RESTORE_SUCCESS_MESSAGE);
            $this->returnToIndex();

        } catch (\Exception $e) {
            $oDb->trans_rollback();
            $oSession->setFlashData('error', static::RESTORE_ERROR_MESSAGE . ' ' . $e->getMessage());
            $this->returnToIndex();
        }
    }
public function restore ( ) : void { $ aConfig = $ this -> getConfig ( ) ; if ( ! $ aConfig [ 'CAN_RESTORE' ] ) { show404 ( ) ; } elseif ( ! static :: userCan ( 'restore' ) ) { unauthorised ( ) ; } $ oUri = Factory :: service ( 'Uri' ) ; $ oDb = Factory :: service ( 'Database' ) ; $ oSession = Factory :: service ( 'Session' , 'nails/module-auth' ) ; $ oModel = $ this -> getModel ( ) ; $ oItem = $ this -> getItem ( [ ] , null , true ) ; try { $ oDb -> trans_begin ( ) ; if ( classUses ( $ oModel , Localised :: class ) ) { $ bResult = $ oModel -> restore ( $ oItem -> id , $ oItem -> locale ) ; } else { $ bResult = $ oModel -> restore ( $ oItem -> id ) ; } if ( ! $ bResult ) { throw new NailsException ( static :: RESTORE_ERROR_MESSAGE . ' ' . $ oModel -> lastError ( ) ) ; } $ oDb -> trans_commit ( ) ; $ oSession -> setFlashData ( 'success' , static :: RESTORE_SUCCESS_MESSAGE ) ; $ this -> returnToIndex ( ) ; } catch ( \ Exception $ e ) { $ oDb -> trans_rollback ( ) ; $ oSession -> setFlashData ( 'error' , static :: RESTORE_ERROR_MESSAGE . ' ' . $ e -> getMessage ( ) ) ; $ this -> returnToIndex ( ) ; } }
Restore an item

@return void
Restore an item