예제 #1
0
function updatesNotificationMailRunCheck($getNextScheduleTime = false)
{
    /*$settings = panelRequestManager::getSettings();
    	$updatesNotificationMail = $settings['notifications']['updatesNotificationMail'];*/
    $isAtleastOneSiteAdded = DB::getExists("?:sites", "siteID", "1 LIMIT 1");
    if (!$isAtleastOneSiteAdded) {
        return false;
        //if no sites are there, then don't send update notification mail
    }
    $getAllNotifications = DB::getArray("?:users", "userID, accessLevel, permissions, notifications, updatesNotificationMailLastSent", 1, "userID");
    if (!empty($getAllNotifications)) {
        foreach ($getAllNotifications as $userID => $userData) {
            if (empty($userData['notifications'])) {
                continue;
            }
            if ($userData['accessLevel'] == 'manager') {
                $permissions = unserialize($userData['permissions']);
                if (empty($permissions['access']) || !empty($permissions['access']) && !in_array('updates', $permissions['access'])) {
                    continue;
                }
            }
            $updatesNotificationMail = unserialize($userData['notifications']);
            $updatesNotificationMail = $updatesNotificationMail['updatesNotificationMail'];
            //check setting
            if ($updatesNotificationMail['frequency'] == 'never' || empty($updatesNotificationMail['coreUpdates']) && empty($updatesNotificationMail['pluginUpdates']) && empty($updatesNotificationMail['themeUpdates'])) {
                continue;
                //	updatesNotificationMail is disabled in the settings
            }
            //get updates Notification Mail Last Sent
            $updatesNotificationMailLastSent = $userData['updatesNotificationMailLastSent'];
            //check last run falls within the frequency
            if ($updatesNotificationMailLastSent > 0) {
                if ($updatesNotificationMail['frequency'] == 'daily') {
                    $frequencyStartTime = strtotime(@date("d F Y 10:00:00", time()));
                    // changed to send at 10:00 am localtime
                } elseif ($updatesNotificationMail['frequency'] == 'weekly') {
                    //mon to sun week
                    $day = @date('w', time());
                    // $frequencyStartTime = mktime(0, 0, 1, @date('m'), @date('d') - ($day > 0 ? $day: 7) + 1, @date('Y'));
                    $frequencyStartTime = strtotime(@date('d', time()) - $day + 1 . " " . @date("F Y 10:00:00", time()));
                    // changed to send on monday,10:00 am localtime
                } else {
                    continue;
                    //user not subscribed to update notification mail
                }
                if ($updatesNotificationMailLastSent < $frequencyStartTime && $frequencyStartTime <= time()) {
                    //send mail
                } else {
                    //stop mail 0 => '1409655692',  1 => 1409670000,  2 => 1409656008
                    continue;
                    //already sent or time less than 10:00 according to local time
                }
            }
            //To get the time schedued to send the update mail Notification.
            if ($getNextScheduleTime) {
                if (isset($frequencyStartTime)) {
                    $time = $frequencyStartTime;
                } else {
                    $time = time();
                }
                return $time;
            }
            return updatesNotificationMailSend();
        }
    }
}
예제 #2
0
 public static function updatesNotificationMailTest()
 {
     return updatesNotificationMailSend(true);
 }