hmaddy Posted May 16, 2023 Share Posted May 16, 2023 i created a small hook file and added in dailycron and its not working. But in syntax all are correct and clear. so how can i check the error or how to know the real issue. is there any way to get the output by line by line to a file or how can i setup a log file on this hook 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted May 16, 2023 Share Posted May 16, 2023 Try pasting your code here. 0 Quote Link to comment Share on other sites More sharing options...
hmaddy Posted May 16, 2023 Author Share Posted May 16, 2023 (edited) following code added in hooks folder with a file name of servermanagement <?php use WHMCS\User\Client; use WHMCS\Database\Capsule; if (!defined('WHMCS')){ die('You cannot access this file directly.'); }else{ add_hook('AfterCronJob', 1, function($vars) { foreach (Capsule::table('tblhosting')->where("domainstatus", "=", "Active") ->whereIn("packageid", [264,265]) ->get() as $hosting) { $auditdate=date_create(date('Y-m-d', strtotime($hosting->nextinvoicedate. ' - 26 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" )) { create_servermanagementticket($myuserid,$userdomain); } } }); } function create_servermanagementticket($myuserid,$userdomain){ $adminUsername = 'gilty'; // Optional for WHMCS 7.2 and later //$client = get_client($userId); $command = 'OpenTicket'; $postData = array( 'deptid' => '6', 'subject' => 'Monthly Server Audit' . $userdomain, 'message' => 'Dear Sir,' . PHP_EOL . PHP_EOL . ' Audit the Server .' . PHP_EOL . PHP_EOL . ucfirst($adminUsername) . PHP_EOL . 'Server Manager/RAF Team', 'clientid' => $myuserid, 'priority' => 'Medium', 'markdown' => true); $results = localAPI($command, $postData, $adminUsername); return $results; } Edited May 16, 2023 by hmaddy 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted May 17, 2023 Share Posted May 17, 2023 Looks to be the same issue as you have mentioned here: You should try dumping the value of $datediff somewhere - either to a file or to the activity log in WHMCS (by using the logActivity() function). If that returns +0, do the same for $results. 0 Quote Link to comment Share on other sites More sharing options...
hmaddy Posted May 26, 2023 Author Share Posted May 26, 2023 i solved it by changing the hook. some api variables are not working on crons. so i change the hook and now its working fine. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.