*/ class helper_plugin_structpublish_publish extends DokuWiki_Plugin { /** @var helper_plugin_structpublish_db */ protected $dbHelper; public function __construct() { $this->dbHelper = plugin_load('helper', 'structpublish_db'); } /** * Save publish data * * @param string $action * @return Revision * @throws Exception */ public function saveRevision($action, $newversion = '') { global $ID; global $INFO; if (!$this->dbHelper->checkAccess($ID, [$action])) { throw new \Exception('User may not ' . $action); } $revision = new Revision($ID, $INFO['currentrev']); if ($action === Constants::ACTION_PUBLISH) { $revision->setVersion($newversion); } $revision->setUser($_SERVER['REMOTE_USER']); $revision->setStatus(Constants::transitionBy($action)); $revision->setTimestamp(time()); $revision->save(); if ($action === Constants::ACTION_PUBLISH) { $this->updateSchemaData(); } return $revision; } /** * Set "published" status in all assigned schemas * * @return void */ protected function updateSchemaData() { global $ID; global $INFO; $schemaAssignments = Assignments::getInstance(); $tables = $schemaAssignments->getPageAssignments($ID); if (empty($tables)) { return; } $sqlite = $this->dbHelper->getDB(); foreach ($tables as $table) { // unpublish earlier revisions $sqlite->query("UPDATE data_$table SET published = 0 WHERE pid = ?", [$ID]); $sqlite->query("UPDATE multi_$table SET published = 0 WHERE pid = ?", [$ID]); // publish the current revision $sqlite->query( "UPDATE data_$table SET published = 1 WHERE pid = ? AND rev = ?", [$ID, $INFO['currentrev']] ); $sqlite->query( "UPDATE multi_$table SET published = 1 WHERE pid = ? AND rev = ?", [$ID, $INFO['currentrev']] ); } } }