Created
March 6, 2023 14:32
-
-
Save andronex/4a50e094873b11336ec1ff4bb6a994b4 to your computer and use it in GitHub Desktop.
Замена ссылок в content поле ресурсов на новые ID ресурсов
This file contains 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 | |
$parents = file_exists(MODX_BASE_PATH . 'parents.txt')?json_decode(file_get_contents(MODX_BASE_PATH . 'parents.txt'), true):[]; | |
//print_r($parents); | |
$ress = $modx->getCollection('modResource'); | |
foreach($ress as $res){ | |
$content = $res->get('content'); | |
preg_match_all('/\[\[\~(\d+)\~{0,}\]\]/', $content, $links); | |
if($links[1]){ | |
foreach($links[1] as $k => $lnk){ | |
if(isset($parents[$lnk])){ | |
$tmp_lnk = str_replace($lnk, $parents[$lnk], $links[0][$k]); | |
$content = str_replace($links[0][$k], $tmp_lnk, $content); | |
print_r($links[0][$k] . '/'.$tmp_lnk . '/' . $res->id . "\n"); | |
// print_r($content . "\n"); | |
// $res->set('content', $content); | |
// $res->save(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment