1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Testing Scheduler | Error 500

Discussion in 'Community' started by SoilentRed, Nov 8, 2019 at 6:24 PM.

  1. SoilentRed

    SoilentRed Caaan do!

    Level: Community
    I'm testing the scheduler. Having fun with it. I was able to change a 0 to a 1 running the job.
    Now I'm trying to trigger a text message, but whenever I run the cron, I'm given an error 500. I'm not sure how to go about debugging this.

    Here is my code in case ya'll have any ideas
    Code (Text):

    require __DIR__ . '/vendor/autoload.php';
    use Twilio\Rest\Client;

    // Your Account SID and Auth Token from twilio.com/console
    $account_sid = 'ACsdsfdshgjfyytgvxbcdthjgbvsfdsgbv'; // not my real sid
    $auth_token = 'fdskfdsjkfjdlksjfslkiropewriwepk'; //also fake
    // In production, these should be environment variables. E.g.:
    // $auth_token = $_ENV["TWILIO_AUTH_TOKEN"]

    // A Twilio number you own with SMS capabilities
    $twilio_number = "+19035555555";

    $client = new Client($account_sid, $auth_token);
        // Where to send a text message (your cell phone?)
            'from' => $twilio_number,
            'body' => 'I sent this message in under 10 minutes!'
    // Get the db object
    $myDb = JFactory::getDbo();

    // Build the query ? Tables names = CASE SENSITIVE
    $myQuery = $myDb->getQuery(true);

          -> update('txt')
          -> set('txt.status = 1')
          -> where('txt.status = 0');


    // Run the query
    // $found = (int)
    //use $myDb->query() in Joomla2.5
    // var_dump($data);
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    See in
    how Fabrik is doing it.

    If you are debugging in the backend (disable the scheduled task, use the "Run" button to start) you can include debugging output and exit; in your code.
  3. SoilentRed

    SoilentRed Caaan do!

    Level: Community
    Dumb question:

    Is the scheduler going to run this code for each row? or do I need to loop through each row in my code?
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    If you are running the PHP cron plugin, you have two choices. You can either specify the list youw ant to use, and the row limit, and then that list data will be in $data, in our usual grouped format ...

    Code (Text):

    foreach ($data as $group) {
       foreach ($group as $row) {
          // element are in $row->tablename___elementname
    ... or don't specify a list, and look up the data you want yourself in the database. I usually do the latter, as relying on the list data being loaded for you has a number of potential issues. Firstly, it goes through our full getData() process, including full rendering of every elements, which can be VERY expensive for large datasets. Secondly, if you have any ACL's on your list, you probably won't see all the data ... because of the way we have to do scheduled tasks in Joomla, which is running a plugin after page load, you never know what access you'll have, because you don't know who will have loaded the page when the cron happens to fire.

    -- hugh

Share This Page