original_string: protected static function create_level_instances() {
          global $DB;
  
          $sql = "SELECT ".CONTEXT_COURSECAT.", cc.id
                    FROM {course_categories} cc
                   WHERE NOT EXISTS (SELECT 'x'
                                       FROM {context} cx
                                      WHERE cc.id = cx.instanceid AND cx.contextlevel=".CONTEXT_COURSECAT.")";
          $contextdata = $DB->get_recordset_sql($sql);
          foreach ($contextdata as $context) {
              context::insert_context_record(CONTEXT_COURSECAT, $context->id, null);
          }
          $contextdata->close();
      }
code: protected static function create_level_instances() {
          global $DB;
  
          $sql = "SELECT ".CONTEXT_COURSECAT.", cc.id
                    FROM {course_categories} cc
                   WHERE NOT EXISTS (SELECT 'x'
                                       FROM {context} cx
                                      WHERE cc.id = cx.instanceid AND cx.contextlevel=".CONTEXT_COURSECAT.")";
          $contextdata = $DB->get_recordset_sql($sql);
          foreach ($contextdata as $context) {
              context::insert_context_record(CONTEXT_COURSECAT, $context->id, null);
          }
          $contextdata->close();
      }
code_tokens: protected static function create_level_instances ( ) { global $ DB ; $ sql = "SELECT " . CONTEXT_COURSECAT . ", cc.id
                    FROM {course_categories} cc
                   WHERE NOT EXISTS (SELECT 'x'
                                       FROM {context} cx
                                      WHERE cc.id = cx.instanceid AND cx.contextlevel=" . CONTEXT_COURSECAT . ")" ; $ contextdata = $ DB -> get_recordset_sql ( $ sql ) ; foreach ( $ contextdata as $ context ) { context :: insert_context_record ( CONTEXT_COURSECAT , $ context -> id , null ) ; } $ contextdata -> close ( ) ; }
docstring: Create missing context instances at course category context level
  @static
docstring_tokens: Create missing context instances at course category context level