Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Class not found when run through Cron job


Go to End


4 Posts   3029 Views

Avatar
jayslippy

Community Member, 10 Posts

5 February 2012 at 4:56am

I'm trying to set up regular tasks for my website using the Cron job feature from my web provider. The problem I have is that I have an extension class (code copied below) which works perfectly when browsing the website, but produces a class not found error when code is run by the cron job command line. I've spent a long time doing basic checks, and I have another extension class in the same folder which is added in the same config file and has no problems. I used the class_exists function to output to an e-mail through the cron job and to one of my web pages, and confirmed that it returns true to the web, but false to my e-mail!

Is there any difference in the way the code is built when run through command line compared to being accessed through a browser? Any reason why the code for this particular class would be ignored by my cron job even through the website finds it, builds it and uses the function it contains? Any suggestions on further tests I could run?

In the code below the two php files are in the same folder. When I remove the first add_extension everything works fine, so it is building the VerificationExtension class fine, but FormFieldExtension causes the fatal error.

In config.php

Object::add_extension('FormField', 'FormFieldExtension');
Object::add_extension('Page_Controller', 'VerificationExtension');

In FormFieldExtension.php

<?php

class FormFieldExtension extends Extension {

public function hasNoLabelClass() {
if($self = $this->owner) {
if($self->hasClass("nolabel")) {
return true;
}
}
return false;
}

}

In VerificationExtension.php

<?php

class VerificationExtension extends Extension {

public function Verified() {
if($member = Member::CurrentMember()){
if($member->RegistrationStatus > 1) {
return true;
}
}
return false;
}

}

Avatar
swaiba

Forum Moderator, 1899 Posts

5 February 2012 at 6:06am

Is there any difference in the way the code is built when run through command line compared to being accessed through a browser?

Depends on how you are running it through through command line. Silverstripe uses URL rewriting and send all php requests to sapphire/main.php with the url as a parameter.

Avatar
jayslippy

Community Member, 10 Posts

5 February 2012 at 6:34am

Edited: 05/02/2012 7:21am

Thanks for the reply, I still don't quite know where to go with this though! Is there a way for me to debug the manifest builder and output the data somehow to see why some of my classes aren't being built? Does anybody know any reason why my extension class might be ignored sometimes and not others? I've run the /deb/build so it's not that.

I have now output the manifest file contents through the e-mail and the website, the relevant sections are copied below. What are the possible explanations for the manifest builder ignoring the FormFieldExtension.php file and the class it contains when run through a cron job, when it works fine through the browser?

via e-mail/cron job/command line:

'regularemailtask' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/mysite/tasks/RegularEmailTask.php',
'editprofilepage' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/EditProfilePage.php',
'editprofilepage_controller' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/EditProfilePage.php',
'memberdecorator' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/MemberDecorator.php',
'registrationpage' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/RegistrationPage.php',
'registrationpage_controller' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/RegistrationPage.php',
'verificationextension' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/VerificationExtension.php',
'dataformatter' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/sapphire/api/DataFormatter.php',

via website:

'regularemailtask' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/mysite/tasks/RegularEmailTask.php',
'editprofilepage' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/EditProfilePage.php',
'editprofilepage_controller' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/EditProfilePage.php',
'formfieldextension' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/FormFieldExtension.php',
'memberdecorator' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/MemberDecorator.php',
'registrationpage' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/RegistrationPage.php',
'registrationpage_controller' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/RegistrationPage.php',
'verificationextension' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/registration/code/VerificationExtension.php',
'dataformatter' => '/nfs/c09/h02/mnt/129055/domains/mro-247.com/html/sapphire/api/DataFormatter.php',

Avatar
jayslippy

Community Member, 10 Posts

5 February 2012 at 11:38pm

Resolved. In case anybody else is interested, I realised that there is a separate manifest for main (ie web access) and cli-script, which is what the cron job was using. You can check the different builds of the manifest in the silverstripe-cache folder, which confirmed to me that my cli-script version was a few days old. To force a refresh just add "flush=all" to the end of your command.

"sapphire/cli-script.php /RegularEmailTask flush=all"