1<?php 2 3use dokuwiki\plugin\struct\meta\StructException; 4use dokuwiki\plugin\structpublish\meta\Assignments; 5use dokuwiki\plugin\structpublish\meta\Constants; 6use dokuwiki\plugin\structpublish\meta\Revision; 7 8/** 9 * Action component to handle page save 10 */ 11class action_plugin_structpublish_save extends DokuWiki_Action_Plugin 12{ 13 /** @inheritDoc */ 14 public function register(Doku_Event_Handler $controller) 15 { 16 $controller->register_hook('COMMON_WIKIPAGE_SAVE', 'AFTER', $this, 'handleSave'); 17 } 18 19 /** 20 * Handle the page save event to store revision meta data 21 * 22 * @param Doku_Event $event 23 * @return void 24 */ 25 public function handleSave(Doku_Event $event) 26 { 27 /** @var helper_plugin_structpublish_db $dbHelper */ 28 $dbHelper = plugin_load('helper', 'structpublish_db'); 29 30 $id = $event->data['id']; 31 32 $assignments = Assignments::getInstance(); 33 $assignments->updatePageAssignments($id); 34 35 if (!$dbHelper->isPublishable()) { 36 return; 37 } 38 39 $revision = new Revision($id, $event->data['newRevision']); 40 $revision->setStatus(Constants::STATUS_DRAFT); 41 42 try { 43 $revision->save(); 44 } catch (StructException $e) { 45 msg($e->getMessage(), -1); 46 } 47 } 48} 49