Note: wget with quotes around the url wont work for me, for some reason once I put quotes around the url the command wont execute and the & that goes with the parameters causes it to fail.
This is what I tried, among many other things, I tried to simply put the main points of the index file at the top of the cron file so I can use the opencart functions in the file, but it fails at "start('catalog');", I even tried putting the absolute path to catalog.
Here's the file:
Code: Select all
<?php
$message = "This is a log message cron test.";
$logFile = "/home/***/***/test.log";
// DIR
// Configuration
if (is_file('/home/***/***/config.php')) {
require_once('/home/***/***/config.php');
}
// Startup
require_once('/home/***/***/system/startup.php');
error_log("A" . "\n", 3, $logFile);
//start('/home/chris850/site_plks/catalog');
error_log("B" . "\n", 3, $logFile);
// Initialize OpenCart registry and other core objects
$registry = new Registry();
$loader = new Loader($registry);
$config = new Config();
$db = new DB(DB_DRIVER, DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$registry->set('load', $loader);
$registry->set('config', $config);
$registry->set('db', $db);
//$this->log->write("******************************************************CRON CONDITION 1: ");
// Get the controller
$controller = new ControllerExtensionCommonMyScript($registry);
// Get the 'reset' parameter
$resetValue = null; // Initialize to null
//$this->log->write("******************************************************CRON CHECK 2: ");
error_log("1" . "\n", 3, $logFile);
if (isset($argv[1])) {
$parts = explode("=", $argv[1]);
$resetParam = $parts[0];
if ($resetParam === "reset") {
error_log("2" . "\n", 3, $logFile);
$resetValue = $parts[1];
} else {
error_log("3" . "\n", 3, $logFile);
log_error("Invalid reset parameter: " . $argv[1]);
exit(1);
}
} else {
error_log("4" . "\n", 3, $logFile);
log_error("No reset parameter provided.");
exit(1);
}
$_GET['reset'] = $resetValue;
//$this->log->write("******************************************************CRON CHECK 2: " . $_GET['reset']);
// Call the function within a try-catch block
try {
error_log("5" . "\n", 3, $logFile);
$controller->cron_reset();
} catch (Exception $e) {
log_error("Error in cron_reset(): " . $e->getMessage()); // Log the exception
exit(1); // Exit with a non-zero code
}
// Function to log errors (you can customize this)
function log_error($message) {
$timestamp = date('Y-m-d H:i:s');
error_log("{$timestamp} - {$message}\n", 3, $logFile); // Log to file
// You could also log to OpenCart's log system if you have it available:
// $registry->get('log')->write("CRON ERROR: " . $message);
}
?>