diff --git a/wire/config.php b/wire/config.php index c2c9d1a3..faa5374a 100644 --- a/wire/config.php +++ b/wire/config.php @@ -1044,6 +1044,14 @@ $config->logs = array( 'exceptions', ); +/** + * Include IP address in logs, when applicable? + * + * @var bool + * + */ +$config->logIP = false; + /** * Default admin theme * diff --git a/wire/core/PagesExportImport.php b/wire/core/PagesExportImport.php index eb904a44..bc06b435 100644 --- a/wire/core/PagesExportImport.php +++ b/wire/core/PagesExportImport.php @@ -912,7 +912,7 @@ class PagesExportImport extends Wire { } $pageValue = $page->getUnformatted($field->name); - $exportValue = $pageValue === null ? null : $field->type->exportValue($page, $field, $pageValue, $o); + $exportValue = $pageValue === null || !$page->id ? null : $field->type->exportValue($page, $field, $pageValue, $o); if(is_array($importValue) && is_array($exportValue)) { // use regular '==' only for array comparisons @@ -930,11 +930,16 @@ class PagesExportImport extends Wire { try { $pageValue = $field->type->importValue($page, $field, $importValue, $o); } catch(\Exception $e) { - if($options['commit'] && $fieldtypeImportOptions['restoreOnException']) { + $warning = $e->getMessage(); + $page->warning((strpos($warning, "$field:") === 0 ? '' : "$field: ") . $warning); + if($options['commit'] && $fieldtypeImportOptions['restoreOnException'] && $page->id) { $commitException = true; - $pageValue = $field->type->importValue($page, $field, $exportValue, $o); - $page->warning("$field: " . $e->getMessage()); - $page->warning("$field: Attempted to restore previous value"); + try { + $pageValue = $field->type->importValue($page, $field, $exportValue, $o); + $page->warning("$field: Attempted to restore previous value"); + } catch(\Exception $e) { + $commitException = true; + } } } if(!$commitException) { diff --git a/wire/core/WireShutdown.php b/wire/core/WireShutdown.php index a8001897..459c1d88 100644 --- a/wire/core/WireShutdown.php +++ b/wire/core/WireShutdown.php @@ -72,7 +72,8 @@ class WireShutdown extends Wire { $http = isset($_SERVER['HTTP_HOST']); $config = $this->wire('config'); $user = $this->wire('user'); - $userName = $user ? $user->name : '?'; + $userName = $user ? $user->name : '?'; + if($config && $config->logIP && isset($_SERVER['REMOTE_ADDR'])) $userName .= " ($_SERVER[REMOTE_ADDR])"; $page = $this->wire('page'); $path = ($config ? $config->httpHost : '') . ($page ? $page->url : '/?/'); if($config && $http) $path = ($config->https ? 'https://' : 'http://') . $path; diff --git a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module index 7fdc2ae9..9d70a76f 100644 --- a/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module +++ b/wire/modules/Fieldtype/FieldtypeRepeater/FieldtypeRepeater.module @@ -793,6 +793,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule { $repeaterParent = $this->getRepeaterPageParent($page, $field); $repeaterTemplate = $this->getRepeaterTemplate($field); $repeaterPageClass = $this->getPageClass(); + $repeaterPageArrayClass = $this->getPageArrayClass(); $parentPath = $repeaterParent->path(); $commit = isset($options['commit']) ? (bool) $options['commit'] : true; $messages = array(); @@ -805,9 +806,17 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule { $importItemNames = array(); $existingValue = $page->get($field->name); + if(!$existingValue instanceof PageArray) { // i.e. FieldsetPage + $existingValue = $existingValue->id ? array($existingValue) : array(); + } + // update paths for local foreach($value['pages'] as $key => $item) { $name = $item['settings']['name']; + if(strpos($name, self::repeaterPageNamePrefix) === 0 && count($value['pages']) == 1) { + $name = self::repeaterPageNamePrefix . $page->id; // i.e. FieldsetPage + $value['pages'][$key]['settings']['name'] = $name; + } $path = $parentPath . $name . '/'; $importItemNames[$name] = $name; $value['pages'][$key]['path'] = $path; @@ -829,22 +838,28 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule { $p->setForField($field); $p->save(); $itemsAdded[$p->id] = $p; + if($p->name != $name) $importItemNames[$p->name] = $p->name; } } - - foreach($existingValue as $p) { - if(!isset($importItemNames[$p->name])) { - $itemsDeleted[] = $p; - $numDeleted++; + + if($page->get('_importType') == 'update') { + foreach($existingValue as $p) { + if(!isset($importItemNames[$p->name])) { + $itemsDeleted[] = $p; + $numDeleted++; + } } } + + /** @var RepeaterPageArray $pageArray */ + $pageArray = $this->wire(new $repeaterPageArrayClass($page, $field)); $importOptions = array( 'commit' => $commit, 'create' => true, 'update' => true, 'delete' => true, // @todo - 'pageArray' => $this->getBlankValue($page, $field), + 'pageArray' => $pageArray ); /** @var PagesExportImport $importer */ @@ -1208,6 +1223,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule { public function getMatchQuery($query, $table, $subfield, $operator, $value) { $field = $query->field; + $singlePageMode = $this->className() == 'FieldtypeFieldsetPage'; if($subfield == 'count') { $value = (int) $value; @@ -1273,13 +1289,17 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule { $pageFinder = $this->wire(new PageFinder()); $value = $this->wire('sanitizer')->selectorValue($value); $templateID = $field->get('template_id'); - $selectors = $this->wire(new Selectors("templates_id=$templateID, check_access=0, $f->name$operator$value")); + $includeMode = $singlePageMode ? "include=all" : "check_access=0"; + $selectors = $this->wire(new Selectors("templates_id=$templateID, $includeMode, $f->name$operator$value")); $matches = $pageFinder->find($selectors); // use the IDs found from the separate find() as our getMatchQuery if(count($matches)) { $ids = array(); - foreach($matches as $match) $ids[$match['parent_id']] = $match['parent_id']; + $matchKey = $singlePageMode ? 'id' : 'parent_id'; + foreach($matches as $match) { + $ids[$match[$matchKey]] = $match[$matchKey]; + } $query->where("$table.parent_id IN(" . implode(',', $ids) . ")"); } else { $query->where("1>2"); // force a non-match