Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mixing datasource formats on one page fails #37

Closed
kmeinke opened this issue Dec 8, 2017 · 2 comments · Fixed by #43
Closed

Mixing datasource formats on one page fails #37

kmeinke opened this issue Dec 8, 2017 · 2 comments · Fixed by #43
Assignees
Labels

Comments

@kmeinke
Copy link

kmeinke commented Dec 8, 2017

Hello,

first of all thank you for this extension! the new version has improved a lot!

I spend 2 days debugging to find this bug...
I use 2 different Remote_Datasource - one in XML and one in JSON Format - on the same page.

Line 9 of remote_datasource/data-sources/datasource.remote.php defines the $transformer class as static member.
Line 1092 of remote_datasource/data-sources/datasource.remote.php only loads a transformer for given format if no transformer was choosen yet.

The first datasource (XML) is executed - and the XML tranformer is loaded. The 2nd datasource (JSON) is executed, and resuses the XML tranformer - wich fails cause... doh! :)

Because the transformer is a static member, choice is made once per page based on the first format encountered.

i suggest making $transformer an array for formats

    public static function getTransformer($format)
    {
        if (is_array(self::$transformer) && array_key_exists($format, self::$transformer)) {
            return self::$transformer[$format];
        }

        if (!is_array(self::$transformer)) {
            self::$transformer = Array();
        }

        $transformerFile = EXTENSIONS . '/remote_datasource/lib/class.' . strtolower($format) . '.php';
        if (file_exists($transformerFile)) {
            $classname = require_once $transformerFile;
            self::$transformer[$format] = new $classname;
            return self::$transformer[$format];
        }

        throw new Exception("could not load transformer [$transformerFile] for format [$format]");
    }
@michael-e
Copy link
Member

This sounds like an important issue. @nitriques what do you think?

@nitriques nitriques self-assigned this Dec 29, 2017
@nitriques nitriques added the bug label Dec 29, 2017
@nitriques
Copy link
Member

@michael-e it is. Fixing it is easy. Fixing it while not crashing existing data source and ensure they still work will be harder.

@kmeinke Wanna send a PR with your modifications in order to discuss it better ?

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants