original_string: public function store_item($course) {
          global $CFG, $DB;
  
          require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  
          // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage
          // setting (storing backups @ real location. For recycle bin we want to ensure that
          // backup files are always stored in Moodle file area. In order to achieve that, we
          // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other
          // operations.  See MDL-65218 for more information.
          // This hack will be removed once recycle bin switches to use its own backup mode, with
          // own preferences and 100% appart from MODLE_AUTOMATED.
          // TODO: Remove this as part of MDL-65228.
          $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0];
  
          // Backup the course.
          $user = get_admin();
          $controller = new \backup_controller(
              \backup::TYPE_1COURSE,
              $course->id,
              \backup::FORMAT_MOODLE,
              \backup::INTERACTIVE_NO,
              \backup::MODE_AUTOMATED,
              $user->id
          );
          $controller->execute_plan();
  
          // We don't need the forced setting anymore, hence unsetting it.
          // TODO: Remove this as part of MDL-65228.
          unset($CFG->forced_plugin_settings['backup']);
  
          // Grab the result.
          $result = $controller->get_results();
          if (!isset($result['backup_destination'])) {
              throw new \moodle_exception('Failed to backup activity prior to deletion.');
          }
  
          // Have finished with the controller, let's destroy it, freeing mem and resources.
          $controller->destroy();
  
          // Grab the filename.
          $file = $result['backup_destination'];
          if (!$file->get_contenthash()) {
              throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).');
          }
  
          // Record the activity, get an ID.
          $item = new \stdClass();
          $item->categoryid = $course->category;
          $item->shortname = $course->shortname;
          $item->fullname = $course->fullname;
          $item->timecreated = time();
          $binid = $DB->insert_record('tool_recyclebin_category', $item);
  
          // Create the location we want to copy this file to.
          $filerecord = array(
              'contextid' => \context_coursecat::instance($course->category)->id,
              'component' => 'tool_recyclebin',
              'filearea' => TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA,
              'itemid' => $binid,
              'timemodified' => time()
          );
  
          // Move the file to our own special little place.
          $fs = get_file_storage();
          if (!$fs->create_file_from_storedfile($filerecord, $file)) {
              // Failed, cleanup first.
              $DB->delete_records('tool_recyclebin_category', array(
                  'id' => $binid
              ));
  
              throw new \moodle_exception("Failed to copy backup file to recyclebin.");
          }
  
          // Delete the old file.
          $file->delete();
  
          // Fire event.
          $event = \tool_recyclebin\event\category_bin_item_created::create(array(
              'objectid' => $binid,
              'context' => \context_coursecat::instance($course->category)
          ));
          $event->trigger();
      }
code: public function store_item($course) {
          global $CFG, $DB;
  
          require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
  
          // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage
          // setting (storing backups @ real location. For recycle bin we want to ensure that
          // backup files are always stored in Moodle file area. In order to achieve that, we
          // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other
          // operations.  See MDL-65218 for more information.
          // This hack will be removed once recycle bin switches to use its own backup mode, with
          // own preferences and 100% appart from MODLE_AUTOMATED.
          // TODO: Remove this as part of MDL-65228.
          $CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0];
  
          // Backup the course.
          $user = get_admin();
          $controller = new \backup_controller(
              \backup::TYPE_1COURSE,
              $course->id,
              \backup::FORMAT_MOODLE,
              \backup::INTERACTIVE_NO,
              \backup::MODE_AUTOMATED,
              $user->id
          );
          $controller->execute_plan();
  
          // We don't need the forced setting anymore, hence unsetting it.
          // TODO: Remove this as part of MDL-65228.
          unset($CFG->forced_plugin_settings['backup']);
  
          // Grab the result.
          $result = $controller->get_results();
          if (!isset($result['backup_destination'])) {
              throw new \moodle_exception('Failed to backup activity prior to deletion.');
          }
  
          // Have finished with the controller, let's destroy it, freeing mem and resources.
          $controller->destroy();
  
          // Grab the filename.
          $file = $result['backup_destination'];
          if (!$file->get_contenthash()) {
              throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).');
          }
  
          // Record the activity, get an ID.
          $item = new \stdClass();
          $item->categoryid = $course->category;
          $item->shortname = $course->shortname;
          $item->fullname = $course->fullname;
          $item->timecreated = time();
          $binid = $DB->insert_record('tool_recyclebin_category', $item);
  
          // Create the location we want to copy this file to.
          $filerecord = array(
              'contextid' => \context_coursecat::instance($course->category)->id,
              'component' => 'tool_recyclebin',
              'filearea' => TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA,
              'itemid' => $binid,
              'timemodified' => time()
          );
  
          // Move the file to our own special little place.
          $fs = get_file_storage();
          if (!$fs->create_file_from_storedfile($filerecord, $file)) {
              // Failed, cleanup first.
              $DB->delete_records('tool_recyclebin_category', array(
                  'id' => $binid
              ));
  
              throw new \moodle_exception("Failed to copy backup file to recyclebin.");
          }
  
          // Delete the old file.
          $file->delete();
  
          // Fire event.
          $event = \tool_recyclebin\event\category_bin_item_created::create(array(
              'objectid' => $binid,
              'context' => \context_coursecat::instance($course->category)
          ));
          $event->trigger();
      }
