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

Fabrik 3.9: Recoverable fatal error in databasejoin.php on line 1522

Discussion in 'Standard Support' started by Roland, Nov 13, 2018.

  1. Roland

    Roland Member

    Level: Community
    Hi there,

    after updating to Joomla 3.9 and Fabrik 3.9 I get an PHP error on saving form data in the frontend which contains a databasejoin field. This is the error message:
    Recoverable fatal error: Object of class stdClass could not be converted to string in /home/www/neue-politische-literatur.de/plugins/fabrik_element/databasejoin/databasejoin.php on line 1522

    All changes on editing the form data are being saved, even changes in the databasejoin field.
    I tried to use one of the default forms coming with Fabrik, but I get the same error message.

    Do you have an idea?
     
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    Which php version?
     
  3. Roland

    Roland Member

    Level: Community
    PHP 7.2
     
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    I can't replicate.
    What are your element settings?
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I can't replicate this.

    Are your joins rendered as dropdowns, or checkbox / multiselect?

    -- hugh
     
  6. Roland

    Roland Member

    Level: Community
    The joined field is added to form by an extra group. The form is about reviewing books. It is possible to add 1 to x reviewed books.
    It seems that the problem is not the joined field but my own PHP addon that runs after the form.
    The way of selecting the form variable seems not to work anymore. At least there was no error message with Fabrik 3.8.1
    This is the code of my addon:
    $id_rezensent = $formModel->formData['id_rezensent'][0];
    foreach ($formModel->formData['id_buecher'] as $array_value) {
    foreach ($array_value as $id_buch) {
    $db = JFactory::getDbo();
    $query = $db->getQuery(true);
    $query->update('#__npl_buecher');
    $query->set("RezId = '" . $id_rezensent . "'");
    $query->where("id = '" . $id_buch . "' LIMIT 1");
    $db->setQuery($query);
    $db->execute();
    //echo "<br>id_buecher $id_buch: $query\n";
    }
    }

    $formModel->formData['id_rezensent'][0] and
    $formModel->formData['id_buecher'] seem not to work.
    When I deactivate the addon, I don't get an PHP error.
    I changed the code and get the variables now, but still have problems to convert them into text and explode to an array.
    I need the raw data of the form with numbers. There can be x instances of jos_npl_buecher_beitraege___id_buecher_raw, so I try to explode $buecher by comma which does not work:

    $id_rezensent = '{jos_npl_beitraege___id_rezensent_raw}';
    $buecher = strval('{jos_npl_buecher_beitraege___id_buecher_raw}');
    $id_buch = explode(',', $buecher);
    echo '<pre>Script: beitraege_addon.php<br />';
    echo 'id_rezensent: '. $id_rezensent . '<br />';
    echo 'buecher: ' $buecher) . '<br />';
    echo 'id_buch[0]: '. $id_buch[0] . '<br />';
    echo 'id_buch[1]: '. $id_buch[1] . '<br />';
    echo '</pre>';


    Output:
    Script: beitraege_addon.php
    id_rezensent: 2573
    buecher: 19343,19158
    id_buch[0]: 19343,19158
    id_buch[1]:

    Which way of selecting variables would you suggest?
     
  7. troester

    troester Well-Known Member Staff Member

    Level: Community
    In any case you shouldn't use $db..., this may override variables used by Fabrik.
    Use something like
    $mydb = JFactory::getDbo();
    ...
    $mydb->....

    For your php plugin
    http://fabrikar.com/forums/index.php?wiki/php-form-plugin/#accessing-form-data

    For debugging don't use "echo" but var_dump() or print_r() or the jdump extension to see not only some string conversion but the structure of the variables (arrays, objects...) you want to use.
     
  8. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    What hook are you running your plugin code on? Like, onAfterProcess, or onBeforeStore etc.

    Hugh
     
  9. Roland

    Roland Member

    Level: Community
    Thank you for the hints for variable names and debugging. I will implement it the suggested way.

    I run the script onAfterProcess because I need to save data in another table after the current form is saved.
    In mode onAfterProcess even when I activate the simple plugin dump.php or using the PHP code field (echo 'Hello world';) it returns this error message:
    "Recoverable fatal error: Object of class stdClass could not be converted to string in /home/www/neue-politische-literatur.de/plugins/fabrik_element/databasejoin/databasejoin.php on line 1522"

    Same effect with onBeforeProcess, onBeforeCalculations and onBeforeStore.
    There is no PHP error when I activate getBottomContent or getEndContent.

    Roland



     
  10. troester

    troester Well-Known Member Staff Member

    Level: Community
    I can replicate meanwhile (i.e. I run into the same issue;))
    @cheesegrits : we had this in Skype

    php7.2 issue (ok with 7.0)
    Recoverable fatal error: Object of class stdClass could not be converted to string in ...plugins/fabrik_element/databasejoin/databasejoin.php on line 1522
    To replicate the issue: add a dbjoin to a repeat group,
    set "link to joined record" ("add option in frondend" yes/no doesn't matter)

    It is throwing this error in the FORM view on Save (although the form doesn't have a "link to joined record"), details view and list view are ok.
    Despite the white screen with this error the record is saved correctly.
     
  11. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
  12. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    I think prior to 7.2 there was a "magic method" for objects in PHP, if you tried to use them in a string context, which would just concatenate all the object values together into a string.

    -- hugh
     
  13. troester

    troester Well-Known Member Staff Member

    Level: Community
    fixed:)
     
    cheesegrits likes this.

Share This Page