Skip to content
Snippets Groups Projects
Select Git revision
  • 1cf3a5338b438845d02a8c7f57d9431060da23a9
  • 11.x default protected
  • 10.6.x protected
  • 10.5.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

BatchStorage.php

Blame
  • Alex Pott's avatar
    Issue #2293541 by amitgoyal, marcingy: Remove *_token deprecated functions.
    Alex Pott authored
    1cf3a533
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    BatchStorage.php 1.63 KiB
    <?php
    
    /**
     * @file
     * Contains \Drupal\Core\Batch\BatchStorage.
     */
    
    namespace Drupal\Core\Batch;
    
    use Drupal\Core\Database\Connection;
    
    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::csrfToken()->get($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::csrfToken()->get($batch['id']),
            'batch' => serialize($batch),
          ))
          ->execute();
      }
    }