I would like to run a cron job to loop through the entries in a section and to take a date out of a text field and add it to a date field.

This is the result of a legacy system which used a text field where a date field would have been much better. I now want to filter by dates.

At present I have XML looking like this:


The data source has this customisation added to the end of it:

        $xml = simplexml_load_string($result->generate());
        foreach($xml->xpath('//entry') as $entry) {
            $id = $entry->attributes()->id;
            $paid_until = XXXXXXXXXX;
            Symphony::Database()->query("UPDATE sym_entries_data_268 SET value = $paid_until WHERE entry_id=$id");
            echo("Updated entry $id.";

The problem is that I don't know the syntax for retrieving the value of mc-paid-untilin each entry so that I can insert it into new the new database field.

What does echo'<pre>';print_r($entry);echo'</pre>'; or var_dump($entry); give when inside the foreach construct?

It doesn't solve your customisation issue, but maybe your underlying problem: why don't you create a page that just returns the XML of your data source. You could then use this page as a source in XML Importer, adding your input's value to the date field on import.

Nils solution is the most elegant and error proof.

Thanks guys. I agree Nils' technique is probably more correct, but there are complications (its a members sections with no unique keys other than ID) which make that approach a little bloated compared to the alternative. I would need to add a (reflection) field to the section and install a new extension. The DS approach would avoid both of these and keep things lean.

@DavidOliver adding echo'<pre>';print_r($entry);echo'</pre>'; outputs the following for each entry:

SimpleXMLElement Object ( [@attributes] => Array ( [id] => 15055 ) [mc-paid-until] => 2013-12-13 )

The full DS source is here:

Based on Basic SimpleXML usage, I think it’s:

$paid_until = $entry->mc-paid-until;

You can do this in SQL too, without any PHP or what not.

UPDATE sym_entries_data_268 as `t268` SET value = (SELECT value FROM sym_entries_data_{entry_id} as `txyz` WHERE `txyz`.entry_id=`t268`.entry_id)

@DavidOliver That was indeed what I'd expect but $entry->mc-paid-until returns zero.

Thanks Brendo. Yes, I'll do it that way.

Ah, it's probably the hyphens. If you still want to do it with PHP, you could try $entry->{'mc-paid-until'}.

Accessing elements within an XML document that contain characters not permitted under PHP's naming convention (e.g. the hyphen) can be accomplished by encapsulating the element name within braces and the apostrophe.

Mr Oliver I owe you a beer :-)

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