Welcome Guest, Not a member yet? Register   Sign In
Trying to create a cron job to run if a condition is true
#3

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

class Model_reminders extends CI_Model{
   
   public function get_days_request_reminders($day){
    
    $day_start = date('Y-m-d 00:00:00', $day); //set the $day_start variable to the current date at 12:00 AM
    $day_end = date('Y-m-d 23:59:59', $day); //set the $day_end variable to the current date at 11:59 PM
    return $this->db->select('*')
        ->from('apps_requests')
        ->where('submit_time <', $day_start) //
        ->where('submit_time >', $day_end) //
        ->where('is_sent', 0)
        ->get()->result();
    
   }
   
   
}


and here is my controller... (obviously the email part needs some work still)
Code:
<?php
class Reminders extends CI_Controller{

   public function __construct(){
       parent::__construct();
       $this->load->library('input');
       $this->load->library('email');
       $this->load->model('Model_main');
   }
 
   public function index(){
       if(!$this->input->is_cli_request()){
           echo "This script can only be accessed via the command line" . PHP_EOL;
           return;
       }
       
       $timestamp = strtotime("-1 days");
       $reminder = $this->Model_main->get_days_request_reminders($timestamp);
       
       if(!empty($reminder)){
           foreach($reminder as $r){
               $this->email->set_newline("\r\n");
               $this->email->to($r->email);
               $this->email->from("[email protected]");
               $this->email->subject("Request Reminder");
               $this->email->message("Request has not been responded to in 24 hours");
               $this->email->send();
           }
       }
   }
}


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!
Reply


Messages In This Thread
RE: Trying to create a cron job to run if a condition is true - by alexandervj - 03-04-2015, 03:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB