Skip to content

Instantly share code, notes, and snippets.

@andronex
Created April 8, 2016 20:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andronex/7c19c64998120141a699a2371e468aff to your computer and use it in GitHub Desktop.
Save andronex/7c19c64998120141a699a2371e468aff to your computer and use it in GitHub Desktop.
Копирование ресурсов MODX
<?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