public function getMailUpdate(User $user, $interval) { $output = ""; foreach (Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } $receive_email_notifications = $user->getSetting("receive_email_notifications", 'core', Setting::Get('receive_email_notifications', 'mailing')); // Never receive notifications if ($receive_email_notifications == User::RECEIVE_EMAIL_NEVER) { return ""; } // We are in hourly mode and user wants daily if ($interval == CronController::EVENT_ON_HOURLY_RUN && $receive_email_notifications == User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // We are in daily mode and user dont wants daily reports if ($interval == CronController::EVENT_ON_DAILY_RUN && $receive_email_notifications != User::RECEIVE_EMAIL_DAILY_SUMMARY) { return ""; } // User wants only when offline and is online if ($interval == CronController::EVENT_ON_HOURLY_RUN) { $isOnline = count($user->httpSessions) > 0; if ($receive_email_notifications == User::RECEIVE_EMAIL_WHEN_OFFLINE && $isOnline) { return ""; } } $query = Notification::find()->where(['user_id' => $user->id])->andWhere(['!=', 'seen', 1])->andWhere(['!=', 'emailed', 1]); foreach ($query->all() as $notification) { $output .= $notification->getClass()->render(BaseNotification::OUTPUT_MAIL); $notification->emailed = 1; $notification->save(); } return $output; }
/** * Tasks on hourly cron job * * @param \yii\base\Event $event */ public static function onHourlyCron($event) { $controller = $event->sender; foreach (Yii::$app->authClientCollection->getClients() as $authClient) { if ($authClient instanceof authclient\interfaces\AutoSyncUsers) { /** * @var authclient\interfaces\AutoSyncUsers $authClient */ $authClient->syncUsers(); } } // Delete expired session foreach (models\Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } }
public static function onHourlyCron($event) { $controller = $event->sender; if (Setting::Get('enabled', 'authentication_ldap') && Setting::Get('refreshUsers', 'authentication_ldap') && Ldap::isAvailable()) { $controller->stdout("Refresh ldap users... "); Ldap::getInstance()->refreshUsers(); $controller->stdout('done.' . PHP_EOL, \yii\helpers\Console::FG_GREEN); } // Delete expired session foreach (models\Session::find()->where(['<', 'expire', time()])->all() as $session) { $session->delete(); } }