Ejemplo n.º 1
0
 protected function _generateTrackingToken($user)
 {
     // Get tracking token
     App_Controller_Plugin_TrackingToken::generateToken($user->getUserName(), $user->getOrganizationId());
 }
    $cli = new Cli();
    /**
     * @var MongoCollection
     */
    $db = $cli->getResource('mongo');
    $config = $cli->getConfig('resources.inactivity.lastLogin');
    $regex = new MongoRegex("/^(" . implode('|', $config['orgTypes']) . ").+/i");
    $time = time() - $config['interval'];
    $cursor = $db->user->find(array("organizationId" => $regex, "lastLogin" => array('$lt' => new \MongoDate($time)), "status" => 'activated', "deleted" => array('$exists' => false)));
    $count = 0;
    foreach ($cursor as $data) {
        try {
            //echo json_encode($data) . "\n";
            $user = \Application\Service\UserService::getInstance()->load($data['_id']);
            // Prepare request
            App_Controller_Plugin_TrackingToken::generateToken($user->getUserName(), $user->getOrganizationId());
            $org = \Application\Service\OrgService::getInstance()->load($user->getOrganizationId());
            App::getOrgUserLogged($org);
            // Send request
            \Application\Service\UserService::getInstance()->blockDueToInactivity($user);
            $count++;
        } catch (Exception $e) {
            echo "Error with user " . $data['_id'] . ": " . $e->getMessage();
        }
    }
    echo "{$count} inactive users successfully blocked \n";
} catch (Exception $e) {
    echo 'AN ERROR HAS OCCURRED:' . PHP_EOL;
    echo $e->getMessage() . PHP_EOL;
    exit(1);
}