code_tokens: public function store_item ( $ course ) { global $ CFG , $ DB ; require_once ( $ CFG -> dirroot . '/backup/util/includes/backup_includes.php' ) ; // As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage // setting (storing backups @ real location. For recycle bin we want to ensure that // backup files are always stored in Moodle file area. In order to achieve that, we // hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other // operations.  See MDL-65218 for more information. // This hack will be removed once recycle bin switches to use its own backup mode, with // own preferences and 100% appart from MODLE_AUTOMATED. // TODO: Remove this as part of MDL-65228. $ CFG -> forced_plugin_settings [ 'backup' ] = [ 'backup_auto_storage' => 0 ] ; // Backup the course. $ user = get_admin ( ) ; $ controller = new \ backup_controller ( \ backup :: TYPE_1COURSE , $ course -> id , \ backup :: FORMAT_MOODLE , \ backup :: INTERACTIVE_NO , \ backup :: MODE_AUTOMATED , $ user -> id ) ; $ controller -> execute_plan ( ) ; // We don't need the forced setting anymore, hence unsetting it. // TODO: Remove this as part of MDL-65228. unset ( $ CFG -> forced_plugin_settings [ 'backup' ] ) ; // Grab the result. $ result = $ controller -> get_results ( ) ; if ( ! isset ( $ result [ 'backup_destination' ] ) ) { throw new \ moodle_exception ( 'Failed to backup activity prior to deletion.' ) ; } // Have finished with the controller, let's destroy it, freeing mem and resources. $ controller -> destroy ( ) ; // Grab the filename. $ file = $ result [ 'backup_destination' ] ; if ( ! $ file -> get_contenthash ( ) ) { throw new \ moodle_exception ( 'Failed to backup activity prior to deletion (invalid file).' ) ; } // Record the activity, get an ID. $ item = new \ stdClass ( ) ; $ item -> categoryid = $ course -> category ; $ item -> shortname = $ course -> shortname ; $ item -> fullname = $ course -> fullname ; $ item -> timecreated = time ( ) ; $ binid = $ DB -> insert_record ( 'tool_recyclebin_category' , $ item ) ; // Create the location we want to copy this file to. $ filerecord = array ( 'contextid' => \ context_coursecat :: instance ( $ course -> category ) -> id , 'component' => 'tool_recyclebin' , 'filearea' => TOOL_RECYCLEBIN_COURSECAT_BIN_FILEAREA , 'itemid' => $ binid , 'timemodified' => time ( ) ) ; // Move the file to our own special little place. $ fs = get_file_storage ( ) ; if ( ! $ fs -> create_file_from_storedfile ( $ filerecord , $ file ) ) { // Failed, cleanup first. $ DB -> delete_records ( 'tool_recyclebin_category' , array ( 'id' => $ binid ) ) ; throw new \ moodle_exception ( "Failed to copy backup file to recyclebin." ) ; } // Delete the old file. $ file -> delete ( ) ; // Fire event. $ event = \ tool_recyclebin \ event \ category_bin_item_created :: create ( array ( 'objectid' => $ binid , 'context' => \ context_coursecat :: instance ( $ course -> category ) ) ) ; $ event -> trigger ( ) ; }
docstring: Store a course in the recycle bin.
  
  @param \stdClass $course Course
  @throws \moodle_exception
docstring_tokens: Store a course in the recycle bin .