• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

[Solved] Control/debug a php cron plugin (in Schedule option)

georgie

Member
Hello

I would work with your excellent PHP cron plugin. I would load a long code, with many variables...

Is it a way to "control" code inside (debug...)?
To display somethings like "echo", "print_r", var_dump"...

Thank you
 
Yes, you can echo...
but I think you'll need an exit; at least as last statement so you can see you outputs.
Or install the 'dump' extension, it's very usefull for debugging. You can do
dump($somevariable,'some remark');
anywhere and you'll get the output in a pop up, not overridden by page loads so no need to add exit;




Gesendet mit Tapatalk
 
OK, thanks.

Hummm first please, without JDump extension, I can see an array from my list selected in a PHP schedule, just with this in the script, then running the schedule :
Code:
// print_r($data); exit ;

OK for me.
Then to progress step-by-step, I would be able to recover my fields one-by-one. But I can not, doing this:
Code:
var_dump($array["[MyTable___MyFieldA]"]); exit ;

However "[MyTable___MyFieldA]" is well displayed in the array shows by "print_r($data)".

Please can you help me to do this? Knowing that at term, I would be able to store each field/value in variables (to use it in a future query).

Thanks in advance for all advices.
 
Thanks for this syntax, which seems better than mine.

But no, I have always an "NULL" response.

Please you see another thing to add?
 
I think it is a object in an array.

