Skip to content

Commit

Permalink
[mikrobi#84] optimize OnResourceDuplicate
Browse files Browse the repository at this point in the history
  • Loading branch information
goldsky committed Nov 26, 2014
1 parent f1f60a6 commit 05b8e5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
1 change: 1 addition & 0 deletions core/components/babel/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Changelog for Babel.

Babel 3.0.0-dev
==============
- [#84] optimize OnResourceDuplicate
- [#44][#29] Using cultureKey instead of contextKey on BabelTranslation snippet
- [#70] fix is_folder to isfolder
- [#27][#90][#92] Refactor language selection, runs using AJAX
Expand Down
2 changes: 1 addition & 1 deletion core/components/babel/elements/plugins/babel.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
case 'OnResourceDuplicate':
/* init Babel TV of duplicated resources */
$resource =& $modx->event->params['newResource'];
$babel->initBabelTvsRecursive($modx,$babel,$resource);
$babel->initBabelTvsRecursive($modx,$babel,$resource->get('id'));
break;
}
return;
19 changes: 11 additions & 8 deletions core/components/babel/model/babel/babel.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,23 +288,26 @@ public function initBabelTv($resource) {
*
* @param object $modx
* @param object $babel
* @param object $resource
* @param int $id
* @param int $depth
*
* @return void
*/
public function initBabelTvsRecursive(&$modx, &$babel, $resource = null, $depth = 100) {
if ($resource && $depth > 0) {
$children = $resource->getMany('Children');
public function initBabelTvsRecursive(&$modx, &$babel, $id = null, $depth = 100) {
if ($id && $depth > 0) {
$q = $modx->newQuery('modResource');
$q->select(array('id'));
$q->where(array('parent' => $id));
$children = $modx->getCollection('modResource', $q);
foreach ($children as $child) {
$processDepth = $depth - 1;
$this->initBabelTvsRecursive($modx, $babel, $child, $processDepth);
$this->initBabelTvsRecursive($modx, $babel, $child->get('id'), $processDepth);
}
$this->initBabelTv($resource);
$this->initBabelTvById($id);
}
}
/**

/**
* Init/reset the Babel TV of a resource specified by the id of the resource.
*
* @param int $resourceId id of resource (int).
Expand Down

0 comments on commit 05b8e5c

Please sign in to comment.