original_string: public function delete_full($showfeedback = true) {
          global $CFG, $DB;
  
          require_once($CFG->libdir.'/gradelib.php');
          require_once($CFG->libdir.'/questionlib.php');
          require_once($CFG->dirroot.'/cohort/lib.php');
  
          // Make sure we won't timeout when deleting a lot of courses.
          $settimeout = core_php_time_limit::raise();
  
          // Allow plugins to use this category before we completely delete it.
          if ($pluginsfunction = get_plugins_with_function('pre_course_category_delete')) {
              $category = $this->get_db_record();
              foreach ($pluginsfunction as $plugintype => $plugins) {
                  foreach ($plugins as $pluginfunction) {
                      $pluginfunction($category);
                  }
              }
          }
  
          $deletedcourses = array();
  
          // Get children. Note, we don't want to use cache here because it would be rebuilt too often.
          $children = $DB->get_records('course_categories', array('parent' => $this->id), 'sortorder ASC');
          foreach ($children as $record) {
              $coursecat = new self($record);
              $deletedcourses += $coursecat->delete_full($showfeedback);
          }
  
          if ($courses = $DB->get_records('course', array('category' => $this->id), 'sortorder ASC')) {
              foreach ($courses as $course) {
                  if (!delete_course($course, false)) {
                      throw new moodle_exception('cannotdeletecategorycourse', '', '', $course->shortname);
                  }
                  $deletedcourses[] = $course;
              }
          }
  
          // Move or delete cohorts in this context.
          cohort_delete_category($this);
  
          // Now delete anything that may depend on course category context.
          grade_course_category_delete($this->id, 0, $showfeedback);
          if (!question_delete_course_category($this, 0, $showfeedback)) {
              throw new moodle_exception('cannotdeletecategoryquestions', '', '', $this->get_formatted_name());
          }
  
          // Delete all events in the category.
          $DB->delete_records('event', array('categoryid' => $this->id));
  
          // Finally delete the category and it's context.
          $DB->delete_records('course_categories', array('id' => $this->id));
  
          $coursecatcontext = context_coursecat::instance($this->id);
          $coursecatcontext->delete();
  
          cache_helper::purge_by_event('changesincoursecat');
  
          // Trigger a course category deleted event.
          /** @var \core\event\course_category_deleted $event */
          $event = \core\event\course_category_deleted::create(array(
              'objectid' => $this->id,
              'context' => $coursecatcontext,
              'other' => array('name' => $this->name)
          ));
          $event->set_coursecat($this);
          $event->trigger();
  
          // If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
          if ($this->id == $CFG->defaultrequestcategory) {
              set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent' => 0)));
          }
          return $deletedcourses;
      }
code: public function delete_full($showfeedback = true) {
          global $CFG, $DB;
  
          require_once($CFG->libdir.'/gradelib.php');
          require_once($CFG->libdir.'/questionlib.php');
          require_once($CFG->dirroot.'/cohort/lib.php');
  
          // Make sure we won't timeout when deleting a lot of courses.
          $settimeout = core_php_time_limit::raise();
  
          // Allow plugins to use this category before we completely delete it.
          if ($pluginsfunction = get_plugins_with_function('pre_course_category_delete')) {
              $category = $this->get_db_record();
              foreach ($pluginsfunction as $plugintype => $plugins) {
                  foreach ($plugins as $pluginfunction) {
                      $pluginfunction($category);
                  }
              }
          }
  
          $deletedcourses = array();
  
          // Get children. Note, we don't want to use cache here because it would be rebuilt too often.
          $children = $DB->get_records('course_categories', array('parent' => $this->id), 'sortorder ASC');
          foreach ($children as $record) {
              $coursecat = new self($record);
              $deletedcourses += $coursecat->delete_full($showfeedback);
          }
  
          if ($courses = $DB->get_records('course', array('category' => $this->id), 'sortorder ASC')) {
              foreach ($courses as $course) {
                  if (!delete_course($course, false)) {
                      throw new moodle_exception('cannotdeletecategorycourse', '', '', $course->shortname);
                  }
                  $deletedcourses[] = $course;
              }
          }
  
          // Move or delete cohorts in this context.
          cohort_delete_category($this);
  
          // Now delete anything that may depend on course category context.
          grade_course_category_delete($this->id, 0, $showfeedback);
          if (!question_delete_course_category($this, 0, $showfeedback)) {
              throw new moodle_exception('cannotdeletecategoryquestions', '', '', $this->get_formatted_name());
          }
  
          // Delete all events in the category.
          $DB->delete_records('event', array('categoryid' => $this->id));
  
          // Finally delete the category and it's context.
          $DB->delete_records('course_categories', array('id' => $this->id));
  
          $coursecatcontext = context_coursecat::instance($this->id);
          $coursecatcontext->delete();
  
          cache_helper::purge_by_event('changesincoursecat');
  
          // Trigger a course category deleted event.
          /** @var \core\event\course_category_deleted $event */
          $event = \core\event\course_category_deleted::create(array(
              'objectid' => $this->id,
              'context' => $coursecatcontext,
              'other' => array('name' => $this->name)
          ));
          $event->set_coursecat($this);
          $event->trigger();
  
          // If we deleted $CFG->defaultrequestcategory, make it point somewhere else.
          if ($this->id == $CFG->defaultrequestcategory) {
              set_config('defaultrequestcategory', $DB->get_field('course_categories', 'MIN(id)', array('parent' => 0)));
          }
          return $deletedcourses;
      }
