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

Commit 53c417d

Browse files
authored
Merge pull request #134 from Sterc/sort-breaking
Sort function breaking in simplecart
2 parents 8e7057e + f5654e4 commit 53c417d

File tree

1 file changed

+52
-50
lines changed

1 file changed

+52
-50
lines changed

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

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -280,58 +280,60 @@
280280
}
281281
break;
282282
}
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-
}
292-
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'));
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+
}
318293

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();
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+
}
331333
}
332-
}
333-
} // endif $uriChanged
334-
} // endif $oldResource && $resource
334+
} // endif $uriChanged
335+
} // endif $oldResource && $resource
336+
}
335337
break;
336338

337339
case 'OnResourceDuplicate':

0 commit comments

Comments
 (0)