FOF30\Controller\DataController::archive PHP Method

archive() public method

Archive (set enabled = 2) an item.
public archive ( ) : void
return void
    public function archive()
    {
        // CSRF prevention
        $this->csrfProtection();
        $model = $this->getModel()->savestate(false);
        $ids = $this->getIDsFromRequest($model, false);
        $error = null;
        try {
            $status = true;
            foreach ($ids as $id) {
                $model->find($id);
                $userId = $this->container->platform->getUser()->id;
                if ($model->isLocked($userId)) {
                    $model->checkIn($userId);
                }
                $model->archive();
            }
        } catch (\Exception $e) {
            $status = false;
            $error = $e->getMessage();
        }
        // Redirect
        if ($customURL = $this->input->getBase64('returnurl', '')) {
            $customURL = base64_decode($customURL);
        }
        $url = !empty($customURL) ? $customURL : 'index.php?option=' . $this->container->componentName . '&view=' . $this->container->inflector->pluralize($this->view) . $this->getItemidURLSuffix();
        if (!$status) {
            $this->setRedirect($url, $error, 'error');
        } else {
            $this->setRedirect($url);
        }
    }