original_string: protected function queue_user_tasks() {
          global $CFG, $DB;
  
          $timenow = time();
          $sitetimezone = \core_date::get_server_timezone();
          $counts = [
              'digests' => 0,
              'individuals' => 0,
              'users' => 0,
              'ignored' => 0,
              'messages' => 0,
          ];
          $this->log("Processing " . count($this->users) . " users", 1);
          foreach ($this->users as $user) {
              $usercounts = [
                  'digests' => 0,
                  'messages' => 0,
              ];
  
              $send = false;
              // Setup this user so that the capabilities are cached, and environment matches receiving user.
              cron_setup_user($user);
  
              list($individualpostdata, $digestpostdata) = $this->fetch_posts_for_user($user);
  
              if (!empty($digestpostdata)) {
                  // Insert all of the records for the digest.
                  $DB->insert_records('forum_queue', $digestpostdata);
                  $digesttime = usergetmidnight($timenow, $sitetimezone) + ($CFG->digestmailtime * 3600);
  
                  $task = new \mod_forum\task\send_user_digests();
                  $task->set_userid($user->id);
                  $task->set_component('mod_forum');
                  $task->set_next_run_time($digesttime);
                  \core\task\manager::reschedule_or_queue_adhoc_task($task);
                  $usercounts['digests']++;
                  $send = true;
              }
  
              if (!empty($individualpostdata)) {
                  $usercounts['messages'] += count($individualpostdata);
  
                  $task = new \mod_forum\task\send_user_notifications();
                  $task->set_userid($user->id);
                  $task->set_custom_data($individualpostdata);
                  $task->set_component('mod_forum');
                  \core\task\manager::queue_adhoc_task($task);
                  $counts['individuals']++;
                  $send = true;
              }
  
              if ($send) {
                  $counts['users']++;
                  $counts['messages'] += $usercounts['messages'];
                  $counts['digests'] += $usercounts['digests'];
              } else {
                  $counts['ignored']++;
              }
  
              $this->log(sprintf("Queued %d digests and %d messages for %s",
                      $usercounts['digests'],
                      $usercounts['messages'],
                      $user->id
                  ), 2);
          }
          $this->log(
              sprintf(
                  "Queued %d digests, and %d individual tasks for %d post mails. " .
                  "Unique users: %d (%d ignored)",
                  $counts['digests'],
                  $counts['individuals'],
                  $counts['messages'],
                  $counts['users'],
                  $counts['ignored']
              ), 1);
      }
code: protected function queue_user_tasks() {
          global $CFG, $DB;
  
          $timenow = time();
          $sitetimezone = \core_date::get_server_timezone();
          $counts = [
              'digests' => 0,
              'individuals' => 0,
              'users' => 0,
              'ignored' => 0,
              'messages' => 0,
          ];
          $this->log("Processing " . count($this->users) . " users", 1);
          foreach ($this->users as $user) {
              $usercounts = [
                  'digests' => 0,
                  'messages' => 0,
              ];
  
              $send = false;
              // Setup this user so that the capabilities are cached, and environment matches receiving user.
              cron_setup_user($user);
  
              list($individualpostdata, $digestpostdata) = $this->fetch_posts_for_user($user);
  
              if (!empty($digestpostdata)) {
                  // Insert all of the records for the digest.
                  $DB->insert_records('forum_queue', $digestpostdata);
                  $digesttime = usergetmidnight($timenow, $sitetimezone) + ($CFG->digestmailtime * 3600);
  
                  $task = new \mod_forum\task\send_user_digests();
                  $task->set_userid($user->id);
                  $task->set_component('mod_forum');
                  $task->set_next_run_time($digesttime);
                  \core\task\manager::reschedule_or_queue_adhoc_task($task);
                  $usercounts['digests']++;
                  $send = true;
              }
  
              if (!empty($individualpostdata)) {
                  $usercounts['messages'] += count($individualpostdata);
  
                  $task = new \mod_forum\task\send_user_notifications();
                  $task->set_userid($user->id);
                  $task->set_custom_data($individualpostdata);
                  $task->set_component('mod_forum');
                  \core\task\manager::queue_adhoc_task($task);
                  $counts['individuals']++;
                  $send = true;
              }
  
              if ($send) {
                  $counts['users']++;
                  $counts['messages'] += $usercounts['messages'];
                  $counts['digests'] += $usercounts['digests'];
              } else {
                  $counts['ignored']++;
              }
  
              $this->log(sprintf("Queued %d digests and %d messages for %s",
                      $usercounts['digests'],
                      $usercounts['messages'],
                      $user->id
                  ), 2);
          }
          $this->log(
              sprintf(
                  "Queued %d digests, and %d individual tasks for %d post mails. " .
                  "Unique users: %d (%d ignored)",
                  $counts['digests'],
                  $counts['individuals'],
                  $counts['messages'],
                  $counts['users'],
                  $counts['ignored']
              ), 1);
      }
