I have a controller which I use to run a list of processes through a cron, and I need it to run a method from a separate controller.
When that method is called from its own controller, everything works fine, but when running from the cron controller (even if called manually), it is failing.
My code currently looks something like this:
class CronController extends AppController
{
var $uses = array(.., 'EmailTemplate', ..);
var $components = array('Email');
//Some stuff
function process_for_cron_to_run() {
//Some stuff
//Run method from imported controller
App::import('Controller', 'Imported');
$imported = new ImportedController;
$imported->constructClasses();
$imported->method_to_run(); //Dies when running this method
exit;
}
}
...
class ImportedController extends AppController {
var $uses = array(..);
var $components = array('Mailer', 'RequestHandler', 'FileHandler', 'Email');
//Some stuff
function method_to_run() {
//Some stuff
$this->_sendEmail(..);
}
}
...
class AppController extends Controller
{
var $components = array('Cookie', 'RequestHandler', 'Err', 'Email', 'Sms');
var $uses = array(.., 'EmailTemplate', ..);
function _sendEmail(..) {
//Some stuff
$this->EmailTemplate->find(..); //Dying here (Line 1756)
}
..
}
This is dying with the following error:
Fatal error: Call to a member function find() on a non-object in /../app/app_controller.php on line 1756
Where line 1756 is in the AppController above.
I tried adding EmailTemplate
to the $uses
of the ImportedController - this worked, but it instead died a few lines later in the AppController on a call to $this->Email
, which is included in the $components
of all three controllers. The error message for $this->email
, for reference:
Fatal error: Call to a member function reset() on a non-object in /../app/app_controller.php on line 1645
The only other thing I can think of is that the method I am calling from ImportedController is an admin_X, so when I'm calling it from /processes/process_for_cron_to_run, it could be getting kicked out due to authentication issues?