1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-16 19:54:24 +02:00

Fix issue processwire/processwire-issues#66 where deleting item from 2 different repeater fields at same time resulted in only item from first repeater being deleted

This commit is contained in:
Ryan Cramer
2016-11-14 07:57:29 -05:00
parent facc671e8d
commit 8b1e5a3c41
3 changed files with 25 additions and 10 deletions

View File

@@ -476,8 +476,11 @@ class Pages extends Wire {
* #pw-group-manipulation
*
* @param Page $page Page to delete
* @param bool $recursive If set to true, then this will attempt to delete all children too.
* @param array $options Optional settings to change behavior (for the future, none currently in use).
* @param bool|array $recursive If set to true, then this will attempt to delete all children too.
* If you don't need this argument, optionally provide $options array instead.
* @param array $options Optional settings to change behavior:
* - uncacheAll (bool): Whether to clear memory cache after delete (default=false)
* - recursive (bool): Same as $recursive argument, may be specified in $options array if preferred.
* @return bool|int Returns true (success), or integer of quantity deleted if recursive mode requested.
* @throws WireException on fatal error
* @see Pages::trash()

View File

@@ -969,24 +969,34 @@ class PagesEditor extends Wire {
* this method will throw an exception. If a recursive delete fails for any reason, an exception will be thrown.
*
* @param Page $page
* @param bool $recursive If set to true, then this will attempt to delete all children too.
* @param array $options Optional settings to change behavior (for the future)
* @param bool|array $recursive If set to true, then this will attempt to delete all children too.
* If you don't need this argument, optionally provide $options array instead.
* @param array $options Optional settings to change behavior:
* - uncacheAll (bool): Whether to clear memory cache after delete (default=false)
* - recursive (bool): Same as $recursive argument, may be specified in $options array if preferred.
* @return bool|int Returns true (success), or integer of quantity deleted if recursive mode requested.
* @throws WireException on fatal error
*
*/
public function delete(Page $page, $recursive = false, array $options = array()) {
$defaults = array(
'uncacheAll' => false,
'recursive' => is_bool($recursive) ? $recursive : false,
);
if(is_array($recursive)) $options = $recursive;
$options = array_merge($defaults, $options);
if($options) {} // to ignore unused parameter inspection
if(!$this->isDeleteable($page)) throw new WireException("This page may not be deleted");
$numDeleted = 0;
if($page->numChildren) {
if(!$recursive) {
if(!$options['recursive']) {
throw new WireException("Can't delete Page $page because it has one or more children.");
} else foreach($page->children("include=all") as $child) {
/** @var Page $child */
if($this->pages->delete($child, true)) {
if($this->pages->delete($child, true, $options)) {
$numDeleted++;
} else {
throw new WireException("Error doing recursive page delete, stopped by page $child");
@@ -1008,6 +1018,7 @@ class PagesEditor extends Wire {
} catch(\Exception $e) {
}
/** @var PagesAccess $access */
$access = $this->wire(new PagesAccess());
$access->deletePage($page);
@@ -1026,10 +1037,10 @@ class PagesEditor extends Wire {
$page->status = Page::statusDeleted; // no need for bitwise addition here, as this page is no longer relevant
$this->pages->deleted($page);
$numDeleted++;
$this->pages->uncacheAll($page);
if($options['uncacheAll']) $this->pages->uncacheAll($page);
$this->pages->debugLog('delete', $page, true);
return $recursive ? $numDeleted : true;
return $options['recursive'] ? $numDeleted : true;
}
/**

View File

@@ -1057,6 +1057,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
}
if(in_array($operator, array('*=', '~=', '^=', '$=', '%='))) {
/** @var DatabaseQuerySelectFulltext $ft */
$ft = $this->wire(new DatabaseQuerySelectFulltext($query));
$ft->match($table, $subfield, $operator, $value);
@@ -1221,7 +1222,7 @@ class FieldtypeRepeater extends Fieldtype implements ConfigurableModule {
if($value->has($p)) continue;
// $this->message("Deleted Repeater", Notice::debug);
// delete the repeater page
$this->wire('pages')->delete($p);
$this->wire('pages')->delete($p, $saveOptions);
}
$result = parent::___savePageField($page, $field);