class BatchStorage

Hierarchy

Expanded class hierarchy of BatchStorage

1 string reference to 'BatchStorage'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses BatchStorage

File

drupal/core/lib/Drupal/Core/Utility/BatchStorage.php, line 12
Contains \Drupal\Core\Utility\BatchStorage.

Namespace

Drupal\Core\Utility
View source
class BatchStorage implements BatchStorageInterface {

  /**
   * @var \Drupal\Core\Database\Connection
   */
  protected $connection;
  public function __construct(Connection $connection) {
    $this->connection = $connection;
  }

  /**
   * {@inheritdoc}
   */
  public function load($id) {
    $batch = $this->connection
      ->query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
      ':bid' => $id,
      ':token' => drupal_get_token($id),
    ))
      ->fetchField();
    if ($batch) {
      return unserialize($batch);
    }
    return FALSE;
  }

  /**
   * {@inheritdoc}
   */
  public function delete($id) {
    $this->connection
      ->delete('batch')
      ->condition('bid', $id)
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  public function update(array $batch) {
    $this->connection
      ->update('batch')
      ->fields(array(
      'batch' => serialize($batch),
    ))
      ->condition('bid', $batch['id'])
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  public function cleanup() {

    // Cleanup the batch table and the queue for failed batches.
    $this->connection
      ->delete('batch')
      ->condition('timestamp', REQUEST_TIME - 864000, '<')
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  function create(array $batch) {
    $this->connection
      ->insert('batch')
      ->fields(array(
      'bid' => $batch['id'],
      'timestamp' => REQUEST_TIME,
      'token' => drupal_get_token($batch['id']),
      'batch' => serialize($batch),
    ))
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BatchStorage::$connection protected property
BatchStorage::cleanup public function Cleans up failed or old batches. Overrides BatchStorageInterface::cleanup
BatchStorage::create function Creates and saves a batch. Overrides BatchStorageInterface::create
BatchStorage::delete public function Loads a batch. Overrides BatchStorageInterface::delete
BatchStorage::load public function Loads a batch. Overrides BatchStorageInterface::load
BatchStorage::update public function Updates a batch. Overrides BatchStorageInterface::update
BatchStorage::__construct public function