code_tokens: public function delete_full ( $ showfeedback = true ) { global $ CFG , $ DB ; require_once ( $ CFG -> libdir . '/gradelib.php' ) ; require_once ( $ CFG -> libdir . '/questionlib.php' ) ; require_once ( $ CFG -> dirroot . '/cohort/lib.php' ) ; // Make sure we won't timeout when deleting a lot of courses. $ settimeout = core_php_time_limit :: raise ( ) ; // Allow plugins to use this category before we completely delete it. if ( $ pluginsfunction = get_plugins_with_function ( 'pre_course_category_delete' ) ) { $ category = $ this -> get_db_record ( ) ; foreach ( $ pluginsfunction as $ plugintype => $ plugins ) { foreach ( $ plugins as $ pluginfunction ) { $ pluginfunction ( $ category ) ; } } } $ deletedcourses = array ( ) ; // Get children. Note, we don't want to use cache here because it would be rebuilt too often. $ children = $ DB -> get_records ( 'course_categories' , array ( 'parent' => $ this -> id ) , 'sortorder ASC' ) ; foreach ( $ children as $ record ) { $ coursecat = new self ( $ record ) ; $ deletedcourses += $ coursecat -> delete_full ( $ showfeedback ) ; } if ( $ courses = $ DB -> get_records ( 'course' , array ( 'category' => $ this -> id ) , 'sortorder ASC' ) ) { foreach ( $ courses as $ course ) { if ( ! delete_course ( $ course , false ) ) { throw new moodle_exception ( 'cannotdeletecategorycourse' , '' , '' , $ course -> shortname ) ; } $ deletedcourses [ ] = $ course ; } } // Move or delete cohorts in this context. cohort_delete_category ( $ this ) ; // Now delete anything that may depend on course category context. grade_course_category_delete ( $ this -> id , 0 , $ showfeedback ) ; if ( ! question_delete_course_category ( $ this , 0 , $ showfeedback ) ) { throw new moodle_exception ( 'cannotdeletecategoryquestions' , '' , '' , $ this -> get_formatted_name ( ) ) ; } // Delete all events in the category. $ DB -> delete_records ( 'event' , array ( 'categoryid' => $ this -> id ) ) ; // Finally delete the category and it's context. $ DB -> delete_records ( 'course_categories' , array ( 'id' => $ this -> id ) ) ; $ coursecatcontext = context_coursecat :: instance ( $ this -> id ) ; $ coursecatcontext -> delete ( ) ; cache_helper :: purge_by_event ( 'changesincoursecat' ) ; // Trigger a course category deleted event. /** @var \core\event\course_category_deleted $event */ $ event = \ core \ event \ course_category_deleted :: create ( array ( 'objectid' => $ this -> id , 'context' => $ coursecatcontext , 'other' => array ( 'name' => $ this -> name ) ) ) ; $ event -> set_coursecat ( $ this ) ; $ event -> trigger ( ) ; // If we deleted $CFG->defaultrequestcategory, make it point somewhere else. if ( $ this -> id == $ CFG -> defaultrequestcategory ) { set_config ( 'defaultrequestcategory' , $ DB -> get_field ( 'course_categories' , 'MIN(id)' , array ( 'parent' => 0 ) ) ) ; } return $ deletedcourses ; }
docstring: Recursively delete category including all subcategories and courses
  
  Function {@link core_course_category::can_delete_full()} MUST be called prior
  to calling this function because there is no capability check
  inside this function
  
  @param boolean $showfeedback display some notices
  @return array return deleted courses
  @throws moodle_exception
docstring_tokens: Recursively delete category including all subcategories and courses