Forked from bobbravo2/WHMCS licensing addon suspension cron hook
Created
June 11, 2014 17:21
-
-
Save DVSB/5192e4152b14c18aa19f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* WHMCS Licensing Cron Hook | |
* Automatically suspends overdue | |
* WHMCS Support & Updates Addons | |
* @license GPL V3 <http://www.gnu.org/licenses/> | |
* | |
* Copyright (C) 2013 Robert Gregor | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* See <http://www.gnu.org/licenses/>. | |
*/ | |
add_hook('DailyCronJob', 1, 'suspend_overdue_support_updates'); | |
function suspend_overdue_support_updates () | |
{ | |
$message = 'Cron Job: Licensing: Suspending Overdue Support & Updates'; | |
logActivity($message); | |
echo $message . PHP_EOL; | |
$query = "SELECT `configoption7` FROM `tblproducts` | |
WHERE `servertype` = 'licensing'"; | |
$result = mysql_query($query); | |
$support_updates = array(); | |
while ($row = mysql_fetch_assoc($result)) { | |
$string = $row['configoption7']; | |
$addon_array = explode('|', $string); | |
if ($addon_array[0] > 0 ) { | |
$support_updates[] = $addon_array[0]; | |
} | |
} | |
$support_updates = array_unique($support_updates); | |
if (empty($support_updates)) { | |
$message = 'Cron Job: Licensing: No Support & Updates Addons Found'; | |
echo $message . PHP_EOL; | |
logActivity($message); | |
return; | |
} | |
$date = date('Y-m-d'); | |
$query = " | |
UPDATE `tblhostingaddons` | |
SET `status` = 'Suspended' | |
WHERE `addonid` IN (" . implode(',', array_map('intval', $support_updates)) . ')'." | |
AND `nextduedate` < '{$date}' | |
AND `status` = 'Active'"; | |
mysql_query($query); | |
$updated = mysql_affected_rows(); | |
$message = 'Cron Job: Licensing: Suspended '.$updated . ' Overdue Support & Updates'; | |
logActivity($message); | |
echo $message . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment