-
Notifications
You must be signed in to change notification settings - Fork 1
/
publish.php
91 lines (76 loc) · 2.46 KB
/
publish.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
use dokuwiki\plugin\struct\meta\Assignments;
use dokuwiki\plugin\structpublish\meta\Constants;
use dokuwiki\plugin\structpublish\meta\Revision;
/**
* DokuWiki Plugin structpublish (Helper Component)
*
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
* @author Anna Dabrowska <dokuwiki@cosmocode.de>
*/
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']]
);
}
}
}