Fabrik Schedule with email plugin only works when manually run

Just tested (recent GitHub):
calling the cron with correct Query secrect but URL going to an unaccessible menu item (ie, displaying the login screen instead of menu from URL):
is creating a fabrik_log entry, is setting the last run time, but is doing nothing
So you have to make sure that your wget is calling an accessible menu item

But additionally this issue is still the same
https://github.com/Fabrik/fabrik/issues/1591
So if the Query secrect is not correct (as in your example with fabrik_cron=2) the scheduled task will show a recent "last run" time but would have done nothing

And just to mention it: https://github.com/Fabrik/fabrik/issues/1590
 
I semi fixed that time display. Not too stressed about time zones, just got the time part showing. Folk can figure it out. :)

Sent from my HTC One using Tapatalk
 
I can't replicate that password thing. If I set my query string secret wrong, it doesn't run, and doesn't set the last run time.

If you look at the code of the fabrikcron.php, you'll see that's as it should be. In the main loop, starting around 223, it checks the secret at line 237, and if that's false, it continues back to the top of the loop. The last run would only get reset if reschedule() was run, at line 277.

Now, if the script runs, but it errors out, it will set last run, as the new error handler specifically does that, to get round that old "run gating" issue of crons not getting rescheduled if they errored out.

-- hugh
 
My issue with all of my lists being private is still going to be an issue. So, is there another way to do the Cron Job? How about having the Cron Job run a php file like the following:
/usr/bin/php /path/to/site/cli/run_schedule_resource_reminder_emails.php
I just don't know what to put in the "run_schedule_resource_reminder_emails.php" file. I came across a feature within "ProjectFork" that does something similar; per the following.
https://www.projectfork.net/docs/15-basics/79-email-notifications
Below is what is within the pfnotifications_j3.php that is listed in the above article that they instruct to have the Cron Job run.
Code:
<?php
/**
* @package      Projectfork Notifications
*
* @author       Tobias Kuhn (eaxs)
* @copyright    Copyright (C) 2006-2013 Tobias Kuhn. All rights reserved.
* @license      http://www.gnu.org/licenses/gpl.html GNU/GPL, see LICENSE.txt
*/

