PagePubAction.class.php (1986B)
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 }