Zapisuje draft lub przywraca wersję
@return boolean
336306
public function commitVersion()
    {
        //sprawdzenie czy posiada rodzica (oryginał)
        if (!$this->cmsCategoryOriginalId) {
            return true;
        }
        //wyszukiwanie oryginału
        $originalRecord = (new CmsCategoryQuery)->findPk($this->cmsCategoryOriginalId);
        //tworzenie wersji
        $versionModel = new \Cms\Model\CategoryVersion($originalRecord);
        $versionModel->create();
        //zmiana miejscami draftu z oryginałem
        return $versionModel->exchangeOriginal($this);
    }
680368
public function isWritable()
    {
        if ($this->stream) {
            $meta = $this->getMetadata();
            $writableModes = ['r+', 'w', 'w+', 'a', 'a+', 'x', 'x+', 'c', 'c+'];
            foreach ($writableModes as $mode) {
                if (strpos($meta['mode'], $mode) === 0) {
                    return true;
                }
            }
        }
        return false;
    }
275078
protected function _copyCategory()
    {
        $this->_createCopyRecord();
        $this->_copy->active = $this->_category->active;
        //ustawienie daty dodania na oryginalną kategorię
        $this->_copy->dateAdd = $this->_category->dateAdd;
        //nadawanie id oryginału (chyba że już nadany w przypadku rekordów z historii)
        $this->_copy->cmsCategoryOriginalId = $this->_category->cmsCategoryOriginalId ? $this->_category->cmsCategoryOriginalId : $this->_category->getPk();
        $this->_copy->status = \Cms\Orm\CmsCategoryRecord::STATUS_DRAFT;
        return $this->_copy->save();
    }
1057314
public function thumbnailAction()
    {
        if (!$this->getPost()->cmsFileId) {
            return $this->_jsonError(179);
        }
        //szukamy rekordu pliku
        if (null !== $record = (new CmsFileQuery)->findPk($this->getPost()->cmsFileId)) {
            //sprawdzenie czy obrazek
            if ($record->class === 'image') {
                try {
                    $thumb = new \Cms\Mvc\ViewHelper\Thumb();
                    $url = $thumb->thumb($record, 'scaley', '60');
                    if (!empty($url)) {
                        return json_encode(['result' => 'OK', 'url' => $url]);
                    }
                } catch (\Exception $ex) {
                    
                }
            }
        }
        return $this->_jsonError(179);
    }
987146
public function currentAction()
    {
        $objectId = !empty($this->getPost()->objectId) ? $this->getPost()->objectId : null;
        switch ($this->getPost()->fileTypes) {
            case 'images' :
                //zapytanie o obrazki
                $query = CmsFileQuery::imagesByObject($this->getPost()->object, $objectId);
                break;
            case 'notImages' :
                //wszystkie pliki bez obrazków
                $query = CmsFileQuery::notImagesByObject($this->getPost()->object, $objectId);
                break;
            default :
                //domyślne zapytanie o wszystkie pliki
                $query = CmsFileQuery::byObject($this->getPost()->object, $objectId);
        }

        $records = $query->find();
        foreach ($records as $record) {
            $record->data = $record->data->toArray();
        }

        //zwrot json'a z plikami
        return json_encode([
            'result' => 'OK',
            'files' => $records->toArray()
        ]);
    }
48575
public function make_draft()
    {
        if (!userHasPermission('admin:invoice:invoice:edit')) {
            unauthorised();
        }

        // --------------------------------------------------------------------------

        $oUri     = Factory::service('Uri');
        $oInvoice = $this->oInvoiceModel->getById($oUri->segment(5));
        if (!$oInvoice) {
            show404();
        }

        // --------------------------------------------------------------------------

        //  Allow getting a constant
        $oInvoiceModel = $this->oInvoiceModel;

        $aData = [
            'state' => $oInvoiceModel::STATE_DRAFT,
        ];
        if ($this->oInvoiceModel->update($oInvoice->id, $aData)) {
            $sStatus  = 'success';
            $sMessage = 'Invoice updated successfully!';
        } else {
            $sStatus  = 'error';
            $sMessage = 'Invoice failed to update invoice. ' . $this->oInvoiceModel->lastError();
        }

        $oSession = Factory::service('Session', 'nails/module-auth');
        $oSession->setFlashData($sStatus, $sMessage);

        redirect('admin/invoice/invoice/edit/' . $oInvoice->id);
    }
868173
public function getIsNew ()
		{
			if ($this->_isNew == false)
				return false;

			for ($i = 1; $i <= $this->_params[ 'totalChunks' ]; $i++)
			{
				if ($this->chunkIsUploaded($i))
				{
					$this->_isNew = false;

					return false;
				}
			}

			$this->_isNew = true;

			return true;
		}
