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_db */ 8 protected $dbHelper; 9 10 /** 11 * @inheritDoc 12 */ 13 public function register(Doku_Event_Handler $controller) 14 { 15 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleApprove'); 16 $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handlePublish'); 17 } 18 19 public function handlePublish(Doku_Event $event) 20 { 21 if ($event->data != 'show') return; 22 23 $this->dbHelper = plugin_load('helper', 'structpublish_db'); 24 25 global $INPUT; 26 $in = $INPUT->arr('structpublish'); 27 if (!$in || !isset($in[$this->dbHelper::ACTION_PUBLISH])) { 28 return; 29 } 30 31 // FIXME prevent bumping published version 32 33 global $ID; 34 global $INFO; 35 $sqlite = $this->dbHelper->getDB(); 36 $revision = new Revision($sqlite, $ID, $INFO['currentrev']); 37 // TODO do not autoincrement version, make it a string 38 $revision->setVersion($revision->getVersion() + 1); 39 $revision->setUser($_SERVER['REMOTE_USER']); 40 $revision->setStatus(Revision::STATUS_PUBLISHED); 41 $revision->setDate(time()); 42 43 $revision->save(); 44 } 45 46 public function handleApprove(Doku_Event $event) 47 { 48 if ($event->data != 'show') return; 49 50 $this->dbHelper = plugin_load('helper', 'structpublish_db'); 51 52 global $INPUT; 53 $in = $INPUT->arr('structpublish'); 54 if (!$in || !isset($in[$this->dbHelper::ACTION_APPROVE])) { 55 return; 56 } 57 58 global $ID; 59 global $INFO; 60 $sqlite = $this->dbHelper->getDB(); 61 $revision = new Revision($sqlite, $ID, $INFO['currentrev']); 62 $revision->setVersion($revision->getVersion()); 63 $revision->setUser($_SERVER['REMOTE_USER']); 64 $revision->setStatus(Revision::STATUS_APPROVED); 65 $revision->setDate(time()); 66 67 $revision->save(); 68 } 69} 70