/** * Populate any non-required fields before the second save * * @param string $data file content * @param string $ext file extension * @param OutputInterface $output * @param Page $p * */ protected function addFieldContent($data, $ext, $output, $p) { if ($ext === 'json') { foreach ($data as $fieldname => $fieldval) { $fieldname = strtolower($fieldname); if ($p->{$fieldname}) { if ($fieldname === 'name') { $fieldval = \ProcessWire\wire('sanitizer')->pageName($fieldval); } $p->{$fieldname} = $fieldval; } else { $output->writeln("<comment>For the chosen template field `{$fieldname}` does not exist.\n</comment>"); } } } // finally save the field data as well $p->save(); }
/** * Get current page * * @param string $selector * @return Page * */ protected function getCurrentPage($selector) { // check whether a page with this identifier already exists $page = $this->wire('pages')->get($selector); // if not, create new page if (!$page->id) { $page = new Page(); $page->template = $this->data['xpTemplate']; $page->parent = $this->data['xpParent']; $page->save(); $this->createdCount++; } else { $this->updatedCount++; } return $page; }