original_string: protected static function migrate_competency_tree_rules($tree, $matchids) {
  
          foreach ($tree as $node) {
              $oldcompid = $node->competency->get('id');
              if ($node->competency->get('ruletype') && array_key_exists($oldcompid, $matchids)) {
                  try {
                      // Get the new competency.
                      $competency = $matchids[$oldcompid];
                      $class = $node->competency->get('ruletype');
                      $newruleconfig = $class::migrate_config($node->competency->get('ruleconfig'), $matchids);
                      $competency->set('ruleconfig', $newruleconfig);
                      $competency->set('ruletype', $class);
                      $competency->set('ruleoutcome', $node->competency->get('ruleoutcome'));
                      $competency->update();
                  } catch (\Exception $e) {
                      debugging('Could not migrate competency rule from: ' . $oldcompid . ' to: ' . $competency->get('id') . '.' .
                          ' Exception: ' . $e->getMessage(), DEBUG_DEVELOPER);
                      $competency->reset_rule();
                  }
              }
  
              if (!empty($node->children)) {
                  self::migrate_competency_tree_rules($node->children, $matchids);
              }
          }
      }
code: protected static function migrate_competency_tree_rules($tree, $matchids) {
  
          foreach ($tree as $node) {
              $oldcompid = $node->competency->get('id');
              if ($node->competency->get('ruletype') && array_key_exists($oldcompid, $matchids)) {
                  try {
                      // Get the new competency.
                      $competency = $matchids[$oldcompid];
                      $class = $node->competency->get('ruletype');
                      $newruleconfig = $class::migrate_config($node->competency->get('ruleconfig'), $matchids);
                      $competency->set('ruleconfig', $newruleconfig);
                      $competency->set('ruletype', $class);
                      $competency->set('ruleoutcome', $node->competency->get('ruleoutcome'));
                      $competency->update();
                  } catch (\Exception $e) {
                      debugging('Could not migrate competency rule from: ' . $oldcompid . ' to: ' . $competency->get('id') . '.' .
                          ' Exception: ' . $e->getMessage(), DEBUG_DEVELOPER);
                      $competency->reset_rule();
                  }
              }
  
              if (!empty($node->children)) {
                  self::migrate_competency_tree_rules($node->children, $matchids);
              }
          }
      }
code_tokens: protected static function migrate_competency_tree_rules ( $ tree , $ matchids ) { foreach ( $ tree as $ node ) { $ oldcompid = $ node -> competency -> get ( 'id' ) ; if ( $ node -> competency -> get ( 'ruletype' ) && array_key_exists ( $ oldcompid , $ matchids ) ) { try { // Get the new competency. $ competency = $ matchids [ $ oldcompid ] ; $ class = $ node -> competency -> get ( 'ruletype' ) ; $ newruleconfig = $ class :: migrate_config ( $ node -> competency -> get ( 'ruleconfig' ) , $ matchids ) ; $ competency -> set ( 'ruleconfig' , $ newruleconfig ) ; $ competency -> set ( 'ruletype' , $ class ) ; $ competency -> set ( 'ruleoutcome' , $ node -> competency -> get ( 'ruleoutcome' ) ) ; $ competency -> update ( ) ; } catch ( \ Exception $ e ) { debugging ( 'Could not migrate competency rule from: ' . $ oldcompid . ' to: ' . $ competency -> get ( 'id' ) . '.' . ' Exception: ' . $ e -> getMessage ( ) , DEBUG_DEVELOPER ) ; $ competency -> reset_rule ( ) ; } } if ( ! empty ( $ node -> children ) ) { self :: migrate_competency_tree_rules ( $ node -> children , $ matchids ) ; } } }
docstring: Recursively migrate competency rules.
  
  @param competency[] $tree - array of competencies object
  @param competency[] $matchids - List of old competencies ids matched with new competencies object
docstring_tokens: Recursively migrate competency rules .