-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcron.php
39 lines (30 loc) · 1.25 KB
/
cron.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
use App\Repositories\AccessTokenRepository;
use App\Repositories\AuthorizationCodeRepository;
use App\Services\ApiWrapper;
require __DIR__ . '/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->safeLoad();
$dsn = "mysql:host={$_SERVER['DBURL']};port={$_SERVER['DBPORT']};dbname={$_SERVER['DBNAME']};charset=utf8mb4";
$pdo = new PDO($dsn, $_SERVER['DBUSER'], $_SERVER['DBPASSWORD'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
$accessTokenRepository = new AccessTokenRepository($pdo, $_SERVER['DBPREFIX']);
$authorizationCodeRepository = new AuthorizationCodeRepository($pdo, $_SERVER['DBPREFIX']);
$apiWrapper = new ApiWrapper(
$accessTokenRepository,
$authorizationCodeRepository,
$_SERVER['HA_AUTH_URL'],
$_SERVER['API_URL'],
$_SERVER['API_AUTH_URL'],
$_SERVER['CLIENT_ID'],
$_SERVER['CLIENT_SECRET'],
$_SERVER['WEBSITE_DOMAIN']
);
$tokens = $accessTokenRepository->getAccessTokensToRefresh();
echo count($tokens) . " tokens to refresh";
foreach ($tokens as $token) {
$apiWrapper->getAccessTokensAndRefreshIfNecessary($token->organization_slug);
echo "Token for " . $token->organization_slug ?? "HelloAssoStream" . " refreshed";
}