mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 08:17:12 +02:00
Some adjustments to FieldtypeRepeater for single page mode and update PagesExportImport for support
This commit is contained in:
@@ -1044,6 +1044,14 @@ $config->logs = array(
|
||||
'exceptions',
|
||||
);
|
||||
|
||||
/**
|
||||
* Include IP address in logs, when applicable?
|
||||
*
|
||||
* @var bool
|
||||
*
|
||||
*/
|
||||
$config->logIP = false;
|
||||
|
||||
/**
|
||||
* Default admin theme
|
||||
*
|
||||
|
@@ -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;
|
||||
try {
|
||||
$pageValue = $field->type->importValue($page, $field, $exportValue, $o);
|
||||
$page->warning("$field: " . $e->getMessage());
|
||||
$page->warning("$field: Attempted to restore previous value");
|
||||
} catch(\Exception $e) {
|
||||
$commitException = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!$commitException) {
|
||||
|
@@ -73,6 +73,7 @@ class WireShutdown extends Wire {
|
||||
$config = $this->wire('config');
|
||||
$user = $this->wire('user');
|
||||
$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;
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
Reference in New Issue
Block a user