/** * Updates the Context of all Children recursively to that of the parent. * * @static * @param modX &$modx A reference to an initialized modX instance. * @param modResource $parent The parent modResource instance. * @param array $options An array of options. * @return int The number of children updated. */ public static function updateContextOfChildren(modX &$modx, $parent, array $options = array()) { $count = 0; /** @var modResource $child */ foreach ($parent->getIterator('Children') as $child) { $child->set('context_key', $parent->get('context_key')); if ($child->save()) { $count++; } else { $modx->log(modX::LOG_LEVEL_ERROR, "Could not change Context of child resource {$child->get('id')}", '', __METHOD__, __FILE__, __LINE__); } } return $count; }