original_string: public function execute() {
          global $CFG;
          require_once($CFG->dirroot. '/course/lib.php');
  
          // Set the proper user.
          if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
              $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST);
              cron_setup_user($realuser);
              \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
          } else {
              $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST);
              cron_setup_user($user);
          }
  
          $cms = $this->get_custom_data()->cms;
          foreach ($cms as $cm) {
              try {
                  course_delete_module($cm->id);
              } catch (\Exception $e) {
                  throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}");
              }
          }
      }
code: public function execute() {
          global $CFG;
          require_once($CFG->dirroot. '/course/lib.php');
  
          // Set the proper user.
          if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) {
              $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST);
              cron_setup_user($realuser);
              \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false);
          } else {
              $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST);
              cron_setup_user($user);
          }
  
          $cms = $this->get_custom_data()->cms;
          foreach ($cms as $cm) {
              try {
                  course_delete_module($cm->id);
              } catch (\Exception $e) {
                  throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}");
              }
          }
      }
code_tokens: public function execute ( ) { global $ CFG ; require_once ( $ CFG -> dirroot . '/course/lib.php' ) ; // Set the proper user. if ( $ this -> get_custom_data ( ) -> userid !== $ this -> get_custom_data ( ) -> realuserid ) { $ realuser = \ core_user :: get_user ( $ this -> get_custom_data ( ) -> realuserid , '*' , MUST_EXIST ) ; cron_setup_user ( $ realuser ) ; \ core \ session \ manager :: loginas ( $ this -> get_custom_data ( ) -> userid , \ context_system :: instance ( ) , false ) ; } else { $ user = \ core_user :: get_user ( $ this -> get_custom_data ( ) -> userid , '*' , MUST_EXIST ) ; cron_setup_user ( $ user ) ; } $ cms = $ this -> get_custom_data ( ) -> cms ; foreach ( $ cms as $ cm ) { try { course_delete_module ( $ cm -> id ) ; } catch ( \ Exception $ e ) { throw new \ coding_exception ( "The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}" ) ; } } }
docstring: Run the deletion task.
  
  @throws \coding_exception if the module could not be removed.
docstring_tokens: Run the deletion task .