Created
April 8, 2016 20:24
-
-
Save andronex/7c19c64998120141a699a2371e468aff to your computer and use it in GitHub Desktop.
Копирование ресурсов MODX
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 | |
define('MODX_API_MODE', true); | |
require_once(dirname(__FILE__).'/index.php'); | |
// Включаем обработку ошибок | |
$modx->getService('error','error.modError'); | |
$modx->setLogLevel(modX::LOG_LEVEL_ERROR); | |
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML'); | |
$modx->error->message = null; // Обнуляем переменную | |
$parent = 15; | |
$kuda = array( | |
125 => 'Дедовске' | |
,179 => 'Истре' | |
,180 => 'Нахабино' | |
); | |
$i=0; | |
$sql="SELECT * FROM modx_site_content WHERE parent = {$parent}"; | |
$result= $modx->query($sql); | |
$data= $result->fetchAll(PDO::FETCH_ASSOC); | |
foreach($data as $v){ | |
foreach($kuda as $kv => $vv){ | |
$fields = array( | |
'id' => $v['id'], | |
'name' => $v['pagetitle']." в $vv" | |
); | |
$response = $modx->runProcessor('resource/duplicate', $fields); | |
if ($response->isError()) { | |
$modx->log(modX::LOG_LEVEL_ERROR, 'Failed to copy Resource '.$v['id']); | |
} | |
$newRes = $response->getObject(); | |
$resource = $modx->getObject('modResource', $newRes['id']); | |
$resource->set('parent', $kv); | |
$resource->set('longtitle', $v['pagetitle']); | |
if ($resource->save() == false) { | |
$modx->log(modX::LOG_LEVEL_ERROR, 'Failed to update Resource '.$newRes['id']); | |
} | |
$i++; | |
} | |
echo "скопировано за цикл $i\n<br>"; | |
} | |
echo "итого скопировано $i\n<br>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment