-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
Revision.php
120 lines (105 loc) · 3.12 KB
/
Revision.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* The FAQ revisions class.
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2020-2024 phpMyFAQ Team
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2020-11-01
*/
namespace phpMyFAQ\Administration;
use phpMyFAQ\Configuration;
use phpMyFAQ\Database;
/**
* Class Revision
*
* @package phpMyFAQ
*/
class Revision
{
/**
* Revision constructor.
*/
public function __construct(private readonly Configuration $configuration)
{
}
/**
* Adds a new revision from a given FAQ ID and FAQ language
*/
public function create(int $faqId, string $faqLanguage): bool
{
$query = sprintf(
"
INSERT INTO
%sfaqdata_revisions
SELECT
id, lang, solution_id, revision_id + 1, active, sticky, keywords, thema, content, author, email,
comment, updated, date_start, date_end, created, notes
FROM
%sfaqdata
WHERE
id = %d
AND
laqng = '%s'",
Database::getTablePrefix(),
Database::getTablePrefix(),
$faqId,
$faqLanguage
);
$this->configuration->getDb()->query($query);
return true;
}
/**
* Gets all revisions from a given FAQ ID and FAQ language
*
* @return array<string[]>
*/
public function get(int $faqId, string $faqLanguage, string $faqAuthor): array
{
$revisionData = [];
$query = sprintf(
"SELECT
revision_id, updated, author FROM %sfaqdata_revisions
WHERE
id = %d
AND
lang = '%s'
ORDER BY
revision_id",
Database::getTablePrefix(),
$faqId,
$faqLanguage
);
$result = $this->configuration->getDb()->query($query);
if ($this->configuration->getDb()->numRows($result) > 0) {
while ($row = $this->configuration->getDb()->fetchObject($result)) {
$revisionData[] = [
'revision_id' => $row->revision_id,
'updated' => $faqId === 0 ? date('YmdHis') : $row->updated,
'author' => $faqId === 0 ? ucfirst($faqAuthor) : $row->author,
];
}
}
return $revisionData;
}
/**
* Deletes all revisions for a given FAQ ID and FAQ language
* @return mixed
*/
public function delete(int $faqId, string $faqLanguage)
{
$query = sprintf(
"DELETE FROM %sfaqdata_revisions WHERE id = %d AND lang = '%s'",
Database::getTablePrefix(),
$faqId,
$faqLanguage
);
return $this->configuration->getDb()->query($query);
}
}