mazedigital / association_output

Association Output for Symphony: Inline XML
MIT License
5 stars 4 forks source link

Error with Symphony 2.5.3 #10

Open tonyarnold opened 9 years ago

tonyarnold commented 9 years ago

Hi Nils,

I know you're probably not working on this anymore, but I thought I'd pop this issue in for posterity's sake. I'm seeing an error whenever I try to edit a datasource under Symphony 2.5.3 and it's pointing it's finger at this extension.

Symphony Warning: Invalid argument supplied for foreach()

An error occurred in /Users/tonyarnold/Sites/drcwine.com.au/extensions/association_output/extension.driver.php around line 118
113 $fields = FieldManager::fetch(null, $association['parent_section_id']);
114
115 foreach ($fields as $field) {
116 $modes = $field->fetchIncludableElements();
117
118 foreach ($modes as $mode) {
119 $value = $association['parent_section_id'] . '|#|' . $association['parent_section_field_id'] . '|#|' . $label . '|#|' . $mode;
120 $selected = false;
121
122 if ($section_id == $settings['section_id'] && isset($settings[$label])) {

Backtrace

[/Users/tonyarnold/Sites/drcwine.com.au/extensions/association_output/extension.driver.php:118]
    GenericErrorHandler::handler();
[/Users/tonyarnold/Sites/drcwine.com.au/extensions/association_output/extension.driver.php:82]
    extension_association_output->buildElementOptions();
[/Users/tonyarnold/Sites/drcwine.com.au/symphony/lib/toolkit/class.extensionmanager.php:706]
    extension_association_output->buildEditor();
[/Users/tonyarnold/Sites/drcwine.com.au/symphony/lib/core/class.administration.php:490]
    ExtensionManager::notifyMembers();
[/Users/tonyarnold/Sites/drcwine.com.au/symphony/lib/boot/func.utilities.php:232]
    Administration->display();
[/Users/tonyarnold/Sites/drcwine.com.au/symphony/lib/boot/func.utilities.php:208]
    symphony_launcher();
[/Users/tonyarnold/Sites/drcwine.com.au/index.php:14]
    symphony();

Database Query Log

[0.0002] SET character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8';
[0.0001] SET CHARACTER SET 'utf8';
[0.0001] SET time_zone = '+11:00';
[0.0006] SELECT SQL_CACHE t1.name, t2.page, t2.delegate, t2.callback FROM `sym_extensions` as t1 INNER JOIN `sym_extensions_delegates` as t2 ON t1.id = t2.extension_id WHERE t1.status = 'enabled' ORDER BY t2.delegate, t1.name;
[0.0002] SELECT SQL_CACHE `session_data` FROM `sym_sessions` WHERE `session` = '3hg8b3873060qb14sbopg9tgt7' LIMIT 1;
[0.0003] SELECT SQL_CACHE a.* FROM `sym_authors` AS `a` WHERE `username` = 'tonyarnold' ORDER BY a.id ASC LIMIT 1;
[0.0002] UPDATE sym_authors SET `last_seen` = '2015-03-07 22:01:43' WHERE `id` = 1;
[0.0003] SELECT SQL_CACHE `name` FROM `sym_extensions` WHERE `status` = 'enabled';
[0.0002] SELECT SQL_CACHE * FROM `sym_extensions`;
[0.0003] SELECT SQL_CACHE `s`.* FROM `sym_sections` AS `s` ORDER BY `s`.`sortorder` asc;
[0.0004] SELECT SQL_CACHE `s`.* FROM `sym_sections` AS `s` ORDER BY `s`.`name` ASC;
[0.0003] SELECT SQL_CACHE * FROM `sym_sections_association` AS `sa`, `sym_sections` AS `s` WHERE `sa`.`child_section_id` = 28 AND `s`.`id` = `sa`.`parent_section_id` ORDER BY `s`.`sortorder` ASC;
[0.0002] SELECT SQL_CACHE `element_name` FROM `sym_fields` WHERE `id` = 218 LIMIT 1;
[0.0002] SELECT SQL_CACHE t1.* FROM sym_fields AS `t1` WHERE 1 AND t1.`parent_section` = '13' ORDER BY t1.`sortorder` ASC;
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_textbox` WHERE `field_id` IN (90);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_uniqueupload` WHERE `field_id` IN (91);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_reflection` WHERE `field_id` IN (435);
[0.0002] SELECT SQL_CACHE `element_name` FROM `sym_fields` WHERE `id` = 295 LIMIT 1;
[0.0003] SELECT SQL_CACHE t1.* FROM sym_fields AS `t1` WHERE 1 AND t1.`parent_section` = '17' ORDER BY t1.`sortorder` ASC;
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_uniqueupload` WHERE `field_id` IN (129);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_textbox` WHERE `field_id` IN (296);
[0.0003] SELECT SQL_CACHE * FROM `sym_fields_reflection` WHERE `field_id` IN (436);
[0.0004] SELECT SQL_CACHE * FROM `sym_sections_association` AS `sa`, `sym_sections` AS `s` WHERE `sa`.`child_section_id` = 13 AND `s`.`id` = `sa`.`parent_section_id` ORDER BY `s`.`sortorder` ASC;
[0.0002] SELECT SQL_CACHE `element_name` FROM `sym_fields` WHERE `id` = 308 LIMIT 1;
[0.0003] SELECT SQL_CACHE t1.* FROM sym_fields AS `t1` WHERE 1 AND t1.`parent_section` = '36' ORDER BY t1.`sortorder` ASC;
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_publish_tabs` WHERE `field_id` IN (304,309);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_textbox` WHERE `field_id` IN (305,306,419,420,310);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_association` WHERE `field_id` IN (307,308);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_enhancedtaglist` WHERE `field_id` IN (311);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_author` WHERE `field_id` IN (312);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_select` WHERE `field_id` IN (313);
[0.0002] SELECT SQL_CACHE * FROM `sym_fields_html_panel` WHERE `field_id` IN (314);
nilshoerrmann commented 9 years ago

Thanks, Tony. I'l try have a look into this next week.

tonyarnold commented 9 years ago

Thanks Nils.

I ended up editing extension.driver.php and updating buildElementOptions() to look like so:

    private function buildElementOptions($association, $settings, $section_id)
    {
        $elements = array();
        $label = FieldManager::fetchHandleFromID($association['child_section_field_id']);
        $fields = FieldManager::fetch(null, $association['parent_section_id']);

        if (is_array($fields) || $fields instanceof Traversable) {
          foreach ($fields as $field) {
              $modes = $field->fetchIncludableElements();

              if (is_array($modes) || $modes instanceof Traversable) {
                foreach ($modes as $mode) {
                    $value = $association['parent_section_id'] . '|#|' . $association['parent_section_field_id']  . '|#|' . $label . '|#|' . $mode;
                    $selected = false;

                    if ($section_id == $settings['section_id'] && isset($settings[$label])) {
                        if (in_array($mode, $settings[$label]['elements'])) {
                            $selected = true;
                        }
                    }

                    $elements[] = array($value, $selected, $mode);
                }
              }
          }
        }

        return array(
            'label' => $label,
            'data-label' => $section_id,
            'options' => $elements
        );
    }

Note the if (is_array($fields) || $fields instanceof Traversable) { … } around the lines that were failing. It seems to work without ill effect, but I don't know enough about your code to know if there are other consequences to doing this.

nilshoerrmann commented 9 years ago

Thanks, Tony!

animaux commented 9 years ago

I have a similar issue on a 2.6.0 install. However on an almost similar installation it works.

savosik commented 8 years ago

why this bug is closed without any commit ?

nilshoerrmann commented 8 years ago

The related commit is here, it just wasn't referenced: https://github.com/mazedigital/association_output/commit/018dcb651c3b5384aa1c241cd6b60d26a64d1bcc

savosik commented 8 years ago

ok. Is this commit merged to master ? I installed latest version from master - error happened. I manually changed this part of code ...

nilshoerrmann commented 8 years ago

It's in master representing version 1.1.0. If you had to change these lines manually, your extension version must have been out of date.

savosik commented 8 years ago

Look at master https://github.com/mazedigital/association_output/blob/master/extension.driver.php#L119

if (is_array($modes) || $modes instanceof Traversable) {

this string is not there

nilshoerrmann commented 8 years ago

Ah, good catch! Seems like the fix has only been halfway through.

/cc @jonmifsud

animaux commented 7 years ago

@nilshoerrmann Is it possible this is still not in 1.2.0?

nilshoerrmann commented 7 years ago

Possible, yes.

animaux commented 7 years ago

For some strange reason I have two almost identical installations where in one I can edit the DSes without problems, while in the other I always get this error. However replacing the buildElementOptions() like @tonyarnold did here helps.

nilshoerrmann commented 7 years ago

We haven't been using this extension lately. Asking @jonmifsud to jump in as he might know the current state of the extension better than I do.

animaux commented 7 years ago

Thanks Nils. I love the way we can summon people here like dæmons in a pagan ceremony :·D

animaux commented 7 years ago

This is still a problem for me. @jonmifsud would you be able to investigate?

animaux commented 6 years ago

Still turning up …

twiro commented 6 years ago

Still turning up …

Confirmed! This error just showed up in a Symphony 2.6.11 project for me...

animaux commented 6 years ago

@tonyarnold’s fix still works in Symphony 2.7.0, though.