function updatesNotificationMailSend($force = false) { if ($force == false) { $getAllNotifications = DB::getArray("?:users", "userID, accessLevel, permissions, notifications, updatesNotificationMailLastSent", 1, "userID"); } else { $getAllNotifications = DB::getArray("?:users", "userID, accessLevel, permissions, notifications, updatesNotificationMailLastSent", "userID = '" . $GLOBALS['userID'] . "'", "userID"); } $run = 1; if (!empty($getAllNotifications)) { foreach ($getAllNotifications as $userID => $userData) { if (empty($userData['notifications'])) { continue; } $UID = ''; if ($userData['accessLevel'] == 'manager') { $permissions = unserialize($userData['permissions']); if (empty($permissions['access']) || !empty($permissions['access']) && !in_array('updates', $permissions['access'])) { continue; } $UID = $userID; } $updatesNotificationMail = unserialize($userData['notifications']); $updatesNotificationMail = $updatesNotificationMail['updatesNotificationMail']; //check setting if ($force == false) { if ($updatesNotificationMail['frequency'] == 'never' || empty($updatesNotificationMail['coreUpdates']) && empty($updatesNotificationMail['pluginUpdates']) && empty($updatesNotificationMail['themeUpdates'])) { continue; //updatesNotificationMail is disabled in the settings } } if ($force == false && $run == 1) { //for test mail(i.e $force == true) dont need to get new data Reg::set('currentRequest.actionID', uniqid('', true)); $lastNHours = time() - 60 * 60 * 2; //2 hours $getRemainingSiteIDsQuery = "SELECT S.siteID FROM ?:sites S LEFT OUTER JOIN ?:history H on S.siteID = H.siteID and H.type = 'stats' and H.action = 'getStats' and H.microtimeInitiated >= " . $lastNHours . " and H.status IN('completed', 'error', 'netError') where H.siteID is null"; $remainingSiteIDs = DB::getFields($getRemainingSiteIDsQuery); //Assuming for all the sites reload data can happen in 2 hours. if (!empty($remainingSiteIDs) && is_array($remainingSiteIDs)) { foreach ($remainingSiteIDs as $siteID) { $isAlreadyAdded = DB::getExists("?:history H", "H.historyID", "H.siteID = " . $siteID . " AND H.type = 'stats' AND H.action = 'getStats'and H.microtimeInitiated >= " . $lastNHours . " AND showUser = '******'"); if ($isAlreadyAdded) { continue; //no need to trigger new one, has one is already in place. } $extras = array('directExecute' => true, 'sendAfterAllLoad' => false, 'doNotShowUser' => true); //'directExecute' => true reload data calls will be executed directly blocking mode manageClientsFetch::getStatsProcessor(array($siteID), array(), $extras); $run = 0; if ($GLOBALS['cronStartTime'] + CRON_TIMEOUT < time()) { break; } } } $remainingSiteIDs = DB::getFields($getRemainingSiteIDsQuery); if (!empty($remainingSiteIDs)) { return false; } //If all sites reload data not completed as per above criteria, then go out of this function. In the next cron call it will continue from where it left. As the above while function this case will come from CRON_TIMEOUT meets. } //getting updateInformation $sitesUpdates = panelRequestManager::getSitesUpdates($UID); $hiddenUpdates = panelRequestManager::getHide(); foreach ($hiddenUpdates as $siteID => $value) { foreach ($value as $d) { unset($sitesUpdates['siteView'][$siteID][$d['type']][$d['URL']]); //this will fix the site name shows even all update items are hidden if (empty($sitesUpdates['siteView'][$siteID][$d['type']])) { unset($sitesUpdates['siteView'][$siteID][$d['type']]); } if (empty($sitesUpdates['siteView'][$siteID])) { unset($sitesUpdates['siteView'][$siteID]); } } } if (!empty($sitesUpdates['siteView']) && (empty($updatesNotificationMail['coreUpdates']) || empty($updatesNotificationMail['pluginUpdates']) || empty($updatesNotificationMail['themeUpdates']))) { //this will fix when the "plugin" not selected in settings. Site name shows with empty list when plugin update is available foreach ($sitesUpdates['siteView'] as $siteID => $value) { if (empty($updatesNotificationMail['coreUpdates'])) { unset($sitesUpdates['siteView'][$siteID]['core']); } if (empty($updatesNotificationMail['pluginUpdates'])) { unset($sitesUpdates['siteView'][$siteID]['plugins']); } if (empty($updatesNotificationMail['themeUpdates'])) { unset($sitesUpdates['siteView'][$siteID]['themes']); } if (empty($sitesUpdates['siteView'][$siteID])) { unset($sitesUpdates['siteView'][$siteID]); } } } $params = array('userID' => $userID, 'sitesUpdates' => $sitesUpdates, 'updatesNotificationMail' => $updatesNotificationMail, 'updateNotificationDynamicContent' => getOption('updateNotificationDynamicContent')); $isSent = sendAppMail($params, '/templates/email/updatesNotification.tpl.php'); if ($isSent) { if (!$force) { DB::update("?:users", array('updatesNotificationMailLastSent' => time()), "userID = '" . $userID . "'"); } } else { if (!$force) { DB::update("?:users", array('updatesNotificationMailLastSent' => time()), "userID = '" . $userID . "'"); //even mail sending failed mark as sent this will avoid re-trying, customer will be notified if mail not sent using offline notification } } } } return true; }