Trying to create a cron job to run if a condition is true |
I have a simple database of product sheet requests in the administration section of our website. If a user requests a product sheet it gets sent to the database and an email gets sent to the people in charge of responding to the requests.
I want to create a cron job that runs every 24 hour and checks when the request was sent, if the request has been responded to, and if it hasnt been responded to within 24 hours it sends a reminder email to the people in charge of sending it, then it runs again at 48 hours and reminds them again, and the same with 72 hours. Has anyone done anything like this before with CodeIgniter? I'm not sure how to begin. Any help you can offer is much appreciated!
Adding a cronjob that execute a specific function in CI is very simple. Here is an example of one running at 1am every day.
Code: 00 01 * * * php /path/to/codeigniter/index.php controller my_function >> /dev/null The function your cron is executing should do all the work of checking if a reminder should be sent out or not.
Thanks for the reply,
I'm not sure what to use for my path to codeigniter in the cron job. In my index.php I have my $application_folder = '../../codeI/application'; Is this what I should set as my path to codeigniter in the cron job also? I think I did this right... here is my model... Code: <?php and here is my controller... (obviously the email part needs some work still) Code: <?php Again, what I'm trying to do is get all the requests that were sent yesterday and have not been marked as sent yet, and send an email out to the group responsible for responding to remind them. Thanks for all your help! (03-04-2015, 03:22 PM)alexandervj Wrote: I'm not sure what to use for my path to codeigniter in the cron job. No, for the cronjob you'd need the full filepath up to and including "index.php". Cron doesn't know anything about your relative application path, and actually you don't want to use the application dir anyway...just the path TO index.php. If you don't know the full path, you can open up index.php and scroll down towards the bottom, you will see a define('FCPATH', str_replace(SELF, '', __FILE__)); or something similar. just under that line put die(FCPATH) and visit your site. It will give you the full path to your CI dir. Be sure to remove that line after you do this. Something like /home/some_user/public_html/ Then just add an index.php to the end of that and that's what you'd want to use for your cronjob. /home/some_user/public_html/index.php.
Thanks CroNiX,
I think I figured the cron part out but I think something is wrong with my controller and or model, not sure what. I got some of the code from a tutorial, and I'm actually not sure what the $day variable is in the model... here is the turorial... http://glennstovall.com/blog/2013/01/07/...deigniter/ the script doesnt work when I run it in the address bar. It doesnt have any errors, just doesnt send an email so I'm guessing something is wrong with my controller or model
Did you remove the check for if it was a CLI request from your controllers index method? That would prevent it from running via the url.
Yeah, I did that, it seems to run it just doesn't send the email as expected. If I comment out everything and just have it send a test email it sends the email but there must be a problem with my controller or model or the way I went about this
I figured it out, I had the greater than less than signs backwards haha thanks for your help!
(03-05-2015, 06:56 AM)alexandervj Wrote: I figured it out, I had the greater than less than signs backwards haha thanks for your help! Those are always the best! I once had an application with some code that said, if the value is positive then subtract it and if it is negative then add it - took me hours to work out why the negative values kept doubling up whilst the positives reset themselves to zero! I believe NASA once lost a rocket due to the same error in a guidance control system
|
Welcome Guest, Not a member yet? Register Sign In |