Like this for example:
Code:
Array ( [0] => Array ( [0] => stdClass Object ( [wosweb_users___id] => 1013
[wosweb_users___id_raw] => 1013 [wosweb_users___name] => Mishel XXX
[wosweb_users___name_raw] => Mishel xxx[wosweb_users___email] =>
mishel.xxx@gmail.com [wosweb_users___email_raw] =>
mishel.xxx@gmail.com [wosweb_users___username] => XXX...
 
I think it is a object in an array.

Like this for example:
Code:
Array ( [0] => Array ( [0] => stdClass Object ( [wosweb_users___id] => 1013 [wosweb_users___id_raw] => 1013 [wosweb_users___name] => Mishel Makary [wosweb_users___name_raw] => Mishel Makary [wosweb_users___email] => mishel.everlastwellness@gmail.com [wosweb_users___email_raw] => mishel.everlastwellness@gmail.com [wosweb_users___username] => MMakary...
 
Yes, the $data in a PHP cron plugin is an array of arrays of objects. The outer array is groups, inner array is rows. Each row is an object. Even if your list is not "grouped", you'll still have that outer array, with just one entry.

Typically the way you process it is ...

Code:
foreach ($data as $group) {
   foreach ($group as $row) {
      // do stuff with $row->yourtable___yourelements for each row
   }
}

-- hugh
 
Hello

"an array of arrays of objects" OOOOk!

My test works, I keep to work, but please some advices about my way, to verify that I am not in a bad direction :

At term I would play a query to insert some data from my Fabrik list pointed by my Cron PHP plugin, into others tables from another DB (joined tables morever, why do it simple).
I already verified my SQL query "in text", it works in DB.

So now, I think I have just to replace my "text" in query by my variables recovered with "foreach".
I think all will be OK, and easy, if my data would not be an array. But... it is an array, normal for a Fabrik list.

But I do not know how "loop" a query, to execute them for each rows of my array.

I imagine thing like this for now:
Code:
<?php
defined('_JEXEC') or die('Restricted access');

// Create my variables, thanks to you
foreach ($data as $group) {
   foreach ($group as $row) {
    $var1 = $row->TableA___Field1 ;
    $var2 = $row->TableA___Field2 ;
    $var3 = $row->TableB___Field1 ;
    $var4 = $row->TableC___Field1 ;
...
   }
}

// Then my query
$db = FabrikWorker::getDBO(false, MyRemoteConnexionID);

$query = "

BEGIN;
INSERT INTO MyTableA (MyField1, MyField2, ...)
values ('$var1', '$var2', ...) ;

INSERT INTO MyTableB (id, MyField1, ...)
values (LAST_INSERT_ID(), '$var3', ...) ;

INSERT INTO MyTableC (add_id, MyField1)
values ( (SELECT MAX(id) from MyTableB) ,  '$var4', ...) ;
COMMIT;

" ;

$db->setQuery($query);
$db->query();
?>
I go to do some tests in a test-DB, but if you have some advices... I take!

Is it possible to "loop" a query for each rows from a list?

Thanks you
 
Just put the actual queries in the loop.

Code:
<?php
defined('_JEXEC') or die('Restricted access');

$db = FabrikWorker::getDBO(false, MyRemoteConnexionID);

// Create my variables, thanks to you
foreach ($data as $group) {
   foreach ($group as $row) {
    $var1 = $row->TableA___Field1 ;
    $var2 = $row->TableA___Field2 ;
    $var3 = $row->TableB___Field1 ;
    $var4 = $row->TableC___Field1 ;
...

      // Then my query

$query = "

BEGIN;
INSERT INTO MyTableA (MyField1, MyField2, ...)
values ('$var1', '$var2', ...) ;

INSERT INTO MyTableB (id, MyField1, ...)
values (LAST_INSERT_ID(), '$var3', ...) ;

INSERT INTO MyTableC (add_id, MyField1)
values ( (SELECT MAX(id) from MyTableB) ,  '$var4', ...) ;
COMMIT;

" ;

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


?>
 
Hello

Hummm... Thanks it seems be in the right way, but as it, it does not work.
An error appears:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO customer (civility, lastname, firstname, email) VALUES ('Dr', 'Maka' at line 3

However when I do a var_dump for my query, she is full OK (but just one query is displayed).
If I copy-paste this query generated in DB, SQL tab : full OK, executed!

Hummm I do not understand...:mad:

I suspect the sequence of queries "INSERT INTO" with "BEGIN" and "COMMIT" to be responsible for a PHP-related error, but I can not see it (or I do not know how).

If I just delete "BEGIN" and "COMMIT" (keeping all my "INSERT INTO"), no changes, it does not work.
If I do just one "INSERT INTO" with "BEGIN" and "COMMIT", no changes, it does not work.
If I do just one "INSERT INTO" without "BEGIN" and "COMMIT", so OK, it works.

I think it is the loop which does not manage the "BEGIN" and "COMMIT".

Please have you an idea?:p

Here my full code:
Code:
<?php

defined('_JEXEC') or die('Restricted access');

// Variables
foreach ($data as $group) {
   foreach ($group as $row) {
  
     $wos_title = $row->profiles___title_raw ;
     $wos_firstname = $row->profiles___firstname_raw ;
     $wos_lastname = $row->profiles___lastname_raw ;
     $wos_email = $row->wosweb_users___email_raw ;
     $wos_country = $row->address___country ;
     $wos_code_phone1 = $row->telephones___code_phone1 ;
     $wos_phone1 = $row->telephones___phone1 ;

// Query
$db = FabrikWorker::getDBO(false, 3);

$query = "

BEGIN;

INSERT INTO customer (civility, lastname, firstname, email)
VALUES ('$wos_title', '$wos_lastname', '$wos_firstname', '$wos_email') ;

INSERT INTO address (id_customer, country)
VALUES (LAST_INSERT_ID(), '$wos_country') ;

INSERT INTO telephone (id_customer, id_address, code_tel1, tel1)
VALUES ( (SELECT MAX(id_customer) FROM customer) , (SELECT MAX(id_address) from address) , '$wos_code_phone1', '$wos_phone1') ;

INSERT INTO customer_organisme (id_customer, id_organisme)
VALUES ( (SELECT MAX(id_customer) FROM customer) , '1') ;

COMMIT;

" ;

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

   }

}

?>
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top