enwikipedia-acc /
waca
| 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 Exception; |
||
| 13 | use Waca\DataObject; |
||
| 14 | |||
| 15 | class UserDomain extends DataObject |
||
| 16 | { |
||
| 17 | /** @var int */ |
||
| 18 | private $user; |
||
| 19 | |||
| 20 | /** @var int */ |
||
| 21 | private $domain; |
||
| 22 | |||
| 23 | public function save() |
||
| 24 | { |
||
| 25 | if ($this->isNew()) { |
||
| 26 | // insert |
||
| 27 | $statement = $this->dbObject->prepare(<<<SQL |
||
| 28 | INSERT INTO userdomain ( |
||
| 29 | user, domain |
||
| 30 | ) VALUES ( |
||
| 31 | :user, :domain |
||
| 32 | ); |
||
| 33 | SQL |
||
| 34 | ); |
||
| 35 | |||
| 36 | $statement->bindValue(":user", $this->user); |
||
| 37 | $statement->bindValue(":domain", $this->domain); |
||
| 38 | |||
| 39 | if ($statement->execute()) { |
||
| 40 | $this->id = (int)$this->dbObject->lastInsertId(); |
||
| 41 | } |
||
| 42 | else { |
||
| 43 | throw new Exception($statement->errorInfo()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 44 | } |
||
| 45 | } |
||
| 46 | else { |
||
| 47 | // insert / delete only, no updates please. |
||
| 48 | throw new Exception('Updating domain membership is not available'); |
||
| 49 | } |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return int |
||
| 54 | */ |
||
| 55 | public function getUser(): int |
||
| 56 | { |
||
| 57 | return $this->user; |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param int $user |
||
| 62 | */ |
||
| 63 | public function setUser(int $user): void |
||
| 64 | { |
||
| 65 | $this->user = $user; |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return int |
||
| 70 | */ |
||
| 71 | public function getDomain(): int |
||
| 72 | { |
||
| 73 | return $this->domain; |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @param int $domain |
||
| 78 | */ |
||
| 79 | public function setDomain(int $domain): void |
||
| 80 | { |
||
| 81 | $this->domain = $domain; |
||
| 82 | } |
||
| 83 | |||
| 84 | |||
| 85 | } |