Completed
Pull Request — devel (#18)
by
unknown
38:28
created

CronJobController::actionRemoveExpired()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 18
rs 9.6666
cc 1
nc 1
nop 0
1
<?php
2
3
namespace sweelix\oauth2\server\commands;
4
5
use Yii;
6
use yii\console\Controller;
7
use yii\console\ExitCode;
8
9
class CronJobController extends Controller
10
{
11
    /**
12
     * @return int
13
     * @throws \yii\db\Exception
14
     */
15
    public function actionRemoveExpired()
16
    {
17
        $tokenSuppressedNumber = 0;
18
        $tokenSuppressedNumber += Yii::$app->db->createCommand()
19
            ->delete('oauthAccessTokens', 'expiry <= NOW()')
20
            ->execute();
21
        $tokenSuppressedNumber += Yii::$app->db->createCommand()
22
            ->delete('oauthAuthorizationCodes', 'expiry <= NOW()')
23
            ->execute();
24
        $tokenSuppressedNumber += Yii::$app->db->createCommand()
25
            ->delete('oauthJtis', 'expires <= NOW()')
26
            ->execute();
27
        $tokenSuppressedNumber += Yii::$app->db->createCommand()
28
            ->delete('oauthRefreshTokens', 'expiry <= NOW()')
29
            ->execute();
30
        $this->stdout($tokenSuppressedNumber."\n");
31
        return ExitCode::OK;
32
    }
33
}
34