706313
public function isArchived()
    {
        /** @var Versioned|DataObject $record */
        $record = $this->record;
        if (!$record->hasExtension(Versioned::class) || !$record->hasStages()) {
            return false;
        }

        if (!isset($record->_cached_isArchived)) {
            $baseClass = $record->baseClass();
            $currentDraft = Versioned::get_by_stage($baseClass, Versioned::DRAFT)->byID($record->ID);
            $currentLive = Versioned::get_by_stage($baseClass, Versioned::LIVE)->byID($record->ID);

            $record->_cached_isArchived = (
                (!$currentDraft || ($currentDraft && $record->Version != $currentDraft->Version))
                && (!$currentLive || ($currentLive && $record->Version != $currentLive->Version))
            );
        }

        return $record->_cached_isArchived;
    }
572033
public function exchangeOriginal(\Cms\Orm\CmsCategoryRecord $draft)
    {
        //usuwanie plików tinymce i z atrybutów
        (new \Cms\Orm\CmsFileQuery)
            //tinymce
            ->orQuery((new \Cms\Orm\CmsFileQuery)->whereObject()->equals(self::FILE_CATEGORY_OBJECT)
                ->andFieldObjectId()->equals($this->_category->id))
            //atrybuty like 'category%' ale bez 'categoryWidgetRelation%'
            ->orQuery((new \Cms\Orm\CmsFileQuery)->whereObject()->like(self::OBJECT_TYPE . '%')
                ->andFieldObject()->notLike(self::CATEGORY_WIDGET_RELATION . '%')
                ->andFieldObjectId()->equals($this->_category->id))
            ->find()
            ->delete();
        //usuwanie widgetów
        (new \Cms\Orm\CmsCategoryWidgetCategoryQuery)
            ->whereCmsCategoryId()->equals($this->_category->id)
            ->find()
            ->delete();
        $attributeValueRelationModel = new AttributeValueRelationModel(self::OBJECT_TYPE, $this->_category->id);
        $attributeValueRelationModel->deleteAttributeValueRelations();
        //nadpisanie danych oryginału
        $this->_category->setFromArray($draft->toArray());
        //id pozostaje niezmienione
        $this->_category->id = $this->_category->getInitialStateValue('id');
        //status active
        $this->_category->status = \Cms\Orm\CmsCategoryRecord::STATUS_ACTIVE;
        //czyszczenie id oryginału
        $this->_category->cmsCategoryOriginalId = null;
        //przenoszenie plików
        \Cms\Model\File::move(self::FILE_CATEGORY_OBJECT, $draft->id, self::FILE_CATEGORY_OBJECT, $this->_category->id);
        //przepinanie widgetów
        foreach ((new \Cms\Orm\CmsCategoryWidgetCategoryQuery)
            ->whereCmsCategoryId()->equals($draft->id)
            ->find() as $widgetCategory) {
            //przepinanie id
            $widgetCategory->cmsCategoryId = $this->_category->id;
            $widgetCategory->save();
        }
        //przepinanie atrybutów
        foreach ((new \Cms\Orm\CmsAttributeValueRelationQuery)
            ->whereObject()->equals(self::OBJECT_TYPE)
            ->whereObjectId()->equals($draft->id)
            ->find() as $attributeRelation) {
            //przepinanie id
            $attributeRelation->objectId = $this->_category->id;
            $attributeRelation->save();
        }
        //przepinanie plików
        foreach ((new \Cms\Orm\CmsFileQuery)
            //tinymce
            ->orQuery((new \Cms\Orm\CmsFileQuery)->whereObject()->equals(self::FILE_CATEGORY_OBJECT)
                ->andFieldObjectId()->equals($draft->id))
            //atrybuty like 'category%' ale bez 'categoryWidgetRelation%'
            ->orQuery((new \Cms\Orm\CmsFileQuery)->whereObject()->like(self::OBJECT_TYPE . '%')
                ->andFieldObject()->notLike(self::CATEGORY_WIDGET_RELATION . '%')
                ->andFieldObjectId()->equals($draft->id))
            ->find() as $file) {
            //przepinanie id
            $file->objectId = $this->_category->id;
            $file->save();
        }
        //synchronizacja ról
        $this->_synchronizeRoles($draft);
        //synchronizacja tagów
        $this->_synchronizeTags($draft);
        //usuwanie draftu
        $draft->delete();
        $this->_category->dateAdd = date('Y-m-d H:i:s');
        return $this->_category->save();
    }
1272199
public function save()
    {
        //data modyfikacji
        $this->dateModify = date('Y-m-d H:i:s');
        $this->lang = \Mmi\App\FrontController::getInstance()->getRequest()->lang;
        //usunięcie kompilantów
        foreach (glob(BASE_PATH . '/var/compile/' . $this->lang . '_*.php') as $compilant) {
            unlink($compilant);
        }
        try {
            $result = parent::save();
        } catch (\Exception $e) {
            //duplikat
            return false;
        }
        //usunięcie cache
        \App\Registry::$cache->remove('Cms-text');
        return $result;
    }
