Created
October 21, 2021 13:03
-
-
Save Semdevmaster/6876822289db838ccfbddd5db64c6167 to your computer and use it in GitHub Desktop.
Скрипт очистки дублей редиректов в компоненте Seosuite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Скрипт очистки дублей редиректов в компоненте Seosuite | |
| * @var modX $modx | |
| */ | |
| $resource_template = 3; | |
| $otherProps = [ | |
| 'processors_path' => $modx->getOption('core_path') . 'components/seosuite/processors/' | |
| ]; | |
| $resources = $modx->getCollection('msProduct', [ | |
| 'template' => $resource_template | |
| ]); | |
| foreach ($resources as $resource) { | |
| $resource_id = (int)$resource->get('id'); | |
| $resource_uri = $resource->get('uri'); | |
| $getlistprops = [ | |
| 'start' => 0, | |
| 'limit' => 0, | |
| 'resource' => $resource_id | |
| ]; | |
| $redirectsIds = []; | |
| $response = $modx->runProcessor('mgr/redirects/getlist', $getlistprops, $otherProps); | |
| if ($response->isError()) { | |
| $modx->log(1, 'Message: ' . print_r($response->response)); | |
| } | |
| $response = json_decode($response->response, true, 512, JSON_THROW_ON_ERROR); | |
| if (!empty($response['results'])) { | |
| foreach ($response['results'] as $redirect) { | |
| if($resource_uri == $redirect['old_url']){ | |
| $redirectsIds[] = $redirect['id']; | |
| } | |
| } | |
| $modx->log(1, 'Было удалено: '.count($redirectsIds).' дублей редиректов'); | |
| $removeprops = [ | |
| 'id' => implode(",", $redirectsIds) | |
| ]; | |
| $response = $modx->runProcessor('mgr/redirects/removemultiple', $removeprops, $otherProps); | |
| if ($response->isError()) { | |
| $modx->log(1, 'Message: ' . print_r($response->response)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment