Last active
March 1, 2018 18:14
-
-
Save ig0r74/02177032083ad9c792680ddaa7198169 to your computer and use it in GitHub Desktop.
Console Выборка ресурсов, изменение полей и сохранение
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 | |
print '<pre>'; | |
ini_set('display_errors', 1); | |
$where = array( | |
'parent' => 47, | |
'publishedon' => '' | |
); | |
$resources = $modx->getCollection('modResource',$where); | |
$output = '<p>Всего ресурсов: '.count($resources).'</p>'; | |
foreach ($resources as $k => $res) { | |
$output .= '<p>['.$k.'] => '.$res->get('pagetitle').'</p>'; | |
// $res->set('publishedon', '2016-06-10 17:40:45'); | |
// $res->save(); | |
} | |
print $output; | |
// -- Пример if in_array | |
(in_array ($current_id, array(39,41)))?"если в массиве, то выводим этот текст":'') | |
// -- Удаляем слэш в конце у замороженных ссылок | |
$recs=$modx->getIterator('modResource',['uri_override'=>1]); | |
foreach($recs as $r){ | |
$r->set('uri', preg_replace('/\/$/','',$r->get('uri'))); | |
$r->save(); | |
} | |
print 'OK'; | |
// -- Обрабатываем контент | |
foreach ($resources as $k => $res) { | |
$res->set('content', str_replace(array('http://rusnavgeo.ru', 'wp-content/uploads/'), array('', 'assets/images/site/uploads/'),$res->content)); | |
$res->save(); | |
} | |
// -- Набивка картинок в MIGX | |
// -- Задача стояла прочитать все файлы в директории и набить их в галерею | |
$doc_id = 87013; | |
$path = 'gallery/87013/'; | |
$uploads_path = MODX_BASE_PATH . "uploads/"; | |
$doc = $modx->getObject("modResource", $doc_id); | |
$files = glob("{$uploads_path}{$path}*"); | |
$migx = array(); | |
foreach($files as $file){ | |
$basename = basename($file); | |
$migx[] = array( | |
"MIGX_id" => count($migx) + 1, | |
"title" => "", | |
"image" => "{$path}{$basename}", | |
"description" => "", | |
); | |
} | |
if($migx){ | |
$doc->setTVValue(27, json_encode($migx)); | |
// print_r($migx); | |
} | |
// -- MIGX в MIGX | |
// -- MIGX с двумя уровнями вложенности | |
if ($res = $modx->getObject('modResource', 1297)) { | |
$v = $res->getTVValue(10); | |
$v = json_decode($v,1); | |
foreach ($v as & $item) { | |
$item[services] = json_decode($item[services],1); | |
foreach ($item[services] as & $item2) { | |
echo '<option data-price="' . $item2[price] . '" value="' . $item2[MIGX_id] . '">' . $item2[title] . '</option><br>'; | |
} | |
} | |
//echo "<pre>"; | |
//print_r ($v); | |
die; | |
} | |
// Копируем значение TV, получаем документы с вложенностью и вставляем в TV | |
$where = array( | |
'contentid' => 981 | |
, 'tmplvarid' => 10 | |
); | |
$tv = $modx->getObject('modTemplateVarResource', $where); | |
print $tv->get('value'); | |
$tv = $tv->get('value'); | |
$child = $modx->getChildIds(49, 10, array('context' => 'web')); | |
$collection = $modx->getCollection('modResource', array( | |
'id:IN' => $child, | |
'template' => 8, | |
// 'deleted' => false, | |
)); | |
foreach ($collection as $k => $res) { | |
$output .= '<p>['.$k.'] => '.$res->get('pagetitle').'</p>'; | |
$res->setTVValue(prices, $tv); | |
// $res->set('prices', $tv); | |
// $res->set('publishedon', '2016-06-10 17:40:45'); | |
// $res->save(); | |
} | |
print $output; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment