Search

Hmn, I’m having some trouble with the validation. I’m not using any namespaces (which worked great with another file/structure). When I run the importer I get the following errors for each entry. However, the file is perfectly readable, and after complaining twice about it not being readable, the importer lists how the fields would be imported, which looks exactly like it should (see attached screenshot). Am I missing something very basic?

Attachments:
Bildschirmfoto 2011-09-29 um 11.22.23.png

@myself ok … I tried to import data in file upload fields, which is apparently not so easy

Just a quick question, does this load the xml automatically or do I have to run the import manually every time I want the load new xml content?

Thanks

Run the importer manually each time you want new content.

You can setup a cronjob to hit the importer URL every so often (using ?auth-token to log the user in) to make it 'automatic' though.

Thanks, a cronjob will do nicely

Rowan has moved this extension into the hands of the Symphonists and I've taken some time tonight to update, tweak and optimise the extension. I've opened up the Issue Tracker and have pushed my commits to the unstable branch for everyone to test.

Thanks Brendan, was wondering where it had moved too.

Could the extensions page be updated? I don't see a flag/comment action at all.

This extension has been updated to 1.1.0

Version 1.1.0, 21 November 2011

  • Fix issues with XPath and namespaces
  • Add $entry_id to prepareImportValue function
  • Added README information about the prepareImportValue function
  • Use the unique Duplicator (where available) to improve the UX
  • Tiny performance enhancements

@jtyoungs I've updated the first message in this thread and the extension page :)

Just used it. Perfect :)

Can functions other than text() or node() be used? I have an XML source that changes order periodically, and I'd like my local data to reflect the updated order by setting "Can update existing entries" to true and my Xpath Expression to ./position(), but this tells me "DOMXPath::evaluate(): Invalid expression".

Not sure if I'm doing something wrong or if it's simply not supported.

I´m having a problem trying to import a xml page created in localy, to explain it better:

i created a page that process a xml from outsite, and change it´s structure. i used this page url, wicth is a xml page, in the xml importer

but no entryes ar imported, i get ( 'No data to import.' ), but if i visit the url, it shows the xml correctly, any ideia of what could be causing this?

RE: I found the problem, as i´m running localhost, and accessing the server with no-ip, i had to use 'http://localhost' instead of 'http://mysite.no-ip'.

Thanks.

I’m experiencing a discrepancy between my local development copy of my site and my production server.

I’m using XML importer with, among other things, an upload field. I’m grabbing a JPEG from an external site based on a URL provided by the XML I’m importing. I’ve got a helper function that takes the URL provided by XML Importer and saves a copy of the file to the appropriate workspace folder:

static function saveBookCover($img) {
// Check if the image is from Amazon or Goodreads and manipulate the URL
// accordingly to get the large version.
if(strpos($img,'images-amazon.com') !== false) {
    $img = preg_replace('#_[a-z0-9]+_.#i', '', $img);
}
else if(strpos($img, 'goodreads.com') !== false) {
    $img = preg_replace('#([0-9])m/#', '$1l/', $img);
}

$name = explode('/', $img);
$name = '/images/book_covers/' . array_pop($name);
file_put_contents(WORKSPACE . $name, file_get_contents($img));
return $name;
}

On both the local and live sites, this function works fine. The file gets saved to my workspace folder, and the appropriate entry gets added to the database. Hurrah!

On the live site, however, the database doesn’t pick up the correct mimetype (it should be image/jpeg) and it doesn’t add the width and height attributes to the meta column. Yet I have no problems on my local setup.

File permissions are the same for both of the files. Just in case I even tried having my function chmodding the files to 0755 after they were saved. No luck.

There are some significant differences between my local and production server—for instance, the local server is running PHP 5.3 while my site is on a server with PHP 5.2.17!

Any ideas would be appreciated. :)

Let's say I need to remotely run an XML Importer periodically, but with a different query string on the source URL each time. Can I do something like this (I've tried and this doesn't work), or is there another way to accomplish this?

Job URL: http://example.com/symphony/extension/xmlimporter/importers/run/importername/?auth-token=123e45f6&id=123456789

Source URL: http://source.com/path/to.xml?id={$url-id}

To achieve this:

http://source.com/path/to.xml?id=123456789

I don't believe the XMLImporter will attempt to parse URL parameters, it should though. Can you log an issue?

In the past we have created a custom event that sits on a page which evaluates the parameters and then programmatically invokes the XMLImporter with these values.

I would post it up but it has some extra logic to prevent server crashes (we run it via a CRON) and some sensitive information in it.

This part I can share (and it's probably the most important to you!)

class your_new_xmlimporter_name extends XMLImporter {
    protected $event;

    public function options() {
        $im = new XMLImporterManager(Frontend::instance());
        $importer = $im->create('handle-of-your-importer');

        $options = $importer->options();
        $options['fields'][] = array(
            'field' => '120',
            'xpath' => $this->event,
            'php' => '',
        );

        return $options;
    }

    public function setEvent($id){
        $this->event = $id;
    }
}

Basically we extend the base XMLImporter and then prepopulate it's values from an existing XMLImporter. Our extended XMLImporter is created ($xmlimporter = new your_new_xmlimporter_name(Frontend::instance();) in the __trigger() function of the Event and then we use setEvent to pass the evaluated parameter(s).

The XMLImporter can then be made to run with:

$status = $xmlimporter->validate('your-xml-string', false);

And then if it's all good, commit() will import the entries.

if ($status == XMLImporter::__OK__) {
    $xmlimporter->commit();
}

You can check for errors with:

$xmlimporter->getErrors();

Or you can have a look individual entry statuses with:

$xmlimporter->getEntries();

Hope that helps.

That's great Brendo, I was thinking about running the xml importer from en event, so I can fetch some entries first and also use url parameters. This will help me a lot. Thanks.

Thanks Brendan, that is very helpful! I have logged an issue and will try the code you provided this weekend.

Hello!

Great extension.

However, at the second attempt onwards when i try to run a Tumblr post import it fails validation.

At first i thought it was because of dupes, but i added Twitter & Facebook importers that run fine each time.

I have no idea what could be wrong, it looks allright to me?

Attachments:
Skärmavbild 2012-02-19 kl. 19.56.28.png

@retypejonas, can you post the remainder of that error?

@bzerangue http://pastie.org/3419193

Import entry #19
"Description" contains invalid XML. The following error was returned: loadXML(): StartTag: invalid element name in Entity, line: 4

It looks like a wysiwyg entry has invalid xml. I would expect it's not the only one in the import like this.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details