889685
public function afterSave()
        {
                //jeśli czegoś nie uddało się zapisać wcześniej
                if (!parent::afterSave()) {
                        return false;
                }
                //jeśli nie udało się zapisać powiązań z rolami
                if (!$this->_saveRoles()) {
                        return false;
                }
                //commit wersji
                if ($this->getElement('commit')->getValue()) {
                        $this->getRecord()->commitVersion();
                }
                //usunięcie locka
                return (new CategoryLockModel($this->getRecord()->cmsCategoryOriginalId))->releaseLock();
        }
1251987
public function delete()
    {
        //brak pk
        if ($this->getPk() === null) {
            return false;
        }
        //usuwanie historycznych, draftów i dzieci
        (new CmsCategoryQuery)
            ->whereCmsCategoryOriginalId()->equals($this->id)
            ->orFieldParentId()->equals($this->id)
            ->find()
            ->delete();
        //pobranie dzieci
        $children = (new \Cms\Model\CategoryModel)->getCategoryTree($this->getPk());
        if (!empty($children)) {
            throw new \Cms\Exception\ChildrenExistException();
        }
        //usuwanie plików
        (new CmsFileQuery)->whereObject()->equals(self::FILE_OBJECT)
            ->andFieldObjectId()->equals($this->getPk())
            ->find()
            ->delete();
        //usuwanie widgetów
        (new CmsCategoryWidgetCategoryQuery)
            ->whereCmsCategoryId()->equals($this->getPk())
            ->find()
            ->delete();
        //usuwanie kategorii i czyszczenie bufora
        return parent::delete() && $this->clearCache();
    }
1319278
public function releaseLock()
    {
        //wyszukiwanie blokady dla kategorii
        if (null === $lockRecord = (new CacheQuery)->findPk($lockKey = self::CACHE_PREFIX . $this->_categoryId)) {
            //brak blokady
            return true;
        }
        //zwalnianie blokady z opóźnieniem
        $lockRecord->ttl = time() + self::RELEASE_TIMEOUT;
        return $lockRecord->save();
    }
1258943
public function callbackSubmit()
    {
        // Get values from the submitted form
        $password      = $this->form->value("password");
        $passwordAgain = $this->form->value("password-again");

        // Check password matches
        if ($password == null) {
            $this->form->rememberValues();
            $this->form->addOutput("Du angav aldrig ett lösenord");
            return false;
        }

        // Check password matches
        if ($password !== $passwordAgain) {
            $this->form->rememberValues();
            $this->form->addOutput("Lösenordet matchade ej");
            return false;
        }

        $this->user->setPassword($password);
        $this->user->save();
        $this->form->addOutput("<p>Du ändrade ditt lösenord!</p>
        <p>TIPS:Innan du loggar ut, kontrollera så din kontrollfråga stämmer ifall du glömmer bort</p>");
        return true;
    }
591785
public function beforeSave()
    {
        //brak loginu lub hasła
        if (!$this->getElement('username')->getValue() || !$this->getElement('password')->getValue()) {
            return false;
        }
        //autoryzacja
        $auth = \App\Registry::$auth;
        \App\Registry::$auth->setIdentity($this->getElement('username')->getValue());
        \App\Registry::$auth->setCredential($this->getElement('password')->getValue());
        //autoryzacja
        if (!\App\Registry::$auth->authenticate()) {
            return false;
        }
        //zapamiętanie jeśli zaznaczona opcja
        if ($this->getElement('remember')) {
            \App\Registry::$auth->rememberMe(\App\Registry::$config->session->authRemember);
        }
        return true;
    }
1011625
public function beforeSave()
    {
        //brak loginu lub hasła
        if (!$this->getElement('username')->getValue() || !$this->getElement('password')->getValue()) {
            return false;
        }
        //autoryzacja
        $auth = \App\Registry::$auth;
        \App\Registry::$auth->setIdentity($this->getElement('username')->getValue());
        \App\Registry::$auth->setCredential($this->getElement('password')->getValue());
        return \App\Registry::$auth->authenticate();
    }
362004
public function pluploadAction()
    {
        set_time_limit(5 * 60);
        //obiekt handlera plupload
        $pluploadHandler = new Model\PluploadHandler();
        //jeśli wystąpił błąd
        if (!$pluploadHandler->handle()) {
            return $this->_jsonError($pluploadHandler->getErrorCode(), $pluploadHandler->getErrorMessage());
        }
        //jeśli wykonać operację po przesłaniu całego pliku i zapisaniu rekordu
        if ($this->getPost()->afterUpload && null !== $record = $pluploadHandler->getSavedCmsFileRecord()) {
            $this->_operationAfter($this->getPost()->afterUpload, $record);
        }
        return json_encode(['result' => 'OK', 'cmsFileId' => $pluploadHandler->getSavedCmsFileId()]);
    }