Jump to content

cron hook not working


hmaddy

Recommended Posts

this code is not working

 

<?php
use WHMCS\Database\Capsule;


add_hook('DailyCronJob', 1, function($vars) {
    // Perform hook code here...

##Database Data Collection
 #foreach (Capsule::table('tblhosting')->where("domainstatus", "=", "Active")  ->where("packageid", "=", 264) ->orwhere("packageid", "=", 265)    ->get() as $hosting) {
foreach (Capsule::table('tblhosting')->where("domainstatus", "=", "Active")  ->whereIn("packageid", [264,265])    ->get() as $hosting) {
$auditdate=date_create(date('Y-m-d', strtotime($hosting->nextinvoicedate. ' - 30 days')));
$auditordate=$hosting->nextinvoicedate;
$Cdate=date("Y/m/d");
$CurDate=date_create(date("Y/m/d"));
$ndiff=date_diff($CurDate,$auditdate);
$datediff=$ndiff->format("%R%a");
$myuserid=$hosting->userid;
$userdomain=$hosting->domain;

##Condition Checking.

if ( $datediff == "+0" ) {

##Open Ticket

$adminUsername = 'emily'; // Optional for WHMCS 7.2 and later

$command = 'OpenTicket';
    $postData = array(
    'deptid' => '6',
    'subject' => 'Monthly Server Audit : ' .  PHP_EOL $userdomain,
    'message' => 'Dear Sir,' . PHP_EOL . PHP_EOL . ' Audit the server and attach the result. ' ' . PHP_EOL . PHP_EOL . ucfirst($adminUsername) . PHP_EOL . 'System Admin',
    'clientid' => $myuserid
    'priority' => 'Medium',
    'markdown' => true);
  
   
    $results = localAPI($command, $postData, $adminUsername);
    
    return $results;
}


##hook function close
});

 

 

ticket not opening. 

Link to comment
Share on other sites

Don't waste time testing cron-based hook points using the actual cron. Save time as follows:

image.png.5504f7f6f68a950790bc0b89994ccd23.png

While I'm still coding, I comment AfterCronJob trigger and temporarily replace it with AdminAreaPage. At the very top of the function I put a condition that immediatlly exits the script if the query string is missing simulate_cron parameter.

In other words I can browse WHMCS backend as normal. Whenever I want to simulate the cron I simply need to add ?simulate_cron=blabla in the query string on any page I am (eg. yourwhmcs.example.com/clients.php?simulate_cron=1). This way you can test your script without waiting for real cron job. Moreover if there's an error you can see that on screen.

When you're ready to go live simply remove AdminAreaPage trigger and remove comment for AfterCronJob. Alternatively you can use an approach like this one basically a button you can press to run the cron job on click.

Edited by Kian
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated