Skip to content

Commit

Permalink
WIP: festival: Add clunky but working migration
Browse files Browse the repository at this point in the history
  • Loading branch information
matthijskooijman committed Sep 1, 2020
1 parent 03b90f7 commit a775672
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions system/datatypes/festival.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,59 @@ public function __construct($pageListNode, RequestContext $O_O) {
parent::__construct($pageListNode, $O_O);
$this->xml = new Xml('festival', Xml::multiLingualOn, Xml::versionsOff);
$this->xml->loadFromFile('data/pages/'.$pageListNode->getAttribute('id'));

$this->migrate();
}

public function migrate() {
if ($this->xml->documentElement->getAttribute('migrated'))
return;
$this->xml->lockAndReload();

// Make sure day ids are valid ids (starting
// with a letter).
foreach ($this->getConfigElement(self::CONFIG_ID_DAYS, self::CONFIG_TAG_DAYS)->children() as $day)
$day->setId('day' . $day->getId());

foreach ($this->xml->find(self::TAG_CONTRIBUTION_EVENT) as $event)
$event->setAttribute(self::ATTR_EVENT_DAY, 'day' . $event->getAttribute(self::ATTR_EVENT_DAY));

// Duplicate the header
$header = $this->getConfigElement('header');
if ($header) {
$this->getConfigElement(self::CONFIG_ID_LINEUP_HEADER, self::CONFIG_TAG)->append($header->html());
$this->getConfigElement(self::CONFIG_ID_TIMETABLE_HEADER, self::CONFIG_TAG)->append($header->html());
$header->remove();
}

// Make stuff translated
foreach ($this->xml->find(self::TAG_CONTRIBUTION) as $c) {
$lang = $this->xml->createElement(self::TAG_CONTRIBUTION_LANGUAGE);
$lang->setAttribute(self::ATTR_LANGUAGE_ID, 'nl');
$c->append($lang);
foreach ([self::ATTR_CONTRIBUTION_IMAGE, self::ATTR_CONTRIBUTION_NAME, self::ATTR_CONTRIBUTION_TITLE, self::ATTR_CONTRIBUTION_WEBSITE, self::ATTR_CONTRIBUTION_CATEGORY] as $attr) {
$lang->setAttribute($attr, $c->getAttribute($attr));
$c->removeAttribute($attr);
}
$lang->append($c->get(self::TAG_CONTRIBUTION_DESCRIPTION));
}

foreach ([self::CONFIG_ID_CONTRIBUTION_FORM, self::CONFIG_ID_SIGNUP_FORM, self::CONFIG_ID_LINEUP_HEADER, self::CONFIG_ID_TIMETABLE_HEADER, self::CONFIG_ID_ABOUT] as $id) {
$c = $this->getConfigElement($id);
if ($c) {
$lang = $this->xml->createElement(self::CONFIG_TAG_LANGUAGE);
$lang->setAttribute(self::ATTR_LANGUAGE_ID, 'nl');
$lang->append($c->children());
$c->append($lang);
}
}


$this->xml->documentElement->setAttribute('migrated', 1);
$this->xml->saveAndUnlock();
}


public static function getDatatypeName() {
return __('datatype.name.festivalpage');
}
Expand Down

0 comments on commit a775672

Please sign in to comment.