// Initialize Joomla framework
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php')) {
    require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES')) {
    define('JPATH_BASE', dirname(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';


/**
* Cron job to send Projectfork notifications
*
* @since      4.2
*/
class PFNotificationCron extends JApplicationCli
{
    /**
     * Entry point for the script
     *
     */
    public function doExecute()
    {
        $mailfrom = JFactory::getConfig()->get('mailfrom');
        $fromname = JFactory::getConfig()->get('fromname');
        $db       = JFactory::getDbo();

        // Get plugin params
        $query = $db->getQuery(true);

        $query->select('params')
              ->from('#__extensions')
              ->where('element = ' . $db->quote('pfnotifications'))
              ->where('type = ' . $db->quote('plugin'));

        $db->setQuery($query);
        $plg_params = $db->loadResult();

        $params = new JRegistry();
        $params->loadString($plg_params);

        $limit = (int) $params->get('cron_limit');


        // Get a list of emails to send
        $query->clear();

        $query->select('id, email, subject, message, created')
              ->from('#__pf_emailqueue')
              ->order('id ASC');

        $db->setQuery($query, 0, $limit);
        $items = $db->loadObjectList();

        if (!is_array($items)) $items = array();

        // Send and delete each email
        foreach ($items AS $item)
        {
            $mailer = JFactory::getMailer();
            $mailer->sendMail($mailfrom, $fromname, $item->email, $item->subject, $item->message);

            $query->clear();
            $query->delete('#__pf_emailqueue')
                  ->where('id = ' . (int) $item->id);

            $db->setQuery($query);
            $db->execute();
        }
    }
}

JApplicationCli::getInstance('PFNotificationCron')->execute();

Unlike the way it's done in pfnotifications_j3.php; what I would like to know is the code to just run my Fabrik schedule in the same way that I do when I manually run it on the administrator end because the schedule always works correctly when I do it manually. If this should work; then could I trouble you folks for a sample of this code that I could put into a run_schedule_resource_reminder_emails.php" file?
Thanks in advance.
 
You can set up a php cron job (with some dummy list, or maybe you can omit the list selection completly, I'm not sure) doing queries and mailing on your own.

But you'll need a "free" menu item to trigger this scheduled task (it can be any, nothing to do with Fabrik).

@cheesegrits:
Is it possible to add something like "run task as user(group) xy"? At least if the Query Secret is set?
So you don't need to create lists with access levels/prefilters/import truncate+override etc. for Public because this access is needed in cron jobs?

The last run would only get reset if reschedule() was run,
I didn't test again, but this is what I'd found in https://github.com/Fabrik/fabrik/issues/1591
 
Unlike the way it's done in pfnotifications_j3.php; what I would like to know is the code to just run my Fabrik schedule in the same way that I do when I manually run it on the administrator end because the schedule always works correctly when I do it manually. If this should work; then could I trouble you folks for a sample of this code that I could put into a run_schedule_resource_reminder_emails.php" file?
Thanks in advance.

Not really, it would take me longer to figure it out and tell you how to do it than to do it myself, and it's way beyond "standard" sub support. You can look at our schedule (cron) plugin code, which does all the grunt work running on the onAfterRender hook on a page load.

-- hugh
 
Hi Hugh.
I looked at the fabrikcron.php; but it's way over my head. So, I went back to trouble-shooting why the 'wget site/index.php?fabrik_cron=resource' wasn't working for me. When I paste the 'site/index.php?fabrik_cron=resource' into my browsers url and run it I receive the schedule event log email that says the following:
updates 0 records email listid = 11 SELECT SQL_CALC_FOUND_ROWS DISTINCT `bw_resources`.`id` AS `bw_resources___id`, `bw_resources`.`id` AS `bw_resources___id_raw`, `bw_resources`.`date_time` AS `bw_resources___date_time`, `bw_resources`.`date_time` AS `bw_resources___date_time_raw`, `bw_resources`.`name` AS `bw_resources___name`, `bw_resources`.`name` AS `bw_resources___name_raw`, `bw_resources`.`reminder_date` AS `bw_resources___reminder_date`, `bw_resources`.`reminder_date` AS `bw_resources___reminder_date_raw`, `bw_resources`.`scan_docs` AS `bw_resources___scan_docs`, `bw_resources`.`scan_docs` AS `bw_resources___scan_docs_raw`, `bw_resources`.`current_status` AS `bw_resources___current_status`, `bw_resources`.`current_status` AS `bw_resources___current_status_raw`, `bw_resources`.`id` AS slug , `bw_resources`.`id` AS `__pk_val` FROM `bw_resources` ORDER BY `bw_resources`.`name` ASC
If I manually run the same Fabrik schedule in the back end then it works and sends the reminder email correctly. It also sends the schedule event log email that says the following:
updates 1 records email listid = 11
The condition of the related record didn't change within the 2 minutes that I did this test of both. It seems like the wget process has different results than the manual run of the same schedule.
I then tried another test. I removed the "query secret" & I turned off the "require querystring". I then browsed to the web page and it ran correctly with the same results as running it manually in the back end; but only once (my "every=1 Unit=minutes). It just wouldn't work again on page refresh. So, I then changed the "unit=seconds" and refreshed the front end page again and it ran correctly with the same results as running it manually in the back end; but only once, again. Is this a bug or am I looking at this wrong? Any suggestions why and what I can do to resolve this?
Thanks in advance, Hugh.
 
I came across this thread, searching for cron email answers I have been stuck with for most of last year, and am still experiencing. I realise this is an old post, but did you ever figure this out? I'm experiencing more or less the same issues as you, on different sites, with everything set to public, I don't even have private lists.

The weirdest thing is, one of the sites that do not have server crons setup, runs more or less as expected, even though it's not always at the times set up. The other two with server crons running wget commands seem to only run randomly, I cannot figure out what exactly makes them work and when or why.

Same as you, I receive emails from the server crons, but not the fabrik crons. And here's the really weird thing, Fabrik still updates the last run date/time, even though it does not send anything out.
 
I gave up on the Fabrik schedules for sending out auto-emails based on DB data. I've been using only wget cron jobs for the past year and they've been working well for me.
 
I'm doing a lot of automatic emailing via Fabrik cron using the php plugin.

By doing the DB access directly in the code you don't have access restrictions and mailing via Fabrik or Joomla helpers is no problem.
 
@Bren so your tasks run if you do a wget command?

I have the most random problem. 3 sites with crons. On one, it's only fabrik's cron, and the emails eventually all go out, even though randomly and on some days not at all, but they all get out eventually. Then I have another that runs with a wget command from the server. Some run, and some I have to go in and run manually from time to time.
Then the third one was setup from scratch, didn't touch any permissions, or anything, so it's all public. Setup with server crons to make them run, and they simply don't run at all. I have to run them manually every day.

@troester wish I had the skills to write code like that.
 
Just reporting what I discovered.

I decided yesterday to do a test with that one site where everything is set up with default settings, yet the tasks won't run with a wget command from the server. So what I did was, switch off the server crons and switch off the 'require query string' in fabrik. And voila, all tasks are running...

The mystery continues. ;)
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top