コード例 #1
0
 public static function migratePages()
 {
     $pages = Symphony::Database()->fetch("SELECT * FROM `tbl_pages`");
     // Creates DOMDocument object
     $xml = new DOMDocument('1.0', 'UTF-8');
     $xml->preserveWhiteSpace = false;
     $xml->formatOutput = true;
     // Root node
     $root = $xml->createElement('pages');
     // Page entries
     $entries = $xml->createElement('entries');
     if (is_array($pages) && !empty($pages)) {
         foreach ($pages as $page) {
             // Ensures that pages has a guid
             if (!$page['guid']) {
                 $page['guid'] = uniqid();
                 Symphony::Database()->update(array('guid' => $page['guid']), 'tbl_pages', "id = {$page['id']}");
             }
             $entry = $xml->createElement('entry');
             foreach ($page as $column => $value) {
                 if ($column == 'id') {
                     continue;
                 }
                 $data = $xml->createElement($column, $value);
                 $entry->appendChild($data);
             }
             $entries->appendChild($entry);
         }
     }
     // Page types
     $types = MigrationManager::getPagesTypes($page['guid']);
     $pages_types = $xml->createElement('types');
     if (is_array($types) && !empty($types)) {
         foreach ($types as $page_type) {
             $type = $xml->createElement('type');
             foreach ($page_type as $column => $value) {
                 if ($column == 'type') {
                     $value = implode(', ', $value);
                 }
                 $data = $xml->createElement($column, $value);
                 $type->appendChild($data);
             }
             $pages_types->appendChild($type);
         }
     }
     $root->appendChild($entries);
     $root->appendChild($pages_types);
     $xml->appendChild($root);
     $location = WORKSPACE . "/pages/_pages.xml";
     $output = $xml->saveXML();
     General::writeFile($location, $output, Symphony::Configuration()->get('write_mode', 'file'));
 }