Sheduled task - plugin php - problem to write 'php setup'

Hi,
I try to write script that will run 2 times a day - the script should update column {ccjom_cc_lista_zastepstw___dzisiaj} with value 'dzisiaj' (in EN = today) if range of 2 columns :
{ccjom_cc_lista_zastepstw___data_zas_od1} -- datestart
{ccjom_cc_lista_zastepstw___data_zas_do1} -- dateend
include "today" -- todaydate

I try to do this with sheduled task - plugin php - php setup
So, this code that i write doesn't work (doesn't update column {ccjom_cc_lista_zastepstw___dzisiaj} )
Could you help me to modify this?


Code:
$db =& JFactory::getDBO();
$datestart = strtotime("{ccjom_cc_lista_zastepstw___data_zas_od1}");
$dateend = strtotime("{ccjom_cc_lista_zastepstw___data_zas_do1}");
$todaydate = strtotime("today");
 
$todayholiday = '{ccjom_cc_lista_zastepstw___dzisiaj}';
 
$query = "UPDATE `ccjom_cc_lista_zastepstw` SET `dzisiaj`='dzisiaj' WHERE ($datestart <= $todaydate and $dateend => $todaydate)";
 
//var_dump($query);exit; //uncomment for debugging
 
$db->setQuery($query);
$db->query();
 

Attachments

  • Zaznaczenie_476.png
    Zaznaczenie_476.png
    39.3 KB · Views: 333
Hi, i try also in field "PHP Script" to use my script that is in file today-fromto.php
it has code:
PHP:
// Check to ensure this file is included in Joomla!
// defined('_JEXEC') or die();
 
// $data = $listModel->getData();
// $data = $data[0][0];
 
// $db = FabrikWorker::getDbo();
$db =& JFactory::getDBO();
 
$from = strtotime("{ccjom_cc_lista_zastepstw___data_zas_od1}");
$to = strtotime("{ccjom_cc_lista_zastepstw___data_zas_do1}");
 
$now = time();
if($from <= $now && $to >= $now) {
    // It's between
$query = "UPDATE `ccjom_cc_lista_zastepstw` SET `dzisiaj`= 'dzisiaj' ";
 
$db->setQuery($query);
$db->query();
 
}
but this doesn't update column `dzisiaj`.
This works only without "if line":
without:
if($from <= $now && $to >= $now) {

and then update all records.

Is something wrong for fabrik with my "if line" ?
 
Hi,
I modify my script and now it works but there are others small problems concerned this.
My code is:
PHP:
<?php
// Check to ensure this file is included in Joomla!
// defined('_JEXEC') or die();
 
// $data = $listModel->getData();
// $data = $data[0][0];
 
// $db = FabrikWorker::getDbo();
$db =& JFactory::getDBO();
 
$from = strtotime("{ccjom_cc_lista_zastepstw___data_zas_od1}");
$to = strtotime("{ccjom_cc_lista_zastepstw___data_zas_do1}");
$now = time();
 
$query = "UPDATE `ccjom_cc_lista_zastepstw` SET `dzisiaj`= 'nie'";
 
$db->setQuery($query);
$db->query();
 
$query = "UPDATE `ccjom_cc_lista_zastepstw` SET `dzisiaj`= 'dzisiaj' WHERE `data_zas_od1` <= now() AND `data_zas_do1`>= now()";
 
$db->setQuery($query);
$db->query();
 
?>

This:
1. clear values of all records to 'nie' (EN = 'no')
2. set some values (where data is beetwen) to 'dzisiaj' (EN='today')
= This set in column `dzisiaj` who today has holiday ( not present at office)
----------------------------------------------------------------------------------------------------
I have problems:
1. when manualy "Run" - schedule: ID=6 (CC-16 - Kto ma urlop dzisiaj ) then show:
"0 records updated"
but i have now - 19 records and all are updated - should show:
"19 records updated"


2. when schedule is running then send an email - in this moment to me xxxxxxx@hotmail.com

I get "something strange" in email but i would have to get nice message:
for example:

Schedule ID=6 (CC-16 - Kto ma urlop dzisiaj ) was running.
Updated 19 records.
ccjom_cc_lista_zastepstw___id ---- ccjom_cc_lista_zastepstw___person_name ---- ccjom_cc_lista_zastepstw___dzisiaj
(list of person that have status `dzisiaj`= 'dzisiaj'

Can i ask how to link my own nice emailtemplate1 in html or php to this cron job (schedule Run) ?
 

Attachments

  • Zaznaczenie_479.png
    Zaznaczenie_479.png
    129.7 KB · Views: 297
  • Zaznaczenie_480.png
    Zaznaczenie_480.png
    26.7 KB · Views: 323
  • Zaznaczenie_478.png
    Zaznaczenie_478.png
    26.5 KB · Views: 282
Apologies, I wrote a response to your previous post the other evening, and never hit "Post Reply". Then my laptop died, and I'm just now back up and running with a new one.

I'm reading your latest post now ...

-- hugh
 
OK ...

For the PHP cron plugin, we just call it one time, with all the row data in $data. We don't call your code once for each row. So placeholders don't work, as those are per-row things, and are meaningless in this context.

If you need row by row logic which uses element values form each row, you'll need to loop around $data. As usual, var_dump() is your friend, so the first step to knowing what's in $data would be ...

PHP:
var_dump($data);exit;

... and then "Run" the plugin, which should show you how $data is structured.

Also, unlike the other cron plugins where it's Fabrik's own code running, there's no automatic way to know how many rows were updated, as that's entirely up to you. So the way that works (in 3.0, anyway) is you set the variable $processed to tell us how many you updated. In the PHP plugin, after we've run your code, we then do:

PHP:
        if (isset($processed))
        {
            return (int) $processed;
        }
        return 0;

... which tells the main cron model what to put in that info msg.

For sending mail, you can just do it yourself. See the email plugin for an example of how to do that, which boils down to:

PHP:
                        $mail = JFactory::getMailer();
                        $res = $mail->sendMail($MailFrom, $FromName, $thisto, $thissubject, $thismsg, true);

Obviously you'll have to replace those variables with the values you need. The message ($thismsg) is just some HTML formatted text, which you can create in your code.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top