Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DVSB/5192e4152b14c18aa19f to your computer and use it in GitHub Desktop.
Save DVSB/5192e4152b14c18aa19f to your computer and use it in GitHub Desktop.
<?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