Skip to content

Commit de7abc9

Browse files
JoshuaLuckersopengeekMark-H
authored
Prevent cascading container conversion on resource move (#16001)
* Fix issue where moving resource above another would make the "target" a container * Reformat code according to code style * Return failures Co-authored-by: Mark Hamstra <[email protected]> Co-authored-by: Jason Coward <[email protected]> Co-authored-by: Mark Hamstra <[email protected]>
1 parent 3bc624f commit de7abc9

File tree

1 file changed

+24
-11
lines changed
  • core/src/Revolution/Processors/Resource

1 file changed

+24
-11
lines changed

core/src/Revolution/Processors/Resource/Sort.php

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/*
34
* This file is part of MODX Revolution.
45
*
@@ -10,7 +11,6 @@
1011

1112
namespace MODX\Revolution\Processors\Resource;
1213

13-
1414
use MODX\Revolution\modContext;
1515
use MODX\Revolution\Processors\Processor;
1616
use MODX\Revolution\modResource;
@@ -53,9 +53,13 @@ public function process()
5353

5454
// Because of BC
5555
$data = urldecode($this->getProperty('data', ''));
56-
if (empty($data)) $this->failure($this->modx->lexicon('invalid_data'));
56+
if (empty($data)) {
57+
return $this->failure($this->modx->lexicon('invalid_data'));
58+
}
5759
$data = $this->modx->fromJSON($data);
58-
if (empty($data)) $this->failure($this->modx->lexicon('invalid_data'));
60+
if (empty($data)) {
61+
return $this->failure($this->modx->lexicon('invalid_data'));
62+
}
5963

6064
// Because of BC
6165
$this->getNodesFormatted($data, $this->getProperty('parent', 0));
@@ -66,7 +70,7 @@ public function process()
6670
$source = $this->getProperty('source', '');
6771
$point = $this->getProperty('point', '');
6872

69-
if (empty ($target)) {
73+
if (empty($target)) {
7074
return $this->failure('Target not set');
7175
}
7276

@@ -83,7 +87,9 @@ public function process()
8387
$this->parseNodes($source, $target);
8488

8589
$sorted = $this->sort();
86-
if ($sorted !== true) return $this->failure($sorted);
90+
if ($sorted !== true) {
91+
return $this->failure($sorted);
92+
}
8793

8894
$this->fireAfterSort();
8995

@@ -151,7 +157,6 @@ public function fireAfterSort()
151157
'contextsAffected' => &$this->contextsAffected,
152158
'modifiedNodes' => &$this->nodesAffected, /* backward compat */
153159
]);
154-
155160
}
156161

157162
public function clearCache()
@@ -174,8 +179,12 @@ public function fixParents($node)
174179
/** @var modResource $newParent */
175180
$newParent = $this->modx->getObject(modResource::class, $this->target->id);
176181

177-
if (empty($oldParent) && empty($newParent)) return;
178-
if ($oldParent->id == $newParent->id) return;
182+
if (empty($oldParent) && empty($newParent)) {
183+
return;
184+
}
185+
if ($oldParent->id == $newParent->id) {
186+
return;
187+
}
179188

180189
if (!empty($oldParent)) {
181190
$oldParentChildrenCount = $this->modx->getCount(modResource::class, ['parent' => $oldParent->get('id'), 'id:!=' => $node->id]);
@@ -189,7 +198,7 @@ public function fixParents($node)
189198
}
190199
}
191200

192-
if (!empty($newParent)) {
201+
if (!empty($newParent) && $this->point === 'append') {
193202
$newParent->set('isfolder', true);
194203
$newParent->save();
195204

@@ -343,10 +352,14 @@ public function moveResource($type, $rank)
343352
public function moveResourceAbove($lastRank)
344353
{
345354
$moved = $this->moveResource('source', $lastRank);
346-
if ($moved !== true) return $moved;
355+
if ($moved !== true) {
356+
return $moved;
357+
}
347358

348359
$moved = $this->moveResource('target', $lastRank + 1);
349-
if ($moved !== true) return $moved;
360+
if ($moved !== true) {
361+
return $moved;
362+
}
350363

351364
return $this->moveAffectedResources($lastRank);
352365
}

0 commit comments

Comments
 (0)