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