1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

Minor code optimizations to the PagesExportImport modules

This commit is contained in:
Ryan Cramer
2024-12-20 15:15:51 -05:00
parent 1fc3cf414a
commit b7238605e4
2 changed files with 109 additions and 132 deletions

View File

@@ -18,7 +18,7 @@
* *
* Note: all the "change" prefix options require update=true. * Note: all the "change" prefix options require update=true.
* *
* ProcessWire 3.x, Copyright 2017 by Ryan Cramer * ProcessWire 3.x, Copyright 2024 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
*/ */
@@ -35,9 +35,9 @@ class PagesExportImport extends Wire {
*/ */
public function getExportPath($subdir = '') { public function getExportPath($subdir = '') {
/** @var WireFileTools $files */ $files = $this->wire()->files;
$files = $this->wire('files'); $config = $this->wire()->config;
$path = $this->wire('config')->paths->assets . 'backups/' . $this->className() . '/'; $path = $config->paths->assets . 'backups/' . $this->className() . '/';
$readmeText = "When this file is present, files and directories in here are auto-deleted after a short period of time."; $readmeText = "When this file is present, files and directories in here are auto-deleted after a short period of time.";
$readmeFile = $this->className() . '.txt'; $readmeFile = $this->className() . '.txt';
@@ -75,8 +75,7 @@ class PagesExportImport extends Wire {
*/ */
public function cleanupFiles($maxAge = 3600) { public function cleanupFiles($maxAge = 3600) {
/** @var WireFileTools $files */ $files = $this->wire()->files;
$files = $this->wire('files');
$path = $this->getExportPath(); $path = $this->getExportPath();
$qty = 0; $qty = 0;
@@ -111,13 +110,12 @@ class PagesExportImport extends Wire {
* *
* @param PageArray $items * @param PageArray $items
* @param array $options * @param array $options
* @return string|bool Path+filename to ZIP file or boolean false on failure * @return string Path+filename to ZIP file
* *
*/ */
public function exportZIP(PageArray $items, array $options = array()) { public function exportZIP(PageArray $items, array $options = array()) {
/** @var WireFileTools $files */ $files = $this->wire()->files;
$files = $this->wire('files');
$options['exportTarget'] = 'zip'; $options['exportTarget'] = 'zip';
$zipPath = $this->getExportPath(); $zipPath = $this->getExportPath();
@@ -173,7 +171,7 @@ class PagesExportImport extends Wire {
$path = $tempDir->get(); $path = $tempDir->get();
$options['filesPath'] = $path; $options['filesPath'] = $path;
$zipFileItems = $this->wire('files')->unzip($filename, $path); $zipFileItems = $this->wire()->files->unzip($filename, $path);
if(empty($zipFileItems)) return false; if(empty($zipFileItems)) return false;
@@ -192,7 +190,7 @@ class PagesExportImport extends Wire {
* *
* @param PageArray $items * @param PageArray $items
* @param array $options * @param array $options
* @return string|bool JSON string of pages or boolean false on error * @return string JSON string of pages
* *
*/ */
public function exportJSON(PageArray $items, array $options = array()) { public function exportJSON(PageArray $items, array $options = array()) {
@@ -232,8 +230,9 @@ class PagesExportImport extends Wire {
*/ */
public function pagesToArray(PageArray $items, array $options = array()) { public function pagesToArray(PageArray $items, array $options = array()) {
/** @var Config $config */ $config = $this->wire()->config;
$config = $this->wire('config'); $modules = $this->wire()->modules;
$fields = $this->wire()->fields;
$defaults = array( $defaults = array(
'verbose' => false, 'verbose' => false,
@@ -247,7 +246,7 @@ class PagesExportImport extends Wire {
'type' => 'ProcessWire:PageArray', 'type' => 'ProcessWire:PageArray',
'created' => date('Y-m-d H:i:s'), 'created' => date('Y-m-d H:i:s'),
'version' => $config->version, 'version' => $config->version,
'user' => $this->wire('user')->name, 'user' => $this->wire()->user->name,
'host' => $config->httpHost, 'host' => $config->httpHost,
'pages' => array(), 'pages' => array(),
'fields' => array(), 'fields' => array(),
@@ -260,7 +259,7 @@ class PagesExportImport extends Wire {
); );
if($items->getLimit()) { if($items->getLimit()) {
$pageNum = $this->wire('input')->pageNum; $pageNum = $this->wire()->input->pageNum;
$a['pagination'] = array( $a['pagination'] = array(
'start' => $items->getStart(), 'start' => $items->getStart(),
'limit' => $items->getLimit(), 'limit' => $items->getLimit(),
@@ -273,8 +272,7 @@ class PagesExportImport extends Wire {
unset($a['pagination']); unset($a['pagination']);
} }
/** @var Languages $languages */ $languages = $this->wire()->languages;
$languages = $this->wire('languages');
if($languages) $languages->setDefault(); if($languages) $languages->setDefault();
$templates = array(); $templates = array();
@@ -293,9 +291,9 @@ class PagesExportImport extends Wire {
} }
foreach($fieldNames as $fieldName) { foreach($fieldNames as $fieldName) {
if(isset($a['fields'][$fieldName])) continue; if(isset($a['fields'][$fieldName])) continue;
$field = $this->wire('fields')->get($fieldName); $field = $fields->get($fieldName);
if(!$field || !$field->type) continue; if(!$field || !$field->type) continue;
$moduleInfo = $this->wire('modules')->getModuleInfoVerbose($field->type); $moduleInfo = $modules->getModuleInfoVerbose($field->type);
if($options['verbose']) { if($options['verbose']) {
$fieldData = $field->getExportData(); $fieldData = $field->getExportData();
unset($fieldData['name']); unset($fieldData['name']);
@@ -363,8 +361,8 @@ class PagesExportImport extends Wire {
$of = $page->of(); $of = $page->of();
$page->of(false); $page->of(false);
/** @var Languages $languages */ /** @var Languages|Language[] $languages */
$languages = $this->wire('languages'); $languages = $this->wire()->languages;
if($languages) $languages->setDefault(); if($languages) $languages->setDefault();
$numFiles = 0; $numFiles = 0;
@@ -457,7 +455,7 @@ class PagesExportImport extends Wire {
* *
* @param array $a * @param array $a
* @param array $options * @param array $options
* @return PageArray|bool * @return PageArray|int
* @throws WireException * @throws WireException
* *
*/ */
@@ -476,7 +474,7 @@ class PagesExportImport extends Wire {
if(!empty($options['pageArray']) && $options['pageArray'] instanceof PageArray) { if(!empty($options['pageArray']) && $options['pageArray'] instanceof PageArray) {
$pageArray = $options['pageArray']; $pageArray = $options['pageArray'];
} else { } else {
$pageArray = $this->wire('pages')->newPageArray(); $pageArray = $this->wire()->pages->newPageArray();
} }
$count = 0; $count = 0;
@@ -494,7 +492,7 @@ class PagesExportImport extends Wire {
foreach($a['pages'] as $item) { foreach($a['pages'] as $item) {
$page = $this->arrayToPage($item, $options); $page = $this->arrayToPage($item, $options);
$id = $item['settings']['id']; $id = $item['settings']['id'];
$this->wire('notices')->move($page, $pageArray, array('prefix' => "Page $id: ")); $this->wire()->notices->move($page, $pageArray, array('prefix' => "Page $id: "));
if(!$options['count']) $pageArray->add($page); if(!$options['count']) $pageArray->add($page);
$count++; $count++;
} }
@@ -680,8 +678,7 @@ class PagesExportImport extends Wire {
*/ */
protected function importGetPage(array &$a, array &$options, array &$errors) { protected function importGetPage(array &$a, array &$options, array &$errors) {
/** @var Pages $pages */ $pages = $this->wire()->pages;
$pages = $this->wire('pages');
$path = $a['path']; $path = $a['path'];
/** @var Page|NullPage $page */ /** @var Page|NullPage $page */
@@ -738,7 +735,7 @@ class PagesExportImport extends Wire {
if(is_object($template)) { if(is_object($template)) {
// ok // ok
} else { } else {
$template = $this->wire('templates')->get($template); $template = $this->wire()->templates->get($template);
} }
if($template) { if($template) {
$options['template'] = $template; $options['template'] = $template;
@@ -762,12 +759,12 @@ class PagesExportImport extends Wire {
// determine parent // determine parent
static $previousPaths = array(); static $previousPaths = array();
$usePrevious = true; $usePrevious = true;
$pages = $this->wire('pages'); $pages = $this->wire()->pages;
$path = $a['path']; $path = $a['path'];
if($options['parent']) { if($options['parent']) {
// parent specified in options // parent specified in options
if(is_object($options['parent']) && $options['parent'] instanceof Page) { if($options['parent'] instanceof Page) {
$parent = $options['parent']; $parent = $options['parent'];
} else if(ctype_digit("$options[parent]")) { } else if(ctype_digit("$options[parent]")) {
$parent = $pages->get((int) $options['parent']); $parent = $pages->get((int) $options['parent']);
@@ -841,7 +838,7 @@ class PagesExportImport extends Wire {
if(!$isNew) $options['changeTemplate'] = false; if(!$isNew) $options['changeTemplate'] = false;
$template = $options['template']; $template = $options['template'];
$parent = $options['parent']; $parent = $options['parent'];
$languages = $this->wire('languages'); $languages = $this->wire()->languages;
$langProperties = array(); $langProperties = array();
// populate page base settings // populate page base settings
@@ -980,9 +977,9 @@ class PagesExportImport extends Wire {
$page->trackChange("{$field->name}__"); $page->trackChange("{$field->name}__");
} }
} }
if(is_object($pageValue) && $pageValue instanceof Wire) { if($pageValue instanceof Wire) {
// movie notices from the pageValue to the page // movie notices from the pageValue to the page
$this->wire('notices')->move($pageValue, $page); $this->wire()->notices->move($pageValue, $page);
} }
} else { } else {
// test import on existing page, avoids actually setting value to the page // test import on existing page, avoids actually setting value to the page
@@ -1020,9 +1017,8 @@ class PagesExportImport extends Wire {
// 'file3.gif' => [ ... see above ... ], // 'file3.gif' => [ ... see above ... ],
// ]; // ];
/** @var Pagefiles $pagefiles */
$pagefiles = $page->get($field->name); $pagefiles = $page->get($field->name);
if(!$pagefiles || !$pagefiles instanceof Pagefiles) { if(!$pagefiles instanceof Pagefiles) {
$page->warning("Unable to import files to field '$field->name' because it is not a files field"); $page->warning("Unable to import files to field '$field->name' because it is not a files field");
return; return;
} }
@@ -1033,7 +1029,7 @@ class PagesExportImport extends Wire {
$variationsAdded = array(); $variationsAdded = array();
$maxFiles = (int) $field->get('maxFiles'); $maxFiles = (int) $field->get('maxFiles');
$languages = $this->wire('languages'); $languages = $this->wire()->languages;
$filesPath = $pagefiles->path(); $filesPath = $pagefiles->path();
/** @var null|WireHttp $http */ /** @var null|WireHttp $http */
$http = null; $http = null;
@@ -1137,7 +1133,7 @@ class PagesExportImport extends Wire {
if($sourceExists) { if($sourceExists) {
// copy variation from options[filesPath] // copy variation from options[filesPath]
if($this->wire('files')->copy($sourceFile, $targetFile)) { if($this->wire()->files->copy($sourceFile, $targetFile)) {
$variationsAdded[] = $name; $variationsAdded[] = $name;
} else { } else {
$page->warning("Unable to copy file (image variation): $sourceFile"); $page->warning("Unable to copy file (image variation): $sourceFile");
@@ -1243,13 +1239,9 @@ class PagesExportImport extends Wire {
$numExisting = 0; $numExisting = 0;
$numNew = 0; $numNew = 0;
/** @var Pages $pages */ $pages = $this->wire()->pages;
$pages = $this->wire('pages'); $fields = $this->wire()->fields;
/** @var Fields $fields */ $sanitizer = $this->wire()->sanitizer;
$fields = $this->wire('fields');
/** @var Sanitizer $sanitizer */
$sanitizer = $this->wire('sanitizer');
/** @var PageFinder $pageFinder */
$pageFinder = $this->wire(new PageFinder()); $pageFinder = $this->wire(new PageFinder());
// Identify missing fields // Identify missing fields
@@ -1300,7 +1292,7 @@ class PagesExportImport extends Wire {
// determine which templates are missing, and which fields are missing from templates // determine which templates are missing, and which fields are missing from templates
foreach($templateNames as $templateName => $fieldNames) { foreach($templateNames as $templateName => $fieldNames) {
$template = $this->wire('templates')->get($templateName); $template = $this->wire()->templates->get($templateName);
if($template) { if($template) {
// template exists // template exists
$missingTemplateFields[$templateName] = array(); $missingTemplateFields[$templateName] = array();
@@ -1316,7 +1308,7 @@ class PagesExportImport extends Wire {
} }
// determine which parents are missing // determine which parents are missing
foreach($parentPaths as $key => $path) { foreach($parentPaths as /* $key => */ $path) {
if(isset($pagePaths[$path])) { if(isset($pagePaths[$path])) {
// this parent already exists or will be created during import // this parent already exists or will be created during import
} else { } else {

View File

@@ -3,7 +3,7 @@
/** /**
* ProcessWire Page Export and Import * ProcessWire Page Export and Import
* *
* ProcessWire 3.x, Copyright 2017 by Ryan Cramer * ProcessWire 3.x, Copyright 2024 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* Note: this module supports page-edit-export and page-edit-import permissions, but currently the module is * Note: this module supports page-edit-export and page-edit-import permissions, but currently the module is
@@ -49,8 +49,10 @@ class ProcessPagesExportImport extends Process {
* *
*/ */
public function ___execute() { public function ___execute() {
$user = $this->wire()->user;
$input = $this->wire()->input;
if(!$this->wire('user')->isSuperuser()) { if(!$user->isSuperuser()) {
throw new WirePermissionException($this->_('Export/import is currently only available to superuser')); throw new WirePermissionException($this->_('Export/import is currently only available to superuser'));
} }
@@ -58,9 +60,7 @@ class ProcessPagesExportImport extends Process {
$this->wire($this->exportImport); $this->wire($this->exportImport);
$this->exportImport->cleanupFiles(600); $this->exportImport->cleanupFiles(600);
$input = $this->wire('input'); $breadcrumbLabel = $this->wire()->page->title;
$user = $this->wire('user');
$breadcrumbLabel = $this->wire('page')->title;
try { try {
if($input->post('submit_export')) { if($input->post('submit_export')) {
@@ -77,19 +77,13 @@ class ProcessPagesExportImport extends Process {
return $form->render(); return $form->render();
} }
} else { } else {
/*
$this->warning(
'Please note this is a development version of pages export/import ' .
'and not yet recommended for production use.'
);
*/
$form = $this->buildForm(); $form = $this->buildForm();
return $form->render(); return $form->render();
} }
} catch(\Exception $e) { } catch(\Exception $e) {
if(self::debug) throw $e; if(self::debug) throw $e;
$this->error($e->getMessage()); $this->error($e->getMessage());
$this->wire('session')->redirect($this->wire('page')->url); $this->wire()->session->location($this->wire()->page->url);
} }
return ''; return '';
@@ -104,11 +98,9 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function buildForm($tab = '') { protected function buildForm($tab = '') {
/** @var Modules $modules */ $modules = $this->wire()->modules;
$modules = $this->wire('modules');
$modules->get('JqueryWireTabs'); $modules->get('JqueryWireTabs');
/** @var User $user */ $user = $this->wire()->user;
$user = $this->wire('user');
/** @var InputfieldForm $form */ /** @var InputfieldForm $form */
$form = $modules->get('InputfieldForm'); $form = $modules->get('InputfieldForm');
@@ -135,8 +127,7 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function buildImportTab() { protected function buildImportTab() {
/** @var Modules $modules */ $modules = $this->wire()->modules;
$modules = $this->wire('modules');
/** @var InputfieldWrapper $tab */ /** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper()); $tab = $this->wire(new InputfieldWrapper());
@@ -185,8 +176,9 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function processImport() { protected function processImport() {
/** @var WireInput $input */ $input = $this->wire()->input;
$input = $this->wire('input'); $files = $this->wire()->files;
$session = $this->wire()->session;
/** @var InputfieldWrapper|InputfieldForm $importTab */ /** @var InputfieldWrapper|InputfieldForm $importTab */
$importTab = $this->buildForm('import'); $importTab = $this->buildForm('import');
@@ -194,8 +186,7 @@ class ProcessPagesExportImport extends Process {
$submitCommit = $input->post('submit_commit_import') ? true : false; $submitCommit = $input->post('submit_commit_import') ? true : false;
$submitTest = $input->post('submit_test_import') ? true : false; $submitTest = $input->post('submit_test_import') ? true : false;
$submitZIP = !empty($_FILES['import_zip']) && !empty($_FILES['import_zip']['name'][0]); $submitZIP = !empty($_FILES['import_zip']) && !empty($_FILES['import_zip']['name'][0]);
$fileField = null; $filesPath = $session->getFor($this, 'filesPath');
$filesPath = $this->wire('session')->getFor($this, 'filesPath');
$jsonFile = ''; $jsonFile = '';
$a = null; $a = null;
@@ -206,11 +197,11 @@ class ProcessPagesExportImport extends Process {
$zipFile = $this->exportImport->getExportPath() . $fileField->value->first()->name; $zipFile = $this->exportImport->getExportPath() . $fileField->value->first()->name;
if(!$zipFile || !is_file($zipFile)) throw new WireException('No ZIP file found: ' . $zipFile); if(!$zipFile || !is_file($zipFile)) throw new WireException('No ZIP file found: ' . $zipFile);
$unzipPath = $this->exportImport->getExportPath('import-zip'); $unzipPath = $this->exportImport->getExportPath('import-zip');
$zipFileItems = $this->wire('files')->unzip($zipFile, $unzipPath); $zipFileItems = $files->unzip($zipFile, $unzipPath);
$this->wire('files')->unlink($zipFile); $files->unlink($zipFile);
if(empty($zipFileItems)) throw new WireException("No files found in ZIP"); if(empty($zipFileItems)) throw new WireException("No files found in ZIP");
$jsonFile = $unzipPath . "pages.json"; $jsonFile = $unzipPath . "pages.json";
$this->wire('session')->setFor($this, 'filesPath', $unzipPath); $session->setFor($this, 'filesPath', $unzipPath);
} else if(!empty($_POST['import_json'])) { } else if(!empty($_POST['import_json'])) {
// JSON import // JSON import
@@ -218,7 +209,7 @@ class ProcessPagesExportImport extends Process {
$json = $importTab->getChildByName('import_json')->val(); $json = $importTab->getChildByName('import_json')->val();
if(empty($json)) throw new WireException($this->_('No import data found')); if(empty($json)) throw new WireException($this->_('No import data found'));
$a = json_decode($json, true); $a = json_decode($json, true);
$this->wire('session')->setFor($this, 'filesPath', ''); $session->setFor($this, 'filesPath', '');
} else if($filesPath) { } else if($filesPath) {
// ZIP import commit or test // ZIP import commit or test
@@ -252,6 +243,7 @@ class ProcessPagesExportImport extends Process {
if($submitCommit) { if($submitCommit) {
$form->description = sprintf($this->_n('Imported %d page', 'Imported %d pages', $qty), $qty); $form->description = sprintf($this->_n('Imported %d page', 'Imported %d pages', $qty), $qty);
foreach($form->children() as $f) { foreach($form->children() as $f) {
/** @var Inputfield $f */
if($f->name != 'import_items') $form->remove($f); if($f->name != 'import_items') $form->remove($f);
} }
} else { } else {
@@ -293,8 +285,8 @@ class ProcessPagesExportImport extends Process {
// ); // );
set_time_limit(3600); set_time_limit(3600);
/** @var WireInput $input */ $input = $this->wire()->input;
$input = $this->wire('input'); $config = $this->wire()->config;
$form->processInput($input->post); $form->processInput($input->post);
@@ -317,12 +309,12 @@ class ProcessPagesExportImport extends Process {
'changeName' => in_array('name', $fieldNames), 'changeName' => in_array('name', $fieldNames),
'changeStatus' => in_array('status', $fieldNames), 'changeStatus' => in_array('status', $fieldNames),
'changeSort' => in_array('sort', $fieldNames), 'changeSort' => in_array('sort', $fieldNames),
'filesPath' => $this->wire('session')->getFor($this, 'filesPath'), 'filesPath' => $this->wire()->session->getFor($this, 'filesPath'),
'originalHost' => isset($a['host']) ? $a['host'] : $this->wire('config')->httpHost, 'originalHost' => isset($a['host']) ? $a['host'] : $config->httpHost,
'originalRootUrl' => isset($a['url']) ? $a['url'] : $this->wire('config')->urls->root, 'originalRootUrl' => isset($a['url']) ? $a['url'] : $config->urls->root,
); );
foreach($a['pages'] as $key => $item) { foreach($a['pages'] as /* $key => */ $item) {
$id = $item['settings']['id']; $id = $item['settings']['id'];
if($submitCommit && !$input->post("confirm$id")) continue; if($submitCommit && !$input->post("confirm$id")) continue;
$page = $this->processImportItemToPage($item, $options); $page = $this->processImportItemToPage($item, $options);
@@ -346,23 +338,12 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function identifyMissingResources(array &$a) { protected function identifyMissingResources(array &$a) {
/** @var Sanitizer $sanitizer */ $sanitizer = $this->wire()->sanitizer;
$sanitizer = $this->wire('sanitizer'); $modules = $this->wire()->modules;
$templates = $this->wire()->templates;
/** @var Modules $modules*/ $fields = $this->wire()->fields;
$modules = $this->wire('modules'); $pages = $this->wire()->pages;
$input = $this->wire()->input;
/** @var Templates $templates */
$templates = $this->wire('templates');
/** @var Fields $fields */
$fields = $this->wire('fields');
/** @var Pages $pages */
$pages = $this->wire('pages');
/** @var WireInput $input */
$input = $this->wire('input');
$numFatalItems = 0; $numFatalItems = 0;
$missingItems = array(); $missingItems = array();
@@ -386,7 +367,7 @@ class ProcessPagesExportImport extends Process {
$templateName $templateName
) . ' ' . $this->_('Select a template to substitute when creating these pages.'); ) . ' ' . $this->_('Select a template to substitute when creating these pages.');
foreach($this->wire('templates') as $t) { foreach($templates as $t) {
$f->addOption($t->name); $f->addOption($t->name);
} }
@@ -463,7 +444,7 @@ class ProcessPagesExportImport extends Process {
$optionsRecommended = array(); $optionsRecommended = array();
$optionsOther = array(); $optionsOther = array();
foreach($this->wire('fields') as $_field) { foreach($fields as $_field) {
/** @var Field $_field */ /** @var Field $_field */
if($_field->type->className() == $fieldtypeClass && !$_field->hasFlag(Field::flagSystem)) { if($_field->type->className() == $fieldtypeClass && !$_field->hasFlag(Field::flagSystem)) {
$optionsRecommended[$_field->name] = $_field->name; $optionsRecommended[$_field->name] = $_field->name;
@@ -569,8 +550,7 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function adjustImportData(&$a) { protected function adjustImportData(&$a) {
/** @var WireInput $input */ $input = $this->wire()->input;
$input = $this->wire('input');
$importParentID = (int) $input->post('import_parent'); $importParentID = (int) $input->post('import_parent');
$importParentType = $input->post('import_parent_type') === 'direct' ? 'direct' : 'below'; $importParentType = $input->post('import_parent_type') === 'direct' ? 'direct' : 'below';
@@ -654,8 +634,10 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function buildImportForm(InputfieldForm $tab, array &$a) { protected function buildImportForm(InputfieldForm $tab, array &$a) {
$modules = $this->wire('modules'); $modules = $this->wire()->modules;
$input = $this->wire()->input;
/** @var InputfieldForm $form */
$form = $modules->get('InputfieldForm'); $form = $modules->get('InputfieldForm');
$form->attr('id', 'import-form'); $form->attr('id', 'import-form');
$form->description = $this->_('Import summary'); $form->description = $this->_('Import summary');
@@ -672,6 +654,7 @@ class ProcessPagesExportImport extends Process {
/** @var InputfieldFieldset $importTab */ /** @var InputfieldFieldset $importTab */
$importTab = $tab->getChildByName('tab_import'); $importTab = $tab->getChildByName('tab_import');
foreach($importTab->children() as $f) { foreach($importTab->children() as $f) {
/** @var Inputfield $f */
if($f->attr('name') == 'import_zip') { if($f->attr('name') == 'import_zip') {
continue; continue;
} else if($f instanceof InputfieldSubmit) { } else if($f instanceof InputfieldSubmit) {
@@ -715,7 +698,7 @@ class ProcessPagesExportImport extends Process {
$f->icon = 'female'; $f->icon = 'female';
$f->showIf = 'import_mode!=update'; $f->showIf = 'import_mode!=update';
$f->startLabel = $this->_('Choose parent'); $f->startLabel = $this->_('Choose parent');
$checkedDirect = $this->wire('input')->post('import_parent_type') == 'direct' ? "checked='checked'" : ''; $checkedDirect = $input->post('import_parent_type') == 'direct' ? "checked='checked'" : '';
$checkedBelow = $checkedDirect ? '' : "checked='checked'"; $checkedBelow = $checkedDirect ? '' : "checked='checked'";
$f->appendMarkup = $f->appendMarkup =
"<p class='InputfieldRadios'>" . "<p class='InputfieldRadios'>" .
@@ -758,13 +741,14 @@ class ProcessPagesExportImport extends Process {
$f->addOption('status', "status|" . $this->_('Page status') . "|System"); $f->addOption('status', "status|" . $this->_('Page status') . "|System");
$f->addOption('sort', "sort|" . $this->_('Page sort index') . "|System"); $f->addOption('sort', "sort|" . $this->_('Page sort index') . "|System");
$f->attr('value', $value); $f->attr('value', $value);
if(!$this->wire('input')->post('submit_import')) $f->collapsed = Inputfield::collapsedYes; if(!$input->post('submit_import')) $f->collapsed = Inputfield::collapsedYes;
$form->add($f); $form->add($f);
$submitTest = $this->wire('input')->post('submit_test_import') ? true : false; $submitTest = $input->post('submit_test_import') ? true : false;
$submitCommit = $this->wire('input')->post('submit_commit_import') ? true : false; $submitCommit = $input->post('submit_commit_import') ? true : false;
if($submitCommit || $submitTest) { if($submitCommit || $submitTest) {
/** @var InputfieldFieldset $fieldset */
$fieldset = $modules->get('InputfieldFieldset'); $fieldset = $modules->get('InputfieldFieldset');
$fieldset->attr('name', 'import_items'); $fieldset->attr('name', 'import_items');
$fieldset->label = $this->_('Import pages'); $fieldset->label = $this->_('Import pages');
@@ -781,6 +765,7 @@ class ProcessPagesExportImport extends Process {
$form->add($f); $form->add($f);
if(($submitTest || $submitCommit) && empty($a['_noCommit'])) { if(($submitTest || $submitCommit) && empty($a['_noCommit'])) {
/** @var InputfieldSubmit $f */
$f = $modules->get('InputfieldSubmit'); $f = $modules->get('InputfieldSubmit');
$f->attr('name', 'submit_commit_import'); $f->attr('name', 'submit_commit_import');
$f->val($this->_('Commit Import')); $f->val($this->_('Commit Import'));
@@ -796,17 +781,18 @@ class ProcessPagesExportImport extends Process {
* Build a summary InputfieldMarkup for a single item/Page * Build a summary InputfieldMarkup for a single item/Page
* *
* @param array $item Import item array * @param array $item Import item array
* @param Page|NullPage $page Resulting Page object * @param Page $page Resulting Page object
* @param array $options Import options that were passed to PagesExportImport import() method * @param array $options Import options that were passed to PagesExportImport import() method
* @return InputfieldMarkup * @return InputfieldMarkup
* *
*/ */
protected function buildImportItemSummary(array $item, Page $page, array $options) { protected function buildImportItemSummary(array $item, Page $page, array $options) {
$sanitizer = $this->wire('sanitizer'); $sanitizer = $this->wire()->sanitizer;
$languages = $this->wire()->languages;
$changes = $page->get('_importChanges'); $changes = $page->get('_importChanges');
$importType = $page->get('_importType'); $importType = $page->get('_importType');
$languages = $this->wire('languages');
$numChanges = wireCount($changes); $numChanges = wireCount($changes);
$originalID = (int) $item['settings']['id']; $originalID = (int) $item['settings']['id'];
$out = ''; $out = '';
@@ -814,7 +800,8 @@ class ProcessPagesExportImport extends Process {
static $n = 0; static $n = 0;
$n++; $n++;
$f = $this->wire('modules')->get('InputfieldMarkup'); /** @var InputfieldMarkup $f */
$f = $this->wire()->modules->get('InputfieldMarkup');
$f->addClass('import-form-item'); $f->addClass('import-form-item');
$f->label = "$n. "; $f->label = "$n. ";
@@ -869,7 +856,7 @@ class ProcessPagesExportImport extends Process {
foreach($notices as $notice) { foreach($notices as $notice) {
$noticeText = $sanitizer->entities($notice->text); $noticeText = $sanitizer->entities($notice->text);
if($noticeType != 'messages') { if($noticeType != 'messages') {
$icon = $noticeType == 'errors' ? 'warning' : 'warning'; $icon = 'warning';
} else { } else {
$icon = 'check'; $icon = 'check';
} }
@@ -885,8 +872,8 @@ class ProcessPagesExportImport extends Process {
} else if($numChanges) { } else if($numChanges) {
// Page (success) // Page (success)
$attr = "type='radio' name='confirm$originalID' class='import-confirm'"; $attr = "type='radio' name='confirm$originalID' class='import-confirm'";
$val = $this->wire('input')->post("confirm$originalID"); $val = $this->wire()->input->post("confirm$originalID");
if(($val == $originalID || $val === null) && $numChanges) { if($val == $originalID || $val === null) {
$checkedYes = "checked='checked'"; $checkedYes = "checked='checked'";
$checkedNo = ""; $checkedNo = "";
} else { } else {
@@ -916,14 +903,13 @@ class ProcessPagesExportImport extends Process {
*/ */
protected function buildExportTab() { protected function buildExportTab() {
$modules = $this->wire('modules'); /** @var InputfieldWrapper $tab */
$tab = $this->wire(new InputfieldWrapper()); $tab = $this->wire(new InputfieldWrapper());
$tab->attr('id+name', 'tab_export'); $tab->attr('id+name', 'tab_export');
$tab->attr('title', $this->_('Export')); $tab->attr('title', $this->_('Export'));
$tab->addClass('WireTab'); $tab->addClass('WireTab');
$f = $modules->get('InputfieldRadios'); $f = $tab->InputfieldRadios;
$f->attr('name', 'export_type'); $f->attr('name', 'export_type');
$f->label = $this->_('What pages do you want to export?'); $f->label = $this->_('What pages do you want to export?');
$f->icon = 'sitemap'; $f->icon = 'sitemap';
@@ -932,7 +918,7 @@ class ProcessPagesExportImport extends Process {
$f->addOption('selector', $this->_('Pages matching search')); $f->addOption('selector', $this->_('Pages matching search'));
$tab->add($f); $tab->add($f);
$f = $modules->get('InputfieldPageListSelectMultiple'); $f = $tab->InputfieldPageListSelectMultiple;
$f->attr('name', 'pages_specific'); $f->attr('name', 'pages_specific');
$f->label = $this->_('Select pages'); $f->label = $this->_('Select pages');
$f->description = $this->_('Select one or more pages to include in the export.'); $f->description = $this->_('Select one or more pages to include in the export.');
@@ -940,7 +926,7 @@ class ProcessPagesExportImport extends Process {
$f->showIf = 'export_type=specific'; $f->showIf = 'export_type=specific';
$tab->add($f); $tab->add($f);
$f = $modules->get('InputfieldPageListSelect'); $f = $tab->InputfieldPageListSelect;
$f->attr('name', 'pages_parent'); $f->attr('name', 'pages_parent');
$f->label = $this->_('Select parent page'); $f->label = $this->_('Select parent page');
$f->description = $this->_('Select the parent of the pages you want to export. The children of this page will be exported.'); $f->description = $this->_('Select the parent of the pages you want to export. The children of this page will be exported.');
@@ -948,7 +934,7 @@ class ProcessPagesExportImport extends Process {
$f->showIf = 'export_type=parent'; $f->showIf = 'export_type=parent';
$tab->add($f); $tab->add($f);
$f = $modules->get('InputfieldCheckboxes'); $f = $tab->InputfieldCheckboxes;
$f->attr('name', 'options_parent'); $f->attr('name', 'options_parent');
$f->label = $this->_('Additional options'); $f->label = $this->_('Additional options');
$f->icon = 'sliders'; $f->icon = 'sliders';
@@ -960,7 +946,7 @@ class ProcessPagesExportImport extends Process {
$f->addOption('unpublished', $this->_('Include hidden and unpublished pages')); $f->addOption('unpublished', $this->_('Include hidden and unpublished pages'));
$tab->add($f); $tab->add($f);
$f = $modules->get('InputfieldSelector'); $f = $tab->InputfieldSelector;
$f->attr('name', 'pages_selector'); $f->attr('name', 'pages_selector');
$f->label = $this->_('Build a search to match pages for export'); $f->label = $this->_('Build a search to match pages for export');
$f->description = $this->_('Add one or more fields to search and match pages for export.'); $f->description = $this->_('Add one or more fields to search and match pages for export.');
@@ -968,7 +954,7 @@ class ProcessPagesExportImport extends Process {
$f->showIf = 'export_type=selector'; $f->showIf = 'export_type=selector';
$tab->add($f); $tab->add($f);
$f = $modules->get('InputfieldCheckboxes'); $f = $tab->InputfieldCheckboxes;
$f->attr('name', 'export_fields'); $f->attr('name', 'export_fields');
$f->label = $this->_('Export fields'); $f->label = $this->_('Export fields');
$f->description = $f->description =
@@ -1003,8 +989,7 @@ class ProcessPagesExportImport extends Process {
$tab->add($f); $tab->add($f);
*/ */
/** @var InputfieldSubmit $f */ $f = $tab->InputfieldSubmit;
$f = $modules->get('InputfieldSubmit');
$f->attr('name', 'submit_export'); $f->attr('name', 'submit_export');
$f->value = $this->_('Export Now'); $f->value = $this->_('Export Now');
$f->showIf = $showIf; $f->showIf = $showIf;
@@ -1035,10 +1020,10 @@ class ProcessPagesExportImport extends Process {
set_time_limit(3600); set_time_limit(3600);
/** @var Pages $pages */ $pages = $this->wire()->pages;
$pages = $this->wire('pages'); $input = $this->wire()->input;
/** @var WireInput $input */ $modules = $this->wire()->modules;
$input = $this->wire('input'); $files = $this->wire()->files;
$form = $this->buildForm(); $form = $this->buildForm();
$form->processInput($input->post); $form->processInput($input->post);
@@ -1100,8 +1085,9 @@ class ProcessPagesExportImport extends Process {
if($exportTo == 'json') { if($exportTo == 'json') {
// json // json
$json = $exporter->exportJSON($exportPages, $exportOptions); $json = $exporter->exportJSON($exportPages, $exportOptions);
$form = $this->wire('modules')->get('InputfieldForm'); /** @var InputfieldForm $form */
$f = $this->wire('modules')->get('InputfieldTextarea'); $form = $modules->get('InputfieldForm');
$f = $form->InputfieldTextarea;
$f->attr('id+name', 'export_json'); $f->attr('id+name', 'export_json');
$f->label = $this->_('Pages export data for copy/paste'); $f->label = $this->_('Pages export data for copy/paste');
$f->description = sprintf( $f->description = sprintf(
@@ -1119,11 +1105,11 @@ class ProcessPagesExportImport extends Process {
// zip file download // zip file download
$zipFile = $exporter->exportZIP($exportPages, $exportOptions); $zipFile = $exporter->exportZIP($exportPages, $exportOptions);
if($zipFile) { if($zipFile) {
$this->wire('files')->send($zipFile, array( $files->send($zipFile, array(
'forceDownload' => true, 'forceDownload' => true,
'exit' => false 'exit' => false
)); ));
$this->wire('files')->unlink($zipFile); $files->unlink($zipFile);
exit; exit;
} else { } else {
throw new WireException('Export failed during ZIP file generation'); throw new WireException('Export failed during ZIP file generation');
@@ -1143,7 +1129,7 @@ class ProcessPagesExportImport extends Process {
$exporter = new PagesExportImport(); $exporter = new PagesExportImport();
$this->wire($exporter); $this->wire($exporter);
$fields = array(); $fields = array();
foreach($this->wire('fields') as $field) { foreach($this->wire()->fields as $field) {
if(!$field->type) continue; if(!$field->type) continue;
$info = $exporter->getFieldInfo($field); $info = $exporter->getFieldInfo($field);
if($info['exportable']) $fields[$field->name] = $field; if($info['exportable']) $fields[$field->name] = $field;
@@ -1169,4 +1155,3 @@ class ProcessPagesExportImport extends Process {
} }
} }