class BatchStorage in Zircon Profile 8
Same name in this branch
- 8 core/lib/Drupal/Core/Batch/BatchStorage.php \Drupal\Core\Batch\BatchStorage
- 8 core/lib/Drupal/Core/ProxyClass/Batch/BatchStorage.php \Drupal\Core\ProxyClass\Batch\BatchStorage
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Core/Batch/BatchStorage.php \Drupal\Core\Batch\BatchStorage
Hierarchy
- class \Drupal\Core\Batch\BatchStorage implements BatchStorageInterface
Expanded class hierarchy of BatchStorage
1 string reference to 'BatchStorage'
- core.services.yml in core/
core.services.yml - core/core.services.yml
1 service uses BatchStorage
File
- core/
lib/ Drupal/ Core/ Batch/ BatchStorage.php, line 14 - Contains \Drupal\Core\Batch\BatchStorage.
Namespace
Drupal\Core\BatchView source
class BatchStorage implements BatchStorageInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* The session.
*
* @var \Symfony\Component\HttpFoundation\Session\SessionInterface
*/
protected $session;
/**
* The CSRF token generator.
*
* @var \Drupal\Core\Access\CsrfTokenGenerator
*/
protected $csrfToken;
/**
* Constructs the database batch storage service.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection.
* @param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
* The session.
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
* The CSRF token generator.
*/
public function __construct(Connection $connection, SessionInterface $session, CsrfTokenGenerator $csrf_token) {
$this->connection = $connection;
$this->session = $session;
$this->csrfToken = $csrf_token;
}
/**
* {@inheritdoc}
*/
public function load($id) {
// Ensure that a session is started before using the CSRF token generator.
$this->session
->start();
$batch = $this->connection
->query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
':bid' => $id,
':token' => $this->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}
*/
public function create(array $batch) {
// Ensure that a session is started before using the CSRF token generator.
$this->session
->start();
$this->connection
->insert('batch')
->fields(array(
'bid' => $batch['id'],
'timestamp' => REQUEST_TIME,
'token' => $this->csrfToken
->get($batch['id']),
'batch' => serialize($batch),
))
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BatchStorage:: |
protected | property | The database connection. | |
BatchStorage:: |
protected | property | The CSRF token generator. | |
BatchStorage:: |
protected | property | The session. | |
BatchStorage:: |
public | function |
Cleans up failed or old batches. Overrides BatchStorageInterface:: |
|
BatchStorage:: |
public | function |
Creates and saves a batch. Overrides BatchStorageInterface:: |
|
BatchStorage:: |
public | function |
Deletes a batch. Overrides BatchStorageInterface:: |
|
BatchStorage:: |
public | function |
Loads a batch. Overrides BatchStorageInterface:: |
|
BatchStorage:: |
public | function |
Updates a batch. Overrides BatchStorageInterface:: |
|
BatchStorage:: |
public | function | Constructs the database batch storage service. |