1<?php 2 3use dokuwiki\plugin\structpublish\meta\Revision; 4 5class action_plugin_structpublish_publish extends DokuWiki_Action_Plugin 6{ 7 /** @var \helper_plugin_structpublish_permissions */ 8 protected $permissionsHelper; 9 10 /** 11 * @inheritDoc 12 */ 13 public function register(Doku_Event_Handler $controller) 14 { 15 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handlePublish'); 16 } 17 18 public function handlePublish(Doku_Event $event) 19 { 20 if ($event->data != 'show') return; 21 22 global $INPUT; 23 $in = $INPUT->arr('structpublish'); 24 if (!$in || !$in[\helper_plugin_structpublish_permissions::ACTION_PUBLISH]) { 25 return; 26 } 27 28 // FIXME prevent bumping published version 29 30 $this->permissionsHelper = plugin_load('helper', 'structpublish_permissions'); 31 32 global $ID; 33 global $INFO; 34 $sqlite = $this->permissionsHelper->getDb(); 35 $revision = new Revision($sqlite, $ID, $INFO['currentrev']); 36 // TODO do not autoincrement version, make it a string 37 $revision->setVersion($revision->getVersion() + 1); 38 $revision->setUser($_SERVER['REMOTE_USER']); 39 $revision->setStatus(Revision::STATUS_PUBLISHED); 40 $revision->setDate(time()); 41 42 $revision->save(); 43 } 44} 45