public function importPost($post, $dryrun = true) { // If the mapping is not defined, ignore it. if (empty($this->config['mapping'][$post['post_type']])) { return "<p>No mapping defined for posttype '" . $post['post_type'] . "'.</p>"; } // Find out which mapping we should use. $mapping = $this->config['mapping'][$post['post_type']]; // If the mapped contenttype doesn't exist in Bolt. if (!$this->app['storage']->getContentType($mapping['targetcontenttype'])) { return "<p>Bolt contenttype '" . $mapping['targetcontenttype'] . "' for posttype '" . $post['post_type'] . "' does not exist.</p>"; } // Create the new Bolt Record. $record = new \Bolt\Content($this->app, $mapping['targetcontenttype']); // 'expand' the postmeta fields to regular fields. if (!empty($post['postmeta']) && is_array($post['postmeta'])) { foreach ($post['postmeta'] as $id => $keyvalue) { $post[$keyvalue['key']] = $keyvalue['value']; } } // Iterate through the mappings, see if we can find it. foreach ($mapping['fields'] as $from => $to) { if (isset($post[$from])) { // It's present in the fields. $value = $post[$from]; switch ($from) { case "post_parent": if (!empty($value)) { $value = $mapping['fields']['post_parent_contenttype'] . "/" . $value; } break; case "post_date": if (!empty($value)) { // WXR seems to use only one date value. $record->setValue('datechanged', $value); $record->setValue('datecreated', $value); $record->setValue('datepublish', $value); } break; } switch ($to) { case "username": $value = makeSlug($value); break; case "status": if ($value == "publish") { $value = "published"; } if ($value == "future") { $value = "timed"; } break; } $record->setValue($to, $value); } } // Perhaps import the categories as well.. if (!empty($mapping['category']) && !empty($post['terms'])) { foreach ($post['terms'] as $term) { if ($term['domain'] == 'category') { $record->setTaxonomy($mapping['category'], $term['slug']); if (!in_array($term['slug'], $this->foundcategories)) { $this->foundcategories[] = $term['slug']; } } } } if ($dryrun) { $output = "<p>Original WXR Post <b>\"" . $post['post_title'] . "\"</b> -> Converted Bolt Record :</p>"; $output .= \util::var_dump($post, true); $output .= \util::var_dump($record, true); $output .= "\n<hr>\n"; } else { $this->app['storage']->saveContent($record); $output = "Import: " . $record->get('id') . " - " . $record->get('title') . " <small><em>"; $output .= $this->memUsage() . "mb.</em></small><br>"; } return $output; }