Created
June 29, 2020 22:05
-
-
Save dzhuryn/f8452b5e8a98050b226e879688ac9538 to your computer and use it in GitHub Desktop.
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 | |
| /* | |
| Создаем файлик, запускаэм, потом в плагине тип меняем на default | |
| */ | |
| define('MODX_API_MODE', true); | |
| include_once($_SERVER['DOCUMENT_ROOT'] . "/index.php"); | |
| $modx->db->connect(); | |
| if (empty ($modx->config)) { | |
| $modx->getSettings(); | |
| } | |
| require_once MODX_BASE_PATH.'assets/lib/MODxAPI/modResource.php'; | |
| $modx->invokeEvent("OnWebPageInit"); | |
| $R = $modx->getFullTableName('site_content'); | |
| $TV = $modx->getFullTableName('site_tmplvars'); | |
| $TT = $modx->getFullTableName('site_tmplvar_templates'); | |
| $sql = "select id,name from $TV where type = 'custom_tv:multifields'"; | |
| $tvs = $modx->db->makeArray($modx->db->query($sql)); | |
| if(empty($tvs)){ | |
| echo 'Отсутствуют тв из типом multifields'; | |
| return ; | |
| } | |
| $tvNames = []; | |
| $tvIds = array_column($tvs,'id'); | |
| foreach ($tvs as $tv) { | |
| $tvNames[$tv['id']] = $tv['name']; | |
| } | |
| $templates = $modx->db->makeArray($modx->db->select('*',$TT,'tmplvarid in('.implode(',',$tvIds).')')); | |
| $templates = array_unique(array_column($templates, 'templateid')); | |
| if(empty($templates)){ | |
| echo 'Тв из типом multifields не используются'; | |
| return ; | |
| } | |
| $resources = $modx->db->getColumn('id',$modx->db->select('id',$R,' template in('.implode(',',$templates).')')); | |
| $tvUpdateCount=0; | |
| foreach ($resources as $docId) { | |
| $doc = new modResource($modx); | |
| $doc->edit($docId); | |
| $hasChange = false; | |
| foreach ($tvIds as $tvId) { | |
| $tvName = $tvNames[$tvId]; | |
| $tvValues = $modx->runSnippet('multifields',[ | |
| 'api'=>"0", | |
| 'docid'=>$docId, | |
| 'tvId'=>$tvId | |
| ]); | |
| if(empty($tvValues)){ | |
| continue; | |
| } | |
| $hasChange = true; | |
| $tvUpdateCount++; | |
| $doc->set($tvName,json_encode($tvValues)); | |
| } | |
| if($hasChange){ | |
| $doc->save(); | |
| } | |
| } | |
| echo "Обновлено tv $tvUpdateCount"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment