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