getRevision

@param Site $site
@param Page $page
@param null $pageRevisionId

@return null|\Rcm\Entity\Revision
427946
protected function getRevision(
        Site $site,
        Page $page,
        $pageRevisionId = null
    ) {
        $hasRevisionId = !empty($pageRevisionId);

        $hasAccess = false;

        if ($hasRevisionId) {
            $hasAccess = $this->cmsPermissionChecks->shouldShowRevisions(
                $site->getSiteId(),
                $page->getName(),
                $page->getPageType()
            );
        }

        if ($hasAccess) {
            return $page->getRevisionById($pageRevisionId);
        }

        // Check for staging
        $hasAccess = $this->cmsPermissionChecks->siteAdminCheck(
            $site
        );

        $revision = null;

        if ($hasAccess) {
            // @todo is this right, This means admins can never see published revisions
            $revision = $page->getStagedRevision();
        }

        // There might be cases where there is no staged revision
        // so this check is required
        if (!empty($revision)) {
            return $revision;
        }

        // Finally look for published revision
        return $page->getPublishedRevision();
    }
639996
public function show($version, $page = null)
    {
        $documentation = $this->documentationRepository->get($version, $page);

        if (Gate::has('viewLarecipe')) {
            $this->authorize('viewLarecipe', $documentation);
        }

        if ($this->documentationRepository->isNotPublishedVersion($version)) {
            return redirect()->route(
                'larecipe.show',
                [
                    'version' => config('larecipe.versions.default'),
                    'page' => config('larecipe.docs.landing')
                ]
            );
        }

        return response()->view('larecipe::docs', [
            'title'          => $documentation->title,
            'index'          => $documentation->index,
            'content'        => $documentation->content,
            'currentVersion' => $version,
            'versions'       => $documentation->publishedVersions,
            'currentSection' => $documentation->currentSection,
            'canonical'      => $documentation->canonical,
        ], $documentation->statusCode);
    }
75518
public function save(Site $site)
    {
        $id = $site->getId();
        if ($id == 0) {
            return $this->getTableGateway()->insert($site->toArray());
        } elseif ($this->findById($id)) {
            return $this->getTableGateway()->update($site->toArray(), array("id" => $id));
        } else {
            return NULL;
        }
    }
724220
protected long getRevisionIdFromResponse(JsonNode response) throws JsonMappingException {
		if(response == null) {
			throw new JsonMappingException("API response is null");
		}
		JsonNode entity = null;
		if(response.has("entity")) {
			entity = response.path("entity");
		} else if(response.has("pageinfo")) {
			entity = response.path("pageinfo");
		} 
		if(entity != null && entity.has("lastrevid")) {
			return entity.path("lastrevid").asLong();
		}
		throw new JsonMappingException("The last revision id could not be found in API response");
	}
322601
private function getParamsFromRevision( Revision $revision ) {
		$params = [
			'undo' => $revision->getId(),
			'token' => $this->api->getToken(),
		];

		if ( !is_null( $revision->getPageIdentifier()->getId() ) ) {
			$params['pageid'] = $revision->getPageIdentifier()->getId();
		} else {
			$params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
		}

		return $params;
	}
1085225
public Revision getRevision(final int revisionID)
        throws WikiApiException
    {

        try {
            if (revisionID < 1) {
                throw new IllegalArgumentException();
            }

            int fullRevPK = -1;
            int limit = 1;

            PreparedStatement statement = null;
            ResultSet result = null;

            try {
                statement = this.connection.prepareStatement("SELECT FullRevisionPK, RevisionPK "
                        + "FROM index_revisionID " + "WHERE revisionID=? LIMIT 1");
                statement.setInt(1, revisionID);
                result = statement.executeQuery();

                if (result.next()) {
                    fullRevPK = result.getInt(1);
                    limit = (result.getInt(2) - fullRevPK) + 1;

                }
                else {
                    throw new WikiPageNotFoundException("The revision with the ID " + revisionID
                            + " was not found.");
                }

            }
            finally {
                if (statement != null) {
                    statement.close();
                }
                if (result != null) {
                    result.close();
                }
            }

            return buildRevisionMetaData(fullRevPK, limit);

        }
        catch (WikiPageNotFoundException e) {
            throw e;
        }
        catch (Exception e) {
            throw new WikiApiException(e);
        }
    }
