@@ -12,16 +12,16 @@ |
||
| 12 | 12 | |
| 13 | 13 | class FakeBlacklistHelper implements IBlacklistHelper |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 17 | - * |
|
| 18 | - * @param string $username |
|
| 19 | - * |
|
| 20 | - * @return bool |
|
| 21 | - */ |
|
| 22 | - public function isBlacklisted($username) |
|
| 23 | - { |
|
| 24 | - // Short-circuit |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 15 | + /** |
|
| 16 | + * Returns a value indicating whether the provided username is blacklisted by the on-wiki title blacklist |
|
| 17 | + * |
|
| 18 | + * @param string $username |
|
| 19 | + * |
|
| 20 | + * @return bool |
|
| 21 | + */ |
|
| 22 | + public function isBlacklisted($username) |
|
| 23 | + { |
|
| 24 | + // Short-circuit |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -13,80 +13,80 @@ |
||
| 13 | 13 | |
| 14 | 14 | class JobQueueSearchHelper extends SearchHelperBase |
| 15 | 15 | { |
| 16 | - protected function __construct(PdoDatabase $database) |
|
| 17 | - { |
|
| 18 | - parent::__construct($database, 'jobqueue', JobQueue::class, null); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param PdoDatabase $database |
|
| 23 | - * |
|
| 24 | - * @return JobQueueSearchHelper |
|
| 25 | - */ |
|
| 26 | - public static function get(PdoDatabase $database) |
|
| 27 | - { |
|
| 28 | - $helper = new JobQueueSearchHelper($database); |
|
| 29 | - return $helper; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param string[] $statuses |
|
| 34 | - * |
|
| 35 | - * @return $this |
|
| 36 | - */ |
|
| 37 | - public function statusIn($statuses) |
|
| 38 | - { |
|
| 39 | - $this->inClause('status', $statuses); |
|
| 40 | - |
|
| 41 | - return $this; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function notAcknowledged() |
|
| 48 | - { |
|
| 49 | - $this->whereClause .= ' AND (acknowledged IS NULL OR acknowledged = 0)'; |
|
| 50 | - |
|
| 51 | - return $this; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function byTask($task) |
|
| 55 | - { |
|
| 56 | - $this->whereClause .= ' AND task = ?'; |
|
| 57 | - $this->parameterList[] = $task; |
|
| 58 | - |
|
| 59 | - return $this; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - public function byUser($userId) |
|
| 63 | - { |
|
| 64 | - $this->whereClause .= ' AND user = ?'; |
|
| 65 | - $this->parameterList[] = $userId; |
|
| 66 | - |
|
| 67 | - return $this; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - public function byStatus($status) |
|
| 71 | - { |
|
| 72 | - $this->whereClause .= ' AND status = ?'; |
|
| 73 | - $this->parameterList[] = $status; |
|
| 74 | - |
|
| 75 | - return $this; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - public function byRequest(int $request) : JobQueueSearchHelper |
|
| 79 | - { |
|
| 80 | - $this->whereClause .= ' AND request = ?'; |
|
| 81 | - $this->parameterList[] = $request; |
|
| 82 | - |
|
| 83 | - return $this; |
|
| 84 | - } |
|
| 16 | + protected function __construct(PdoDatabase $database) |
|
| 17 | + { |
|
| 18 | + parent::__construct($database, 'jobqueue', JobQueue::class, null); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param PdoDatabase $database |
|
| 23 | + * |
|
| 24 | + * @return JobQueueSearchHelper |
|
| 25 | + */ |
|
| 26 | + public static function get(PdoDatabase $database) |
|
| 27 | + { |
|
| 28 | + $helper = new JobQueueSearchHelper($database); |
|
| 29 | + return $helper; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param string[] $statuses |
|
| 34 | + * |
|
| 35 | + * @return $this |
|
| 36 | + */ |
|
| 37 | + public function statusIn($statuses) |
|
| 38 | + { |
|
| 39 | + $this->inClause('status', $statuses); |
|
| 40 | + |
|
| 41 | + return $this; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function notAcknowledged() |
|
| 48 | + { |
|
| 49 | + $this->whereClause .= ' AND (acknowledged IS NULL OR acknowledged = 0)'; |
|
| 50 | + |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function byTask($task) |
|
| 55 | + { |
|
| 56 | + $this->whereClause .= ' AND task = ?'; |
|
| 57 | + $this->parameterList[] = $task; |
|
| 58 | + |
|
| 59 | + return $this; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + public function byUser($userId) |
|
| 63 | + { |
|
| 64 | + $this->whereClause .= ' AND user = ?'; |
|
| 65 | + $this->parameterList[] = $userId; |
|
| 66 | + |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + public function byStatus($status) |
|
| 71 | + { |
|
| 72 | + $this->whereClause .= ' AND status = ?'; |
|
| 73 | + $this->parameterList[] = $status; |
|
| 74 | + |
|
| 75 | + return $this; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + public function byRequest(int $request) : JobQueueSearchHelper |
|
| 79 | + { |
|
| 80 | + $this->whereClause .= ' AND request = ?'; |
|
| 81 | + $this->parameterList[] = $request; |
|
| 82 | + |
|
| 83 | + return $this; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - public function newestFirst() |
|
| 87 | - { |
|
| 88 | - $this->orderBy = 'id DESC'; |
|
| 86 | + public function newestFirst() |
|
| 87 | + { |
|
| 88 | + $this->orderBy = 'id DESC'; |
|
| 89 | 89 | |
| 90 | - return $this; |
|
| 91 | - } |
|
| 90 | + return $this; |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -13,87 +13,87 @@ |
||
| 13 | 13 | |
| 14 | 14 | class LogSearchHelper extends SearchHelperBase |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * LogSearchHelper constructor. |
|
| 18 | - * |
|
| 19 | - * @param PdoDatabase $database |
|
| 20 | - */ |
|
| 21 | - protected function __construct(PdoDatabase $database) |
|
| 22 | - { |
|
| 23 | - parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
| 24 | - } |
|
| 16 | + /** |
|
| 17 | + * LogSearchHelper constructor. |
|
| 18 | + * |
|
| 19 | + * @param PdoDatabase $database |
|
| 20 | + */ |
|
| 21 | + protected function __construct(PdoDatabase $database) |
|
| 22 | + { |
|
| 23 | + parent::__construct($database, 'log', Log::class, 'timestamp DESC'); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Initiates a search for requests |
|
| 28 | - * |
|
| 29 | - * @param PdoDatabase $database |
|
| 30 | - * |
|
| 31 | - * @return LogSearchHelper |
|
| 32 | - */ |
|
| 33 | - public static function get(PdoDatabase $database) |
|
| 34 | - { |
|
| 35 | - $helper = new LogSearchHelper($database); |
|
| 26 | + /** |
|
| 27 | + * Initiates a search for requests |
|
| 28 | + * |
|
| 29 | + * @param PdoDatabase $database |
|
| 30 | + * |
|
| 31 | + * @return LogSearchHelper |
|
| 32 | + */ |
|
| 33 | + public static function get(PdoDatabase $database) |
|
| 34 | + { |
|
| 35 | + $helper = new LogSearchHelper($database); |
|
| 36 | 36 | |
| 37 | - return $helper; |
|
| 38 | - } |
|
| 37 | + return $helper; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Filters the results by user |
|
| 42 | - * |
|
| 43 | - * @param int $userId |
|
| 44 | - * |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function byUser($userId) |
|
| 48 | - { |
|
| 49 | - $this->whereClause .= ' AND user = ?'; |
|
| 50 | - $this->parameterList[] = $userId; |
|
| 40 | + /** |
|
| 41 | + * Filters the results by user |
|
| 42 | + * |
|
| 43 | + * @param int $userId |
|
| 44 | + * |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function byUser($userId) |
|
| 48 | + { |
|
| 49 | + $this->whereClause .= ' AND user = ?'; |
|
| 50 | + $this->parameterList[] = $userId; |
|
| 51 | 51 | |
| 52 | - return $this; |
|
| 53 | - } |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Filters the results by log action |
|
| 57 | - * |
|
| 58 | - * @param string $action |
|
| 59 | - * |
|
| 60 | - * @return $this |
|
| 61 | - */ |
|
| 62 | - public function byAction($action) |
|
| 63 | - { |
|
| 64 | - $this->whereClause .= ' AND action = ?'; |
|
| 65 | - $this->parameterList[] = $action; |
|
| 55 | + /** |
|
| 56 | + * Filters the results by log action |
|
| 57 | + * |
|
| 58 | + * @param string $action |
|
| 59 | + * |
|
| 60 | + * @return $this |
|
| 61 | + */ |
|
| 62 | + public function byAction($action) |
|
| 63 | + { |
|
| 64 | + $this->whereClause .= ' AND action = ?'; |
|
| 65 | + $this->parameterList[] = $action; |
|
| 66 | 66 | |
| 67 | - return $this; |
|
| 68 | - } |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * Filters the results by object type |
|
| 72 | - * |
|
| 73 | - * @param string $objectType |
|
| 74 | - * |
|
| 75 | - * @return $this |
|
| 76 | - */ |
|
| 77 | - public function byObjectType($objectType) |
|
| 78 | - { |
|
| 79 | - $this->whereClause .= ' AND objecttype = ?'; |
|
| 80 | - $this->parameterList[] = $objectType; |
|
| 70 | + /** |
|
| 71 | + * Filters the results by object type |
|
| 72 | + * |
|
| 73 | + * @param string $objectType |
|
| 74 | + * |
|
| 75 | + * @return $this |
|
| 76 | + */ |
|
| 77 | + public function byObjectType($objectType) |
|
| 78 | + { |
|
| 79 | + $this->whereClause .= ' AND objecttype = ?'; |
|
| 80 | + $this->parameterList[] = $objectType; |
|
| 81 | 81 | |
| 82 | - return $this; |
|
| 83 | - } |
|
| 82 | + return $this; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Filters the results by object type |
|
| 87 | - * |
|
| 88 | - * @param integer $objectId |
|
| 89 | - * |
|
| 90 | - * @return $this |
|
| 91 | - */ |
|
| 92 | - public function byObjectId($objectId) |
|
| 93 | - { |
|
| 94 | - $this->whereClause .= ' AND objectid = ?'; |
|
| 95 | - $this->parameterList[] = $objectId; |
|
| 85 | + /** |
|
| 86 | + * Filters the results by object type |
|
| 87 | + * |
|
| 88 | + * @param integer $objectId |
|
| 89 | + * |
|
| 90 | + * @return $this |
|
| 91 | + */ |
|
| 92 | + public function byObjectId($objectId) |
|
| 93 | + { |
|
| 94 | + $this->whereClause .= ' AND objectid = ?'; |
|
| 95 | + $this->parameterList[] = $objectId; |
|
| 96 | 96 | |
| 97 | - return $this; |
|
| 98 | - } |
|
| 97 | + return $this; |
|
| 98 | + } |
|
| 99 | 99 | } |
| 100 | 100 | \ No newline at end of file |
@@ -15,73 +15,73 @@ discard block |
||
| 15 | 15 | |
| 16 | 16 | class UserSearchHelper extends SearchHelperBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * UserSearchHelper constructor. |
|
| 20 | - * |
|
| 21 | - * @param PdoDatabase $database |
|
| 22 | - */ |
|
| 23 | - public function __construct(PdoDatabase $database) |
|
| 24 | - { |
|
| 25 | - parent::__construct($database, 'user', User::class); |
|
| 26 | - } |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Initiates a search for requests |
|
| 30 | - * |
|
| 31 | - * @param PdoDatabase $database |
|
| 32 | - * |
|
| 33 | - * @return UserSearchHelper |
|
| 34 | - */ |
|
| 35 | - public static function get(PdoDatabase $database) |
|
| 36 | - { |
|
| 37 | - $helper = new UserSearchHelper($database); |
|
| 38 | - |
|
| 39 | - return $helper; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param string $status |
|
| 44 | - * |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function byStatus($status) |
|
| 48 | - { |
|
| 49 | - $this->whereClause .= ' AND status = ?'; |
|
| 50 | - $this->parameterList[] = $status; |
|
| 51 | - |
|
| 52 | - return $this; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - public function statusIn($statuses) |
|
| 56 | - { |
|
| 57 | - $this->inClause('status', $statuses); |
|
| 58 | - |
|
| 59 | - return $this; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param string $role |
|
| 64 | - * |
|
| 65 | - * @return $this |
|
| 66 | - */ |
|
| 67 | - public function byRole($role) |
|
| 68 | - { |
|
| 69 | - $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
| 70 | - $this->whereClause .= ' AND r.role = ?'; |
|
| 71 | - $this->parameterList[] = $role; |
|
| 72 | - |
|
| 73 | - return $this; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param DateTime $instant |
|
| 78 | - * |
|
| 79 | - * @return $this |
|
| 80 | - */ |
|
| 81 | - public function lastActiveBefore(DateTime $instant) |
|
| 82 | - { |
|
| 83 | - $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
| 84 | - $this->joinClause .= <<<'SQLFRAG' |
|
| 18 | + /** |
|
| 19 | + * UserSearchHelper constructor. |
|
| 20 | + * |
|
| 21 | + * @param PdoDatabase $database |
|
| 22 | + */ |
|
| 23 | + public function __construct(PdoDatabase $database) |
|
| 24 | + { |
|
| 25 | + parent::__construct($database, 'user', User::class); |
|
| 26 | + } |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Initiates a search for requests |
|
| 30 | + * |
|
| 31 | + * @param PdoDatabase $database |
|
| 32 | + * |
|
| 33 | + * @return UserSearchHelper |
|
| 34 | + */ |
|
| 35 | + public static function get(PdoDatabase $database) |
|
| 36 | + { |
|
| 37 | + $helper = new UserSearchHelper($database); |
|
| 38 | + |
|
| 39 | + return $helper; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param string $status |
|
| 44 | + * |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function byStatus($status) |
|
| 48 | + { |
|
| 49 | + $this->whereClause .= ' AND status = ?'; |
|
| 50 | + $this->parameterList[] = $status; |
|
| 51 | + |
|
| 52 | + return $this; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + public function statusIn($statuses) |
|
| 56 | + { |
|
| 57 | + $this->inClause('status', $statuses); |
|
| 58 | + |
|
| 59 | + return $this; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param string $role |
|
| 64 | + * |
|
| 65 | + * @return $this |
|
| 66 | + */ |
|
| 67 | + public function byRole($role) |
|
| 68 | + { |
|
| 69 | + $this->joinClause .= ' INNER JOIN userrole r on origin.id = r.user'; |
|
| 70 | + $this->whereClause .= ' AND r.role = ?'; |
|
| 71 | + $this->parameterList[] = $role; |
|
| 72 | + |
|
| 73 | + return $this; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param DateTime $instant |
|
| 78 | + * |
|
| 79 | + * @return $this |
|
| 80 | + */ |
|
| 81 | + public function lastActiveBefore(DateTime $instant) |
|
| 82 | + { |
|
| 83 | + $this->whereClause .= ' AND origin.lastactive < ? AND approvaldate.timestamp < ?'; |
|
| 84 | + $this->joinClause .= <<<'SQLFRAG' |
|
| 85 | 85 | LEFT JOIN ( |
| 86 | 86 | SELECT objectid, MAX(timestamp) timestamp |
| 87 | 87 | FROM log |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | GROUP BY objectid |
| 90 | 90 | ) approvaldate ON approvaldate.objectid = origin.id |
| 91 | 91 | SQLFRAG; |
| 92 | - $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
| 93 | - $this->parameterList[] = $formattedDate; |
|
| 94 | - $this->parameterList[] = $formattedDate; |
|
| 92 | + $formattedDate = $instant->format("Y-m-d H:i:s"); |
|
| 93 | + $this->parameterList[] = $formattedDate; |
|
| 94 | + $this->parameterList[] = $formattedDate; |
|
| 95 | 95 | |
| 96 | - return $this; |
|
| 97 | - } |
|
| 96 | + return $this; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - public function getRoleMap(&$roleMap) |
|
| 100 | - { |
|
| 101 | - $query = <<<SQL |
|
| 99 | + public function getRoleMap(&$roleMap) |
|
| 100 | + { |
|
| 101 | + $query = <<<SQL |
|
| 102 | 102 | SELECT /* UserSearchHelper/roleMap */ |
| 103 | 103 | r.user user |
| 104 | 104 | , group_concat(r.role SEPARATOR ', ') roles |
@@ -107,22 +107,22 @@ discard block |
||
| 107 | 107 | GROUP BY r.user |
| 108 | 108 | SQL; |
| 109 | 109 | |
| 110 | - $statement = $this->database->prepare($query); |
|
| 111 | - $statement->execute($this->parameterList); |
|
| 110 | + $statement = $this->database->prepare($query); |
|
| 111 | + $statement->execute($this->parameterList); |
|
| 112 | 112 | |
| 113 | - $roleMap = array(); |
|
| 114 | - foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 115 | - $roleMap[$row['user']] = $row['roles']; |
|
| 116 | - } |
|
| 113 | + $roleMap = array(); |
|
| 114 | + foreach ($statement->fetchAll(PDO::FETCH_ASSOC) as $row) { |
|
| 115 | + $roleMap[$row['user']] = $row['roles']; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return $this; |
|
| 119 | - } |
|
| 118 | + return $this; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - public function withReservedRequest() |
|
| 122 | - { |
|
| 123 | - $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
| 124 | - $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
| 121 | + public function withReservedRequest() |
|
| 122 | + { |
|
| 123 | + $this->joinClause = ' INNER JOIN request req ON req.reserved = origin.id'; |
|
| 124 | + $this->groupByClause = ' GROUP BY origin.id, origin.username'; |
|
| 125 | 125 | |
| 126 | - return $this->fetchMap('username'); |
|
| 127 | - } |
|
| 126 | + return $this->fetchMap('username'); |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -13,53 +13,53 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class DebugHelper |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Internal mockable method wrapper for debug_backtrace. |
|
| 18 | - * |
|
| 19 | - * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive |
|
| 20 | - * cascade until the runtime explodes. |
|
| 21 | - * |
|
| 22 | - * Instead, we mock this method, which allows debug_backtrace to still be called correctly. |
|
| 23 | - * |
|
| 24 | - * @return array |
|
| 25 | - */ |
|
| 26 | - public function get_debug_backtrace() |
|
| 27 | - { |
|
| 28 | - return debug_backtrace(); |
|
| 29 | - } |
|
| 16 | + /** |
|
| 17 | + * Internal mockable method wrapper for debug_backtrace. |
|
| 18 | + * |
|
| 19 | + * As mocking out debug_backtrace uses debug_backtrace internally, we need this in order to not cause a recursive |
|
| 20 | + * cascade until the runtime explodes. |
|
| 21 | + * |
|
| 22 | + * Instead, we mock this method, which allows debug_backtrace to still be called correctly. |
|
| 23 | + * |
|
| 24 | + * @return array |
|
| 25 | + */ |
|
| 26 | + public function get_debug_backtrace() |
|
| 27 | + { |
|
| 28 | + return debug_backtrace(); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns a string representation of the current backtrace for display. |
|
| 33 | - * |
|
| 34 | - * Note that this explicitly excludes the top two frames, which will be methods from this class. |
|
| 35 | - * |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function getBacktrace() |
|
| 39 | - { |
|
| 40 | - $backtrace = $this->get_debug_backtrace(); |
|
| 31 | + /** |
|
| 32 | + * Returns a string representation of the current backtrace for display. |
|
| 33 | + * |
|
| 34 | + * Note that this explicitly excludes the top two frames, which will be methods from this class. |
|
| 35 | + * |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function getBacktrace() |
|
| 39 | + { |
|
| 40 | + $backtrace = $this->get_debug_backtrace(); |
|
| 41 | 41 | |
| 42 | - $output = ""; |
|
| 42 | + $output = ""; |
|
| 43 | 43 | |
| 44 | - $count = 0; |
|
| 45 | - foreach ($backtrace as $line) { |
|
| 46 | - if ($count <= 1) { |
|
| 47 | - $count++; |
|
| 48 | - continue; |
|
| 49 | - } |
|
| 44 | + $count = 0; |
|
| 45 | + foreach ($backtrace as $line) { |
|
| 46 | + if ($count <= 1) { |
|
| 47 | + $count++; |
|
| 48 | + continue; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $output .= "#{$count}: "; |
|
| 51 | + $output .= "#{$count}: "; |
|
| 52 | 52 | |
| 53 | - if (isset($line['type']) && $line['type'] != "") { |
|
| 54 | - $output .= $line['class'] . $line['type']; |
|
| 55 | - } |
|
| 53 | + if (isset($line['type']) && $line['type'] != "") { |
|
| 54 | + $output .= $line['class'] . $line['type']; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $output .= $line['function'] . "(...)"; |
|
| 58 | - $output .= " [{$line['file']}#{$line['line']}\r\n"; |
|
| 57 | + $output .= $line['function'] . "(...)"; |
|
| 58 | + $output .= " [{$line['file']}#{$line['line']}\r\n"; |
|
| 59 | 59 | |
| 60 | - $count++; |
|
| 61 | - } |
|
| 60 | + $count++; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return $output; |
|
| 64 | - } |
|
| 63 | + return $output; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -14,14 +14,14 @@ |
||
| 14 | 14 | |
| 15 | 15 | class UserCreationTask extends CreationTaskBase |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * @return IMediaWikiClient |
|
| 19 | - */ |
|
| 20 | - protected function getMediaWikiClient() |
|
| 21 | - { |
|
| 22 | - $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
| 23 | - $this->getSiteConfiguration()); |
|
| 17 | + /** |
|
| 18 | + * @return IMediaWikiClient |
|
| 19 | + */ |
|
| 20 | + protected function getMediaWikiClient() |
|
| 21 | + { |
|
| 22 | + $oauth = new OAuthUserHelper($this->getTriggerUser(), $this->getDatabase(), $this->getOauthProtocolHelper(), |
|
| 23 | + $this->getSiteConfiguration()); |
|
| 24 | 24 | |
| 25 | - return $oauth; |
|
| 26 | - } |
|
| 25 | + return $oauth; |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | \ No newline at end of file |
@@ -20,83 +20,83 @@ |
||
| 20 | 20 | |
| 21 | 21 | class WelcomeUserTask extends BackgroundTaskBase |
| 22 | 22 | { |
| 23 | - /** @var Request */ |
|
| 24 | - private $request; |
|
| 25 | - |
|
| 26 | - public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
| 27 | - { |
|
| 28 | - $job = new JobQueue(); |
|
| 29 | - $job->setDatabase($database); |
|
| 30 | - $job->setTask(WelcomeUserTask::class); |
|
| 31 | - $job->setRequest($request->getId()); |
|
| 32 | - $job->setTriggerUserId($triggerUser->getId()); |
|
| 33 | - $job->save(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function execute() |
|
| 37 | - { |
|
| 38 | - $database = $this->getDatabase(); |
|
| 39 | - $this->request = $this->getRequest(); |
|
| 40 | - $user = $this->getTriggerUser(); |
|
| 41 | - |
|
| 42 | - if ($user->getWelcomeTemplate() === null) { |
|
| 43 | - $this->markFailed('Welcome template not specified'); |
|
| 44 | - |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** @var WelcomeTemplate $template */ |
|
| 49 | - $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
| 50 | - |
|
| 51 | - if ($template === false) { |
|
| 52 | - $this->markFailed('Welcome template missing'); |
|
| 53 | - |
|
| 54 | - return; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
| 58 | - $this->getSiteConfiguration()); |
|
| 59 | - $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
| 60 | - |
|
| 61 | - if ($this->request->getStatus() !== RequestStatus::CLOSED) { |
|
| 62 | - $this->markFailed('Request is currently open'); |
|
| 63 | - |
|
| 64 | - return; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if (!$mediaWikiHelper->checkAccountExists($this->request->getName())) { |
|
| 68 | - $this->markFailed('Account does not exist!'); |
|
| 69 | - |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $this->performWelcome($template, $this->request, $user, $mediaWikiHelper); |
|
| 74 | - $this->markComplete(); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * Performs the welcome |
|
| 79 | - * |
|
| 80 | - * @param WelcomeTemplate $template |
|
| 81 | - * @param Request $request |
|
| 82 | - * @param User $user The user who triggered the job |
|
| 83 | - * @param MediaWikiHelper $mediaWikiHelper |
|
| 84 | - */ |
|
| 85 | - private function performWelcome( |
|
| 86 | - WelcomeTemplate $template, |
|
| 87 | - Request $request, |
|
| 88 | - User $user, |
|
| 89 | - MediaWikiHelper $mediaWikiHelper |
|
| 90 | - ) { |
|
| 91 | - $templateText = $template->getBotCodeForWikiSave($request->getName(), $user->getOnWikiName()); |
|
| 92 | - |
|
| 93 | - $mediaWikiHelper->addTalkPageMessage($request->getName(), $template->getSectionHeader(), 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - protected function markFailed($reason = null, bool $acknowledged = false) |
|
| 97 | - { |
|
| 98 | - $this->getNotificationHelper()->requestWelcomeFailed($this->request, $this->getTriggerUser()); |
|
| 99 | - |
|
| 100 | - parent::markFailed($reason, $acknowledged); |
|
| 101 | - } |
|
| 23 | + /** @var Request */ |
|
| 24 | + private $request; |
|
| 25 | + |
|
| 26 | + public static function enqueue(User $triggerUser, Request $request, PdoDatabase $database) |
|
| 27 | + { |
|
| 28 | + $job = new JobQueue(); |
|
| 29 | + $job->setDatabase($database); |
|
| 30 | + $job->setTask(WelcomeUserTask::class); |
|
| 31 | + $job->setRequest($request->getId()); |
|
| 32 | + $job->setTriggerUserId($triggerUser->getId()); |
|
| 33 | + $job->save(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function execute() |
|
| 37 | + { |
|
| 38 | + $database = $this->getDatabase(); |
|
| 39 | + $this->request = $this->getRequest(); |
|
| 40 | + $user = $this->getTriggerUser(); |
|
| 41 | + |
|
| 42 | + if ($user->getWelcomeTemplate() === null) { |
|
| 43 | + $this->markFailed('Welcome template not specified'); |
|
| 44 | + |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** @var WelcomeTemplate $template */ |
|
| 49 | + $template = WelcomeTemplate::getById($user->getWelcomeTemplate(), $database); |
|
| 50 | + |
|
| 51 | + if ($template === false) { |
|
| 52 | + $this->markFailed('Welcome template missing'); |
|
| 53 | + |
|
| 54 | + return; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $oauth = new OAuthUserHelper($user, $database, $this->getOauthProtocolHelper(), |
|
| 58 | + $this->getSiteConfiguration()); |
|
| 59 | + $mediaWikiHelper = new MediaWikiHelper($oauth, $this->getSiteConfiguration()); |
|
| 60 | + |
|
| 61 | + if ($this->request->getStatus() !== RequestStatus::CLOSED) { |
|
| 62 | + $this->markFailed('Request is currently open'); |
|
| 63 | + |
|
| 64 | + return; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if (!$mediaWikiHelper->checkAccountExists($this->request->getName())) { |
|
| 68 | + $this->markFailed('Account does not exist!'); |
|
| 69 | + |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $this->performWelcome($template, $this->request, $user, $mediaWikiHelper); |
|
| 74 | + $this->markComplete(); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * Performs the welcome |
|
| 79 | + * |
|
| 80 | + * @param WelcomeTemplate $template |
|
| 81 | + * @param Request $request |
|
| 82 | + * @param User $user The user who triggered the job |
|
| 83 | + * @param MediaWikiHelper $mediaWikiHelper |
|
| 84 | + */ |
|
| 85 | + private function performWelcome( |
|
| 86 | + WelcomeTemplate $template, |
|
| 87 | + Request $request, |
|
| 88 | + User $user, |
|
| 89 | + MediaWikiHelper $mediaWikiHelper |
|
| 90 | + ) { |
|
| 91 | + $templateText = $template->getBotCodeForWikiSave($request->getName(), $user->getOnWikiName()); |
|
| 92 | + |
|
| 93 | + $mediaWikiHelper->addTalkPageMessage($request->getName(), $template->getSectionHeader(), 'Welcoming user created through [[WP:ACC]]', $templateText); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + protected function markFailed($reason = null, bool $acknowledged = false) |
|
| 97 | + { |
|
| 98 | + $this->getNotificationHelper()->requestWelcomeFailed($this->request, $this->getTriggerUser()); |
|
| 99 | + |
|
| 100 | + parent::markFailed($reason, $acknowledged); |
|
| 101 | + } |
|
| 102 | 102 | } |
| 103 | 103 | \ No newline at end of file |
@@ -23,268 +23,268 @@ |
||
| 23 | 23 | |
| 24 | 24 | abstract class BackgroundTaskBase |
| 25 | 25 | { |
| 26 | - /** @var JobQueue */ |
|
| 27 | - private $job; |
|
| 28 | - /** @var PdoDatabase */ |
|
| 29 | - private $database; |
|
| 30 | - /** @var IOAuthProtocolHelper */ |
|
| 31 | - private $oauthProtocolHelper; |
|
| 32 | - /** @var SiteConfiguration */ |
|
| 33 | - private $siteConfiguration; |
|
| 34 | - /** @var IEmailHelper */ |
|
| 35 | - private $emailHelper; |
|
| 36 | - /** @var HttpHelper */ |
|
| 37 | - private $httpHelper; |
|
| 38 | - /** @var IrcNotificationHelper */ |
|
| 39 | - private $notificationHelper; |
|
| 40 | - /** @var User */ |
|
| 41 | - private $triggerUser; |
|
| 42 | - /** @var Request */ |
|
| 43 | - private $request; |
|
| 44 | - /** @var EmailTemplate */ |
|
| 45 | - private $emailTemplate = null; |
|
| 46 | - /** @var mixed */ |
|
| 47 | - private $parameters; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @return JobQueue |
|
| 51 | - */ |
|
| 52 | - public function getJob() |
|
| 53 | - { |
|
| 54 | - return $this->job; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @param JobQueue $job |
|
| 59 | - */ |
|
| 60 | - public function setJob(JobQueue $job) |
|
| 61 | - { |
|
| 62 | - $this->job = $job; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @return PdoDatabase |
|
| 67 | - */ |
|
| 68 | - public function getDatabase() |
|
| 69 | - { |
|
| 70 | - return $this->database; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @param PdoDatabase $database |
|
| 75 | - */ |
|
| 76 | - public function setDatabase(PdoDatabase $database) |
|
| 77 | - { |
|
| 78 | - $this->database = $database; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @return IOAuthProtocolHelper |
|
| 83 | - */ |
|
| 84 | - public function getOauthProtocolHelper() |
|
| 85 | - { |
|
| 86 | - return $this->oauthProtocolHelper; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 91 | - */ |
|
| 92 | - public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
| 93 | - { |
|
| 94 | - $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @return SiteConfiguration |
|
| 99 | - */ |
|
| 100 | - public function getSiteConfiguration() |
|
| 101 | - { |
|
| 102 | - return $this->siteConfiguration; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @param SiteConfiguration $siteConfiguration |
|
| 107 | - */ |
|
| 108 | - public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
| 109 | - { |
|
| 110 | - $this->siteConfiguration = $siteConfiguration; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @return HttpHelper |
|
| 115 | - */ |
|
| 116 | - public function getHttpHelper() |
|
| 117 | - { |
|
| 118 | - return $this->httpHelper; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * @param HttpHelper $httpHelper |
|
| 123 | - */ |
|
| 124 | - public function setHttpHelper(HttpHelper $httpHelper) |
|
| 125 | - { |
|
| 126 | - $this->httpHelper = $httpHelper; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @return IEmailHelper |
|
| 131 | - */ |
|
| 132 | - public function getEmailHelper() |
|
| 133 | - { |
|
| 134 | - return $this->emailHelper; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @param IEmailHelper $emailHelper |
|
| 139 | - */ |
|
| 140 | - public function setEmailHelper(IEmailHelper $emailHelper) |
|
| 141 | - { |
|
| 142 | - $this->emailHelper = $emailHelper; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * @return IrcNotificationHelper |
|
| 147 | - */ |
|
| 148 | - public function getNotificationHelper() |
|
| 149 | - { |
|
| 150 | - return $this->notificationHelper; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @param IrcNotificationHelper $notificationHelper |
|
| 155 | - */ |
|
| 156 | - public function setNotificationHelper($notificationHelper) |
|
| 157 | - { |
|
| 158 | - $this->notificationHelper = $notificationHelper; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * @return void |
|
| 163 | - */ |
|
| 164 | - protected abstract function execute(); |
|
| 165 | - |
|
| 166 | - public function run() |
|
| 167 | - { |
|
| 168 | - $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
| 169 | - |
|
| 170 | - if ($this->triggerUser === false) { |
|
| 171 | - throw new ApplicationLogicException('Cannot locate trigger user'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
| 175 | - |
|
| 176 | - if ($this->request === false) { |
|
| 177 | - throw new ApplicationLogicException('Cannot locate request'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if ($this->job->getEmailTemplate() !== null) { |
|
| 181 | - $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
| 182 | - |
|
| 183 | - if ($this->emailTemplate === false) { |
|
| 184 | - throw new ApplicationLogicException('Cannot locate email template'); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if ($this->job->getParameters() !== null) { |
|
| 189 | - $this->parameters = json_decode($this->job->getParameters()); |
|
| 190 | - |
|
| 191 | - if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 192 | - throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // Should we wait for a parent job? |
|
| 197 | - if ($this->job->getParent() !== null) { |
|
| 198 | - /** @var JobQueue $parentJob */ |
|
| 199 | - $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
| 200 | - |
|
| 201 | - if ($parentJob === false) { |
|
| 202 | - $this->markFailed("Parent job could not be found"); |
|
| 203 | - return; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - switch ($parentJob->getStatus()) { |
|
| 207 | - case JobQueue::STATUS_CANCELLED: |
|
| 208 | - case JobQueue::STATUS_FAILED: |
|
| 209 | - $this->markCancelled('Parent job failed/cancelled'); |
|
| 210 | - return; |
|
| 211 | - case JobQueue::STATUS_WAITING: |
|
| 212 | - case JobQueue::STATUS_READY: |
|
| 213 | - case JobQueue::STATUS_QUEUED: |
|
| 214 | - case JobQueue::STATUS_RUNNING: |
|
| 215 | - case JobQueue::STATUS_HELD: |
|
| 216 | - // Defer to next execution |
|
| 217 | - $this->job->setStatus(JobQueue::STATUS_READY); |
|
| 218 | - $this->job->save(); |
|
| 219 | - return; |
|
| 220 | - case JobQueue::STATUS_COMPLETE: |
|
| 221 | - // do nothing |
|
| 222 | - break; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $this->execute(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - protected function markComplete() |
|
| 230 | - { |
|
| 231 | - $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
| 232 | - $this->job->setError(null); |
|
| 233 | - $this->job->setAcknowledged(null); |
|
| 234 | - $this->job->save(); |
|
| 235 | - |
|
| 236 | - Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - protected function markCancelled($reason = null) |
|
| 240 | - { |
|
| 241 | - $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 242 | - $this->job->setError($reason); |
|
| 243 | - $this->job->setAcknowledged(null); |
|
| 244 | - $this->job->save(); |
|
| 245 | - |
|
| 246 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - protected function markFailed($reason = null, bool $acknowledged = false) |
|
| 250 | - { |
|
| 251 | - $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
| 252 | - $this->job->setError($reason); |
|
| 253 | - $this->job->setAcknowledged($acknowledged ? 1 : 0); |
|
| 254 | - $this->job->save(); |
|
| 255 | - |
|
| 256 | - Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * @return User |
|
| 261 | - */ |
|
| 262 | - public function getTriggerUser() |
|
| 263 | - { |
|
| 264 | - return $this->triggerUser; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return Request |
|
| 269 | - */ |
|
| 270 | - public function getRequest() |
|
| 271 | - { |
|
| 272 | - return $this->request; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * @return EmailTemplate |
|
| 277 | - */ |
|
| 278 | - public function getEmailTemplate() |
|
| 279 | - { |
|
| 280 | - return $this->emailTemplate; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @return mixed |
|
| 285 | - */ |
|
| 286 | - public function getParameters() |
|
| 287 | - { |
|
| 288 | - return $this->parameters; |
|
| 289 | - } |
|
| 26 | + /** @var JobQueue */ |
|
| 27 | + private $job; |
|
| 28 | + /** @var PdoDatabase */ |
|
| 29 | + private $database; |
|
| 30 | + /** @var IOAuthProtocolHelper */ |
|
| 31 | + private $oauthProtocolHelper; |
|
| 32 | + /** @var SiteConfiguration */ |
|
| 33 | + private $siteConfiguration; |
|
| 34 | + /** @var IEmailHelper */ |
|
| 35 | + private $emailHelper; |
|
| 36 | + /** @var HttpHelper */ |
|
| 37 | + private $httpHelper; |
|
| 38 | + /** @var IrcNotificationHelper */ |
|
| 39 | + private $notificationHelper; |
|
| 40 | + /** @var User */ |
|
| 41 | + private $triggerUser; |
|
| 42 | + /** @var Request */ |
|
| 43 | + private $request; |
|
| 44 | + /** @var EmailTemplate */ |
|
| 45 | + private $emailTemplate = null; |
|
| 46 | + /** @var mixed */ |
|
| 47 | + private $parameters; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @return JobQueue |
|
| 51 | + */ |
|
| 52 | + public function getJob() |
|
| 53 | + { |
|
| 54 | + return $this->job; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @param JobQueue $job |
|
| 59 | + */ |
|
| 60 | + public function setJob(JobQueue $job) |
|
| 61 | + { |
|
| 62 | + $this->job = $job; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @return PdoDatabase |
|
| 67 | + */ |
|
| 68 | + public function getDatabase() |
|
| 69 | + { |
|
| 70 | + return $this->database; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @param PdoDatabase $database |
|
| 75 | + */ |
|
| 76 | + public function setDatabase(PdoDatabase $database) |
|
| 77 | + { |
|
| 78 | + $this->database = $database; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @return IOAuthProtocolHelper |
|
| 83 | + */ |
|
| 84 | + public function getOauthProtocolHelper() |
|
| 85 | + { |
|
| 86 | + return $this->oauthProtocolHelper; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * @param IOAuthProtocolHelper $oauthProtocolHelper |
|
| 91 | + */ |
|
| 92 | + public function setOauthProtocolHelper(IOAuthProtocolHelper $oauthProtocolHelper) |
|
| 93 | + { |
|
| 94 | + $this->oauthProtocolHelper = $oauthProtocolHelper; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @return SiteConfiguration |
|
| 99 | + */ |
|
| 100 | + public function getSiteConfiguration() |
|
| 101 | + { |
|
| 102 | + return $this->siteConfiguration; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @param SiteConfiguration $siteConfiguration |
|
| 107 | + */ |
|
| 108 | + public function setSiteConfiguration(SiteConfiguration $siteConfiguration) |
|
| 109 | + { |
|
| 110 | + $this->siteConfiguration = $siteConfiguration; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @return HttpHelper |
|
| 115 | + */ |
|
| 116 | + public function getHttpHelper() |
|
| 117 | + { |
|
| 118 | + return $this->httpHelper; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * @param HttpHelper $httpHelper |
|
| 123 | + */ |
|
| 124 | + public function setHttpHelper(HttpHelper $httpHelper) |
|
| 125 | + { |
|
| 126 | + $this->httpHelper = $httpHelper; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @return IEmailHelper |
|
| 131 | + */ |
|
| 132 | + public function getEmailHelper() |
|
| 133 | + { |
|
| 134 | + return $this->emailHelper; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @param IEmailHelper $emailHelper |
|
| 139 | + */ |
|
| 140 | + public function setEmailHelper(IEmailHelper $emailHelper) |
|
| 141 | + { |
|
| 142 | + $this->emailHelper = $emailHelper; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * @return IrcNotificationHelper |
|
| 147 | + */ |
|
| 148 | + public function getNotificationHelper() |
|
| 149 | + { |
|
| 150 | + return $this->notificationHelper; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * @param IrcNotificationHelper $notificationHelper |
|
| 155 | + */ |
|
| 156 | + public function setNotificationHelper($notificationHelper) |
|
| 157 | + { |
|
| 158 | + $this->notificationHelper = $notificationHelper; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * @return void |
|
| 163 | + */ |
|
| 164 | + protected abstract function execute(); |
|
| 165 | + |
|
| 166 | + public function run() |
|
| 167 | + { |
|
| 168 | + $this->triggerUser = User::getById($this->job->getTriggerUserId(), $this->getDatabase()); |
|
| 169 | + |
|
| 170 | + if ($this->triggerUser === false) { |
|
| 171 | + throw new ApplicationLogicException('Cannot locate trigger user'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $this->request = Request::getById($this->job->getRequest(), $this->getDatabase()); |
|
| 175 | + |
|
| 176 | + if ($this->request === false) { |
|
| 177 | + throw new ApplicationLogicException('Cannot locate request'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if ($this->job->getEmailTemplate() !== null) { |
|
| 181 | + $this->emailTemplate = EmailTemplate::getById($this->job->getEmailTemplate(), $this->getDatabase()); |
|
| 182 | + |
|
| 183 | + if ($this->emailTemplate === false) { |
|
| 184 | + throw new ApplicationLogicException('Cannot locate email template'); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if ($this->job->getParameters() !== null) { |
|
| 189 | + $this->parameters = json_decode($this->job->getParameters()); |
|
| 190 | + |
|
| 191 | + if (json_last_error() !== JSON_ERROR_NONE) { |
|
| 192 | + throw new ApplicationLogicException('JSON decode: ' . json_last_error_msg()); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // Should we wait for a parent job? |
|
| 197 | + if ($this->job->getParent() !== null) { |
|
| 198 | + /** @var JobQueue $parentJob */ |
|
| 199 | + $parentJob = JobQueue::getById($this->job->getParent(), $this->getDatabase()); |
|
| 200 | + |
|
| 201 | + if ($parentJob === false) { |
|
| 202 | + $this->markFailed("Parent job could not be found"); |
|
| 203 | + return; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + switch ($parentJob->getStatus()) { |
|
| 207 | + case JobQueue::STATUS_CANCELLED: |
|
| 208 | + case JobQueue::STATUS_FAILED: |
|
| 209 | + $this->markCancelled('Parent job failed/cancelled'); |
|
| 210 | + return; |
|
| 211 | + case JobQueue::STATUS_WAITING: |
|
| 212 | + case JobQueue::STATUS_READY: |
|
| 213 | + case JobQueue::STATUS_QUEUED: |
|
| 214 | + case JobQueue::STATUS_RUNNING: |
|
| 215 | + case JobQueue::STATUS_HELD: |
|
| 216 | + // Defer to next execution |
|
| 217 | + $this->job->setStatus(JobQueue::STATUS_READY); |
|
| 218 | + $this->job->save(); |
|
| 219 | + return; |
|
| 220 | + case JobQueue::STATUS_COMPLETE: |
|
| 221 | + // do nothing |
|
| 222 | + break; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $this->execute(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + protected function markComplete() |
|
| 230 | + { |
|
| 231 | + $this->job->setStatus(JobQueue::STATUS_COMPLETE); |
|
| 232 | + $this->job->setError(null); |
|
| 233 | + $this->job->setAcknowledged(null); |
|
| 234 | + $this->job->save(); |
|
| 235 | + |
|
| 236 | + Logger::backgroundJobComplete($this->getDatabase(), $this->getJob()); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + protected function markCancelled($reason = null) |
|
| 240 | + { |
|
| 241 | + $this->job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 242 | + $this->job->setError($reason); |
|
| 243 | + $this->job->setAcknowledged(null); |
|
| 244 | + $this->job->save(); |
|
| 245 | + |
|
| 246 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + protected function markFailed($reason = null, bool $acknowledged = false) |
|
| 250 | + { |
|
| 251 | + $this->job->setStatus(JobQueue::STATUS_FAILED); |
|
| 252 | + $this->job->setError($reason); |
|
| 253 | + $this->job->setAcknowledged($acknowledged ? 1 : 0); |
|
| 254 | + $this->job->save(); |
|
| 255 | + |
|
| 256 | + Logger::backgroundJobIssue($this->getDatabase(), $this->getJob()); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * @return User |
|
| 261 | + */ |
|
| 262 | + public function getTriggerUser() |
|
| 263 | + { |
|
| 264 | + return $this->triggerUser; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return Request |
|
| 269 | + */ |
|
| 270 | + public function getRequest() |
|
| 271 | + { |
|
| 272 | + return $this->request; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * @return EmailTemplate |
|
| 277 | + */ |
|
| 278 | + public function getEmailTemplate() |
|
| 279 | + { |
|
| 280 | + return $this->emailTemplate; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * @return mixed |
|
| 285 | + */ |
|
| 286 | + public function getParameters() |
|
| 287 | + { |
|
| 288 | + return $this->parameters; |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -16,15 +16,15 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RequestList |
| 18 | 18 | { |
| 19 | - public $requests; |
|
| 20 | - public $showPrivateData; |
|
| 21 | - public $dataClearEmail; |
|
| 22 | - public $dataClearIp; |
|
| 23 | - public $relatedEmailRequests; |
|
| 24 | - public $relatedIpRequests; |
|
| 25 | - public $requestTrustedIp; |
|
| 26 | - public $canBan; |
|
| 27 | - public $canBreakReservation; |
|
| 28 | - public $userList; |
|
| 29 | - public $commonEmail; |
|
| 19 | + public $requests; |
|
| 20 | + public $showPrivateData; |
|
| 21 | + public $dataClearEmail; |
|
| 22 | + public $dataClearIp; |
|
| 23 | + public $relatedEmailRequests; |
|
| 24 | + public $relatedIpRequests; |
|
| 25 | + public $requestTrustedIp; |
|
| 26 | + public $canBan; |
|
| 27 | + public $canBreakReservation; |
|
| 28 | + public $userList; |
|
| 29 | + public $commonEmail; |
|
| 30 | 30 | } |