Created
November 17, 2016 18:51
-
-
Save morelmm/0b00bd67b5f4f9b40a16ea2ed8c80bc9 to your computer and use it in GitHub Desktop.
Modx/babel recursive translation generation
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 | |
$id =$scriptProperties['id']; | |
$ctxSource = $scriptProperties['ctxSource']; | |
$ctxDest = $scriptProperties['ctxDest']; | |
$count = 0; | |
global $babel; | |
$babel = $modx->getService('babel','Babel',$modx->getOption('babel.core_path',null,$modx->getOption('core_path').'components/babel/').'model/babel/'); | |
$resources = $modx->getCollection('modResource', | |
array('parent'=> 0, 'context_key' => $ctxSource)); | |
function generateChildren($resid,$ctxSource,$ctxDest,&$count){ | |
global $modx; | |
global $babel; | |
$children = $modx->getCollection('modResource', | |
array('parent' => $resid, 'context_key' => $ctxSource)); | |
foreach ($children as $child) { | |
$linkedResources = $babel->getLinkedResources($child->get('id')); | |
if ($linkedResources[$ctxDest] == '') { | |
$newObject = $babel->duplicateResource($child, $ctxDest); | |
$count++; | |
$linkedResources = $babel->getLinkedResources($child->get('id')); | |
if(empty($linkedResources)) { | |
$linkedResources[$ctxSource] = $child->get('id'); | |
} | |
$linkedResources[$ctxDest] = $newObject->get('id'); | |
$babel->updateBabelTv($linkedResources, $linkedResources); | |
unset($newObject); | |
} | |
generateChildren($child->get('id'),$ctxSource,$ctxDest,$count); | |
} | |
} | |
foreach($resources as $resource) { | |
$linkedResources = $babel->getLinkedResources($resource->get('id')); | |
if ($linkedResources[$ctxDest] == '') { | |
$newObject = $babel->duplicateResource($resource, $ctxDest); | |
$count++; | |
if(empty($linkedResources)) { | |
$linkedResources[$ctxSource] = $resource->get('id'); | |
} | |
$linkedResources[$ctxDest] = $newObject->get('id'); | |
$babel->updateBabelTv($linkedResources, $linkedResources); | |
unset($newObject); | |
} | |
generateChildren($resource->get('id'),$ctxSource,$ctxDest,$count); | |
} | |
return($count); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, worked like a charm!