1319635
public function getCmsResponse(
        Site $site,
        Page $page,
        $revisionId = null
    ) {
        $pageRenderer = $this->getPageRenderer();

        $response = new \Rcm\Http\Response();
        $layoutView = $this->layout();
        $viewModel = new ViewModel();

        return $pageRenderer->renderZf2ByName(
            $response,
            $layoutView,
            $viewModel,
            $site,
            $page->getName(),
            $page->getPageType(),
            $revisionId
        );
    }
325450
public function getRevision() : ?string 
    {
        if ( ! $this->hasRevision()) {
            $this->setRevision($this->getDefaultRevision());
        }
        return $this->revision;
    }
523617
def preview_page_version(request, revision_id):
    
    revision = get_object_or_404(PageRevision, pk=revision_id)

    if not revision.page.permissions_for_user(request.user).can_publish():
        raise PermissionDenied

    page                = revision.as_page_object()
    request.revision_id = revision_id

    return page.serve_preview(request, page.default_preview_mode)
895974
private function getEditParams( Revision $revision, EditInfo $editInfo = null ) {
		if ( !$revision->getPageIdentifier()->identifiesPage() ) {
			throw new RuntimeException( '$revision PageIdentifier does not identify a page' );
		}

		$params = [];

		$content = $revision->getContent();
		$data = $content->getData();
		if ( !is_string( $data ) ) {
			throw new RuntimeException( 'Dont know how to save content of this model.' );
		}
		$params['text'] = $content->getData();
		$params['md5'] = md5( $content->getData() );

		$timestamp = $revision->getTimestamp();
		if ( !is_null( $timestamp ) ) {
			$params['basetimestamp'] = $timestamp;
		}

		if ( !is_null( $revision->getPageIdentifier()->getId() ) ) {
			$params['pageid'] = $revision->getPageIdentifier()->getId();
		} else {
			$params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
		}

		$params['token'] = $this->api->getToken();

		if ( $this->api->isLoggedin() ) {
			$params['assert'] = 'user';
		}

		$this->addEditInfoParams( $editInfo, $params );

		return $params;
	}
48627
public function getData(
        Site $site,
        $pageName,
        $pageType = PageTypes::NORMAL,
        $revisionId = null
    ) {
        $pageData = $this->getNew();
        $pageData->setSite($site);
        $pageData->setRequestedPage(
            [
                'name' => strtolower($pageName),
                'type' => strtolower($pageType),
                'revision' => $revisionId,
            ]
        );

        $requestPage = $this->getPage(
            $site,
            $pageName,
            $pageType
        );

        $page = $this->preparePage(
            $site,
            $requestPage,
            $revisionId
        );

        if (empty($page)) {
            $pageData->setHttpStatus(
                $this->pageStatus->getNotFoundStatus()
            );

            return $pageData;
        }

        $pageData->setPage($page);

        $allowed = $this->cmsPermissionChecks->isPageAllowedForReading($page);

        if (!$allowed) {
            $pageData->setHttpStatus(
                $this->pageStatus->getNotAuthorizedStatus()
            );

            return $pageData;
        }

        // @todo FUTURE Insert Block data (plugin data)
        // $pageData->setBlocks([]);

        $pageData->setHttpStatus(
            $this->getStatus(
                $pageData->getRequestedPageName(),
                $page->getName()
            )
        );

        return $pageData;
    }
