original_string: public static function queue_adhoc_task(adhoc_task $task, $checkforexisting = false) {
          global $DB;
  
          if ($userid = $task->get_userid()) {
              // User found. Check that they are suitable.
              \core_user::require_active_user(\core_user::get_user($userid, '*', MUST_EXIST), true, true);
          }
  
          $record = self::record_from_adhoc_task($task);
          // Schedule it immediately if nextruntime not explicitly set.
          if (!$task->get_next_run_time()) {
              $record->nextruntime = time() - 1;
          }
  
          // Check if the same task is already scheduled.
          if ($checkforexisting && self::task_is_scheduled($task)) {
              return false;
          }
  
          // Queue the task.
          $result = $DB->insert_record('task_adhoc', $record);
  
          return $result;
      }
code: public static function queue_adhoc_task(adhoc_task $task, $checkforexisting = false) {
          global $DB;
  
          if ($userid = $task->get_userid()) {
              // User found. Check that they are suitable.
              \core_user::require_active_user(\core_user::get_user($userid, '*', MUST_EXIST), true, true);
          }
  
          $record = self::record_from_adhoc_task($task);
          // Schedule it immediately if nextruntime not explicitly set.
          if (!$task->get_next_run_time()) {
              $record->nextruntime = time() - 1;
          }
  
          // Check if the same task is already scheduled.
          if ($checkforexisting && self::task_is_scheduled($task)) {
              return false;
          }
  
          // Queue the task.
          $result = $DB->insert_record('task_adhoc', $record);
  
          return $result;
      }
code_tokens: public static function queue_adhoc_task ( adhoc_task $ task , $ checkforexisting = false ) { global $ DB ; if ( $ userid = $ task -> get_userid ( ) ) { // User found. Check that they are suitable. \ core_user :: require_active_user ( \ core_user :: get_user ( $ userid , '*' , MUST_EXIST ) , true , true ) ; } $ record = self :: record_from_adhoc_task ( $ task ) ; // Schedule it immediately if nextruntime not explicitly set. if ( ! $ task -> get_next_run_time ( ) ) { $ record -> nextruntime = time ( ) - 1 ; } // Check if the same task is already scheduled. if ( $ checkforexisting && self :: task_is_scheduled ( $ task ) ) { return false ; } // Queue the task. $ result = $ DB -> insert_record ( 'task_adhoc' , $ record ) ; return $ result ; }
docstring: Queue an adhoc task to run in the background.
  
  @param \core\task\adhoc_task $task - The new adhoc task information to store.
  @param bool $checkforexisting - If set to true and the task with the same user, classname, component and customdata
  is already scheduled then it will not schedule a new task. Can be used only for ASAP tasks.
  @return boolean - True if the config was saved.
docstring_tokens: Queue an adhoc task to run in the background .