GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

writeDeleteAndSuspensionInfoToDatabase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
/**
4
 * Handles all data manipulation of the admin part
5
 */
6
class AdminModel
7
{
8
    /**
9
     * Sets the deletion and suspension values
10
     *
11
     * @param $suspensionInDays
12
     * @param $softDelete
13
     * @param $userId
14
     */
15
    public static function setAccountSuspensionAndDeletionStatus($suspensionInDays, $softDelete, $userId)
16
    {
17
18
        // Prevent to suspend or delete own account.
19
        // If admin suspend or delete own account will not be able to do any action.
20
        if ($userId == Session::get('user_id')) {
21
            Session::add('feedback_negative', Text::get('FEEDBACK_ACCOUNT_CANT_DELETE_SUSPEND_OWN'));
22
            return false;
23
        }
24
25
        if ($suspensionInDays > 0) {
26
            $suspensionTime = time() + ($suspensionInDays * 60 * 60 * 24);
27
        } else {
28
            $suspensionTime = null;
29
        }
30
31
        // FYI "on" is what a checkbox delivers by default when submitted. Didn't know that for a long time :)
32
        if ($softDelete == "on") {
33
            $delete = 1;
34
        } else {
35
            $delete = 0;
36
        }
37
38
        // write the above info to the database
39
        self::writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete);
40
41
        // if suspension or deletion should happen, then also kick user out of the application instantly by resetting
42
        // the user's session :)
43
        if ($suspensionTime != null OR $delete = 1) {
44
            self::resetUserSession($userId);
45
        }
46
    }
47
48
    /**
49
     * Simply write the deletion and suspension info for the user into the database, also puts feedback into session
50
     *
51
     * @param $userId
52
     * @param $suspensionTime
53
     * @param $delete
54
     * @return bool
55
     */
56
    private static function writeDeleteAndSuspensionInfoToDatabase($userId, $suspensionTime, $delete)
57
    {
58
        $database = DatabaseFactory::getFactory()->getConnection();
59
60
        $query = $database->prepare("UPDATE users SET user_suspension_timestamp = :user_suspension_timestamp, user_deleted = :user_deleted  WHERE user_id = :user_id LIMIT 1");
61
        $query->execute(array(
62
                ':user_suspension_timestamp' => $suspensionTime,
63
                ':user_deleted' => $delete,
64
                ':user_id' => $userId
65
        ));
66
67
        if ($query->rowCount() == 1) {
68
            Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_SUSPENSION_DELETION_STATUS'));
69
            return true;
70
        }
71
    }
72
73
    /**
74
     * Kicks the selected user out of the system instantly by resetting the user's session.
75
     * This means, the user will be "logged out".
76
     *
77
     * @param $userId
78
     * @return bool
79
     */
80
    private static function resetUserSession($userId)
81
    {
82
        $database = DatabaseFactory::getFactory()->getConnection();
83
84
        $query = $database->prepare("UPDATE users SET session_id = :session_id  WHERE user_id = :user_id LIMIT 1");
85
        $query->execute(array(
86
                ':session_id' => null,
87
                ':user_id' => $userId
88
        ));
89
90
        if ($query->rowCount() == 1) {
91
            Session::add('feedback_positive', Text::get('FEEDBACK_ACCOUNT_USER_SUCCESSFULLY_KICKED'));
92
            return true;
93
        }
94
    }
95
}
96