1
|
|
|
<?php |
2
|
|
|
/****************************************************************************** |
3
|
|
|
* Wikipedia Account Creation Assistance tool * |
4
|
|
|
* ACC Development Team. Please see team.json for a list of contributors. * |
5
|
|
|
* * |
6
|
|
|
* This is free and unencumbered software released into the public domain. * |
7
|
|
|
* Please see LICENSE.md for the full licencing statement. * |
8
|
|
|
******************************************************************************/ |
9
|
|
|
|
10
|
|
|
namespace Waca\DataObjects; |
11
|
|
|
|
12
|
|
|
use DateTimeImmutable; |
13
|
|
|
use Exception; |
14
|
|
|
use Waca\DataObject; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class representing a log entry |
18
|
|
|
*/ |
19
|
|
|
class Log extends DataObject |
20
|
|
|
{ |
21
|
|
|
/** @var int */ |
22
|
|
|
private $objectid; |
23
|
|
|
/** @var string */ |
24
|
|
|
private $objecttype; |
25
|
|
|
/** @var int */ |
26
|
|
|
private $user; |
27
|
|
|
/** @var string */ |
28
|
|
|
private $action; |
29
|
|
|
private $timestamp; |
30
|
|
|
/** @var string|null */ |
31
|
|
|
private $comment; |
32
|
|
|
/** @var int|null */ |
33
|
|
|
private $domain; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @throws Exception |
37
|
|
|
*/ |
38
|
|
|
public function save() |
39
|
|
|
{ |
40
|
|
|
if ($this->isNew()) { |
41
|
|
|
$statement = $this->dbObject->prepare(<<<SQL |
42
|
|
|
INSERT INTO log (objectid, objecttype, user, action, timestamp, comment, domain) |
43
|
|
|
VALUES (:id, :type, :user, :action, CURRENT_TIMESTAMP(), :comment, :domain); |
44
|
|
|
SQL |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
$statement->bindValue(":id", $this->objectid); |
48
|
|
|
$statement->bindValue(":type", $this->objecttype); |
49
|
|
|
$statement->bindValue(":user", $this->user); |
50
|
|
|
$statement->bindValue(":action", $this->action); |
51
|
|
|
$statement->bindValue(":comment", $this->comment); |
52
|
|
|
$statement->bindValue(":domain", $this->domain); |
53
|
|
|
|
54
|
|
|
if ($statement->execute()) { |
55
|
|
|
$this->id = (int)$this->dbObject->lastInsertId(); |
56
|
|
|
} |
57
|
|
|
else { |
58
|
|
|
throw new Exception($statement->errorInfo()); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
else { |
62
|
|
|
throw new Exception("Updating logs is not available"); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @throws Exception |
68
|
|
|
*/ |
69
|
|
|
public function delete() |
70
|
|
|
{ |
71
|
|
|
throw new Exception("Deleting logs is not available."); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return int |
76
|
|
|
*/ |
77
|
|
|
public function getObjectId() |
78
|
|
|
{ |
79
|
|
|
return $this->objectid; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Summary of setObjectId |
84
|
|
|
* |
85
|
|
|
* @param int $objectId |
86
|
|
|
*/ |
87
|
|
|
public function setObjectId($objectId) |
88
|
|
|
{ |
89
|
|
|
$this->objectid = $objectId; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
public function getObjectType() |
96
|
|
|
{ |
97
|
|
|
return $this->objecttype; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Summary of setObjectType |
102
|
|
|
* |
103
|
|
|
* @param string $objectType |
104
|
|
|
*/ |
105
|
|
|
public function setObjectType($objectType) |
106
|
|
|
{ |
107
|
|
|
$this->objecttype = $objectType; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return int |
112
|
|
|
*/ |
113
|
|
|
public function getUser() |
114
|
|
|
{ |
115
|
|
|
return $this->user; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Summary of setUser |
120
|
|
|
* |
121
|
|
|
* @param User $user |
122
|
|
|
*/ |
123
|
|
|
public function setUser(User $user) |
124
|
|
|
{ |
125
|
|
|
$this->user = $user->getId(); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @return string |
130
|
|
|
*/ |
131
|
|
|
public function getAction() |
132
|
|
|
{ |
133
|
|
|
return $this->action; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Summary of setAction |
138
|
|
|
* |
139
|
|
|
* @param string $action |
140
|
|
|
*/ |
141
|
|
|
public function setAction($action) |
142
|
|
|
{ |
143
|
|
|
$this->action = $action; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return DateTimeImmutable |
148
|
|
|
*/ |
149
|
|
|
public function getTimestamp() |
150
|
|
|
{ |
151
|
|
|
return new DateTimeImmutable($this->timestamp); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @return string|null |
156
|
|
|
*/ |
157
|
|
|
public function getComment() |
158
|
|
|
{ |
159
|
|
|
return $this->comment; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Summary of setComment |
164
|
|
|
* |
165
|
|
|
* @param string $comment |
166
|
|
|
*/ |
167
|
|
|
public function setComment($comment) |
168
|
|
|
{ |
169
|
|
|
$this->comment = $comment; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getDomain(): ?int |
173
|
|
|
{ |
174
|
|
|
return $this->domain; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setDomain(?int $domain): void |
178
|
|
|
{ |
179
|
|
|
$this->domain = $domain; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|