code_tokens: protected function queue_user_tasks ( ) { global $ CFG , $ DB ; $ timenow = time ( ) ; $ sitetimezone = \ core_date :: get_server_timezone ( ) ; $ counts = [ 'digests' => 0 , 'individuals' => 0 , 'users' => 0 , 'ignored' => 0 , 'messages' => 0 , ] ; $ this -> log ( "Processing " . count ( $ this -> users ) . " users" , 1 ) ; foreach ( $ this -> users as $ user ) { $ usercounts = [ 'digests' => 0 , 'messages' => 0 , ] ; $ send = false ; // Setup this user so that the capabilities are cached, and environment matches receiving user. cron_setup_user ( $ user ) ; list ( $ individualpostdata , $ digestpostdata ) = $ this -> fetch_posts_for_user ( $ user ) ; if ( ! empty ( $ digestpostdata ) ) { // Insert all of the records for the digest. $ DB -> insert_records ( 'forum_queue' , $ digestpostdata ) ; $ digesttime = usergetmidnight ( $ timenow , $ sitetimezone ) + ( $ CFG -> digestmailtime * 3600 ) ; $ task = new \ mod_forum \ task \ send_user_digests ( ) ; $ task -> set_userid ( $ user -> id ) ; $ task -> set_component ( 'mod_forum' ) ; $ task -> set_next_run_time ( $ digesttime ) ; \ core \ task \ manager :: reschedule_or_queue_adhoc_task ( $ task ) ; $ usercounts [ 'digests' ] ++ ; $ send = true ; } if ( ! empty ( $ individualpostdata ) ) { $ usercounts [ 'messages' ] += count ( $ individualpostdata ) ; $ task = new \ mod_forum \ task \ send_user_notifications ( ) ; $ task -> set_userid ( $ user -> id ) ; $ task -> set_custom_data ( $ individualpostdata ) ; $ task -> set_component ( 'mod_forum' ) ; \ core \ task \ manager :: queue_adhoc_task ( $ task ) ; $ counts [ 'individuals' ] ++ ; $ send = true ; } if ( $ send ) { $ counts [ 'users' ] ++ ; $ counts [ 'messages' ] += $ usercounts [ 'messages' ] ; $ counts [ 'digests' ] += $ usercounts [ 'digests' ] ; } else { $ counts [ 'ignored' ] ++ ; } $ this -> log ( sprintf ( "Queued %d digests and %d messages for %s" , $ usercounts [ 'digests' ] , $ usercounts [ 'messages' ] , $ user -> id ) , 2 ) ; } $ this -> log ( sprintf ( "Queued %d digests, and %d individual tasks for %d post mails. " . "Unique users: %d (%d ignored)" , $ counts [ 'digests' ] , $ counts [ 'individuals' ] , $ counts [ 'messages' ] , $ counts [ 'users' ] , $ counts [ 'ignored' ] ) , 1 ) ; }
docstring: Queue the user tasks.
docstring_tokens: Queue the user tasks .