You are here

function background_process_set_process in Background Process 8

Same name and namespace in other branches
  1. 6 background_process.module \background_process_set_process()
  2. 7 background_process.module \background_process_set_process()

Implements to Set background process.

2 calls to background_process_set_process()
BackgroundProcess::execute in ./background_process.class.php
Implements Execute Process.
BackgroundProcess::queue in ./background_process.class.php
Implements Queues.

File

./background_process.module, line 557
This module implements a framework for calling funtions in the background.

Code

function background_process_set_process($handle, $callback, $uid, $args, $token) {

  // Setup parameters.
  $args = serialize($args);
  $callback = serialize($callback);

  // Get user.
  if (!isset($uid)) {
    $user = \Drupal::currentUser();
    $uid = $user->uid;
    if ($uid == '') {
      $uid = '0';
    }
  }
  try {
    $old_db = Database::setActiveConnection('background_process');
    $result = db_update('background_process')
      ->fields([
      'callback' => $callback,
      'args' => $args,
      'uid' => $uid,
      'token' => $token,
    ])
      ->condition('handle', $handle)
      ->execute();
    Database::setActiveConnection($old_db);
    return $result;
  } catch (Exception $e) {
    Database::setActiveConnection($old_db);
    throw $e;
  }
}