File modules/cms/action/page/PagePubAction.class.php

Last commit: Fri Mar 11 12:26:33 2022 +0100	dankert	Fix: Catch error if something happens while publishing.
1 <?php 2 namespace cms\action\page; 3 use cms\action\Method; 4 use cms\action\PageAction; 5 use cms\generator\PageContext; 6 use cms\generator\PageGenerator; 7 use cms\generator\Producer; 8 use cms\generator\Publisher; 9 use cms\generator\PublishOrder; 10 use cms\model\Page; 11 use cms\model\Permission; 12 use cms\model\Template; 13 use language\Messages; 14 use util\exception\PublisherException; 15 use util\Session; 16 17 class PagePubAction extends PageAction implements Method { 18 public function getRequiredPermission() { 19 return Permission::ACL_PUBLISH; 20 } 21 22 public function view() { 23 24 } 25 public function post() { 26 27 if ( !$this->page->hasRight( Permission::ACL_PUBLISH ) ) 28 throw new \util\exception\SecurityException( 'no right for publish' ); 29 30 $project = $this->page->getProject(); 31 32 $template = new Template( $this->page->templateid ); 33 $template->load(); 34 35 if ( ! $template->publish ) { 36 $this->addWarningFor( $this->page,Messages::NOPUBLISH ); 37 return; 38 } 39 40 // Nothing is written to the session from this point. so we should free the session. 41 Session::close(); 42 43 $publisher = new Publisher( $project->projectid ); 44 45 foreach( $project->getModelIds() as $modelId ) { 46 47 foreach( $project->getLanguageIds() as $languageId ) { 48 49 $pageContext = new PageContext( $this->page->objectid, Producer::SCHEME_PUBLIC ); 50 $pageContext->modelId = $modelId; 51 $pageContext->languageId = $languageId; 52 53 $pageGenerator = new PageGenerator( $pageContext ); 54 55 $publisher->addOrderForPublishing( new PublishOrder( $pageGenerator->getCache()->load()->getFilename(),$pageGenerator->getPublicFilename(), $this->page->lastchangeDate ) ); 56 } 57 } 58 59 try { 60 $publisher->publish(); 61 $this->page->setPublishedTimestamp(); 62 63 $this->addNoticeFor( $this->page, 64 'PUBLISHED', 65 array(), 66 implode("\n",$publisher->getDestinationFilenames() ) 67 ); 68 } catch( PublisherException $e ) { 69 $this->addErrorFor( $this->page,Messages::PUBLISHED_ERROR,[],$e->getMessage() ); 70 } 71 } 72 }
Download modules/cms/action/page/PagePubAction.class.php
History Fri, 11 Mar 2022 12:26:33 +0100 dankert Fix: Catch error if something happens while publishing. Sat, 6 Mar 2021 03:42:38 +0100 Jan Dankert New: Better permission checks. Sat, 27 Feb 2021 02:40:09 +0100 Jan Dankert Fix: Use the sourceObjectId from the pageContext for links. Sat, 27 Feb 2021 00:29:39 +0100 Jan Dankert New: Set publishing date on publishing. Sat, 20 Feb 2021 01:34:41 +0100 Jan Dankert New: Publish-switch for templates. Mon, 4 Jan 2021 19:03:18 +0100 Jan Dankert Refactoring: ACL class is renamed to Permission, because most RBAC/DMAC concepts are calling it a permission. Tue, 17 Nov 2020 23:51:00 +0100 Jan Dankert Refactoring: Every Actionmethod has now its own class.