|
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\ConsoleTasks; |
|
10
|
|
|
|
|
11
|
|
|
use PDO; |
|
12
|
|
|
use Waca\DataObjects\User; |
|
13
|
|
|
use Waca\Exceptions\OAuthException; |
|
14
|
|
|
use Waca\Helpers\OAuthUserHelper; |
|
15
|
|
|
use Waca\Helpers\SearchHelpers\UserSearchHelper; |
|
16
|
|
|
use Waca\Tasks\ConsoleTaskBase; |
|
17
|
|
|
|
|
18
|
|
|
class RefreshOAuthDataTask extends ConsoleTaskBase |
|
19
|
|
|
{ |
|
20
|
|
|
public function execute() |
|
21
|
|
|
{ |
|
22
|
|
|
$database = $this->getDatabase(); |
|
23
|
|
|
|
|
24
|
|
|
$idList = $database |
|
25
|
|
|
->query('SELECT user FROM oauthtoken WHERE type = \'access\' AND expiry IS NULL') |
|
26
|
|
|
->fetchAll(PDO::FETCH_COLUMN); |
|
27
|
|
|
|
|
28
|
|
|
if (count($idList) > 0) { |
|
29
|
|
|
/** @var User[] $users */ |
|
30
|
|
|
$users = UserSearchHelper::get($database)->inIds($idList)->fetch(); |
|
31
|
|
|
|
|
32
|
|
|
$expiredStatement = $database |
|
33
|
|
|
->prepare('UPDATE oauthtoken SET expiry = CURRENT_TIMESTAMP() WHERE user = :u AND type = \'access\''); |
|
34
|
|
|
|
|
35
|
|
|
foreach ($users as $u) { |
|
36
|
|
|
$oauth = new OAuthUserHelper($u, $database, $this->getOAuthProtocolHelper(), |
|
37
|
|
|
$this->getSiteConfiguration()); |
|
38
|
|
|
|
|
39
|
|
|
try { |
|
40
|
|
|
$oauth->refreshIdentity(); |
|
41
|
|
|
} |
|
42
|
|
|
catch (OAuthException $ex) { |
|
43
|
|
|
$expiredStatement->execute(array(':u' => $u->getId())); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$this->getDatabase() |
|
49
|
|
|
->exec('DELETE FROM oauthtoken WHERE expiry IS NOT NULL AND expiry < NOW() AND type = \'request\''); |
|
50
|
|
|
} |
|
51
|
|
|
} |