512312
public static function getByLocale($locale, Site $site = null)
    {
        if (!$site) {
            $site = \Core::make('site')->getSite();
        }
        if ($locale) {
            if (!is_object($locale)) {
                $locale = explode('_', $locale);
                if (!isset($locale[1])) {
                    $locale[1] = '';
                }
                $em = Database::get()->getEntityManager();
                $locale = $em->getRepository('Concrete\Core\Entity\Site\Locale')
                    ->findOneBy(['site' => $site, 'msLanguage' => $locale[0], 'msCountry' => $locale[1]]);
            }

            if (is_object($locale)) {
                $obj = parent::getByID($locale->getSiteTree()->getSiteHomePageID(), 'RECENT');
                $obj->setLocale($locale);

                return $obj;
            }
        }

        return false;
    }
836331
public function getDataBySiteIdAndPageId($siteId, $pageId)
	{
	    $select = $this->tableGateway->getSql()->select();
	     
	    $select->columns(array('*'));
	     
	    $select->where(array("s404_site_id" => $siteId, 's404_page_id' => $pageId));
	    $resultSet = $this->tableGateway->selectWith($select);
	     
	    return $resultSet;
	}
574834
protected function getCurrentRevision($page)
    {
        if (empty($page)) {
            return null;
        }
        $revision = $page->getCurrentRevision();
        if ($revision instanceof \Rcm\Entity\Revision) {
            return $revision->getRevisionId();
        }

        return null;
    }
225633
public function url($pageName, $pageType = PageTypes::NORMAL, $pageRevision = null)
    {
        /** @var \Zend\Mvc\Controller\AbstractActionController $controller */
        $view = $this->getView();

        if ($pageType == PageTypes::NORMAL && $pageName == 'index' && empty($pageRevision)) {
            return '/';
        } elseif ($pageType == PageTypes::NORMAL && empty($pageRevision)) {
            return $view->url(
                'contentManager',
                ['page' => $pageName]
            );
        } elseif ($pageType == PageTypes::NORMAL && !empty($pageRevision)) {
            return $view->url(
                'contentManager',
                [
                    'revision' => $pageRevision,
                    'page' => $pageName,
                ]
            );
        } elseif ($pageType != PageTypes::NORMAL && !empty($pageRevision)) {
            return $view->url(
                'contentManagerWithPageType',
                [
                    'revision' => $pageRevision,
                    'pageType' => $pageType,
                    'page' => $pageName,
                ]
            );
        } else {
            return $view->url(
                'contentManagerWithPageType',
                [
                    'pageType' => $pageType,
                    'page' => $pageName,
                ]
            );
        }
    }
907680
public function getPreviewFromPdf(FilesModel $file, int $page = 0): FilesModel
    {
        $strippedName = str_replace('.'.$file->extension, '', $file->name);
        $previewFileName = 'preview-'.$strippedName.'.'.static::FILE_UTIL_CONVERT_FILE_TYPE;
        $folder = str_replace($file->name, '', $file->path);
        $target = $folder.\DIRECTORY_SEPARATOR.$previewFileName;

        // ghostscript
        /** @var Transcoder $transcoder */
        $transcoder = $this->framework->getAdapter(Transcoder::class)->create();
        $transcoder->toImage($file->path, $target);

        // get all created images
        $folderFiles = scandir($folder);
        $pdfPreviewFiles = [];
        $needle = '/preview-'.$strippedName.'*\.'.static::FILE_UTIL_CONVERT_FILE_TYPE.'/';

        foreach ($folderFiles as $file) {
            if (!preg_match($needle, $file)) {
                continue;
            }

            $pdfPreviewFiles[] = $file;
        }

        $preview = null;

        foreach ($pdfPreviewFiles as $key => $value) {
            if ($page != $key && file_exists($value)) {
                unlink($value);

                continue;
            }

            $preview = $value;
        }

        if (null === ($previewFile = $this->framework->getAdapter(FilesModel::class)->findByPath($preview))) {
            $previewFile = $this->framework->getAdapter(Dbafs::class)->addResource($folder.\DIRECTORY_SEPARATOR.$preview);
        }

        return $previewFile;
    }
411926
protected function hasPage(
        $site,
        $pageName,
        $pageType
    ) {
        return $this->getPageRepo()->sitePageExists(
            $site,
            $pageName,
            $pageType
        );
    }