Skip to content
This repository was archived by the owner on Feb 8, 2022. It is now read-only.

Commit a0f02db

Browse files
authored
Merge pull request #152 from Sterc/revert-134-sort-breaking
Revert "Sort function breaking in simplecart"
2 parents 53c417d + 005fe5d commit a0f02db

File tree

1 file changed

+50
-52
lines changed

1 file changed

+50
-52
lines changed

core/components/stercseo/elements/plugins/stercseo.plugin.php

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -280,60 +280,58 @@
280280
}
281281
break;
282282
}
283-
if ($resource) {
284-
$oldResource = $modx->getObject('modResource', $resource);
285-
$resource = $modx->getObject('modResource', $resource);
286-
if ($oldResource && $resource) {
287-
$resource->set('parent', $target);
288-
$resource->set('uri', '');
289-
$uriChanged = false;
290-
if ($oldResource->get('uri') != $resource->get('uri') && $oldResource->get('uri') != '') {
291-
$uriChanged = true;
292-
}
283+
$oldResource = $modx->getObject('modResource', $resource);
284+
$resource = $modx->getObject('modResource', $resource);
285+
if ($oldResource && $resource) {
286+
$resource->set('parent', $target);
287+
$resource->set('uri', '');
288+
$uriChanged = false;
289+
if ($oldResource->get('uri') != $resource->get('uri') && $oldResource->get('uri') != '') {
290+
$uriChanged = true;
291+
}
293292

294-
// Recursive set redirects for drag/dropped resource, and its children (where uri_override is not set)
295-
if ($uriChanged && $modx->getOption('use_alias_path')) {
296-
$oldResource->set('isfolder', true);
297-
$resourceOldBasePath = $oldResource->getAliasPath(
298-
$oldResource->get('alias'),
299-
$oldResource->toArray()
300-
);
301-
$resourceNewBasePath = $resource->getAliasPath(
302-
$resource->get('alias'),
303-
$resource->toArray() + array('isfolder' => 1)
304-
);
305-
$cond = $modx->newQuery('modResource');
306-
$cond->where(array(
307-
array(
308-
'uri:LIKE' => $resourceOldBasePath . '%',
309-
'OR:id:=' => $oldResource->id
310-
),
311-
'uri_override' => '0',
312-
'published' => '1',
313-
'deleted' => '0',
314-
'context_key' => $resource->get('context_key')
315-
));
316-
317-
$ctx = $modx->getContext($resource->get('context_key'));
318-
$site_url = $ctx->getOption('site_url', '', $modx->getOption('site_url'));
319-
320-
$childResources = $modx->getIterator('modResource', $cond);
321-
foreach ($childResources as $childResource) {
322-
$url = urlencode($site_url . $childResource->get('uri'));
323-
if (!$modx->getCount('seoUrl', array('url' => $url))) {
324-
$data = array(
325-
'url' => $url,
326-
'resource' => $childResource->get('id'),
327-
'context_key' => $targetCtx
328-
);
329-
$redirect = $modx->newObject('seoUrl');
330-
$redirect->fromArray($data);
331-
$redirect->save();
332-
}
293+
// Recursive set redirects for drag/dropped resource, and its children (where uri_override is not set)
294+
if ($uriChanged && $modx->getOption('use_alias_path')) {
295+
$oldResource->set('isfolder', true);
296+
$resourceOldBasePath = $oldResource->getAliasPath(
297+
$oldResource->get('alias'),
298+
$oldResource->toArray()
299+
);
300+
$resourceNewBasePath = $resource->getAliasPath(
301+
$resource->get('alias'),
302+
$resource->toArray() + array('isfolder' => 1)
303+
);
304+
$cond = $modx->newQuery('modResource');
305+
$cond->where(array(
306+
array(
307+
'uri:LIKE' => $resourceOldBasePath . '%',
308+
'OR:id:=' => $oldResource->id
309+
),
310+
'uri_override' => '0',
311+
'published' => '1',
312+
'deleted' => '0',
313+
'context_key' => $resource->get('context_key')
314+
));
315+
316+
$ctx = $modx->getContext($resource->get('context_key'));
317+
$site_url = $ctx->getOption('site_url', '', $modx->getOption('site_url'));
318+
319+
$childResources = $modx->getIterator('modResource', $cond);
320+
foreach ($childResources as $childResource) {
321+
$url = urlencode($site_url . $childResource->get('uri'));
322+
if (!$modx->getCount('seoUrl', array('url' => $url))) {
323+
$data = array(
324+
'url' => $url,
325+
'resource' => $childResource->get('id'),
326+
'context_key' => $targetCtx
327+
);
328+
$redirect = $modx->newObject('seoUrl');
329+
$redirect->fromArray($data);
330+
$redirect->save();
333331
}
334-
} // endif $uriChanged
335-
} // endif $oldResource && $resource
336-
}
332+
}
333+
} // endif $uriChanged
334+
} // endif $oldResource && $resource
337335
break;
338336

339337
case 'OnResourceDuplicate':

0 commit comments

Comments
 (0)