OK, only needed a short amount of time to get to where I am so I am really seeing the speed of Processwire development.
The code below is adding pages just fine, my next step would be to check when this is run again if the page is already in the database, then do an update, if it isn't then add. As you will see the XML file contains a Refnumber which I add to Processwire so we can match stuff up.
public function ___executeImport() {
Wire::setFuel('processHeadline', 'Complete');
$out = '<h2>Properties import</h2>';
$xml = wire('config')->paths->templates.DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR.'properties.xml';
if(file_exists($xml)) {
$this->message("The XML file has been found");
$xml = simplexml_load_file($xml);
foreach($xml->Properties->Property as $property) {
$page = new Page();
$page->template = 'basic-page';
$page->parent = $this->pages->get(1017);
$page->name = $property->Number . $property->Street . $property->Address3;
$page->title = $property->Number. ' ' .$property->Street. ', ' .$property->Address3;
$page->property_ref = intval($property->Refnumber);
$page->save();
}
} else {
$this->error("The XML file cannot be found");
}
}
I am guessing I need to make a start by getting the pages:
$properties = wire('pages')->get(1017)->children()->find("template=basic-page");
And then checking the property_ref field.
Any guidance of the best way of doing this would be great.