Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -1,18 +1,19 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Batch\BatchStorage.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Batch;
|
||||
|
||||
use Drupal\Core\Database\Connection;
|
||||
use Drupal\Core\Database\SchemaObjectExistsException;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Drupal\Core\Access\CsrfTokenGenerator;
|
||||
|
||||
class BatchStorage implements BatchStorageInterface {
|
||||
|
||||
/**
|
||||
* The table name.
|
||||
*/
|
||||
const TABLE_NAME = 'batch';
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
|
@ -56,10 +57,16 @@ class BatchStorage implements BatchStorageInterface {
|
|||
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();
|
||||
try {
|
||||
$batch = $this->connection->query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
|
||||
':bid' => $id,
|
||||
':token' => $this->csrfToken->get($id),
|
||||
))->fetchField();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->catchException($e);
|
||||
$batch = FALSE;
|
||||
}
|
||||
if ($batch) {
|
||||
return unserialize($batch);
|
||||
}
|
||||
|
@ -70,29 +77,44 @@ class BatchStorage implements BatchStorageInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($id) {
|
||||
$this->connection->delete('batch')
|
||||
->condition('bid', $id)
|
||||
->execute();
|
||||
try {
|
||||
$this->connection->delete('batch')
|
||||
->condition('bid', $id)
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->catchException($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update(array $batch) {
|
||||
$this->connection->update('batch')
|
||||
->fields(array('batch' => serialize($batch)))
|
||||
->condition('bid', $batch['id'])
|
||||
->execute();
|
||||
try {
|
||||
$this->connection->update('batch')
|
||||
->fields(array('batch' => serialize($batch)))
|
||||
->condition('bid', $batch['id'])
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->catchException($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function cleanup() {
|
||||
// Cleanup the batch table and the queue for failed batches.
|
||||
$this->connection->delete('batch')
|
||||
->condition('timestamp', REQUEST_TIME - 864000, '<')
|
||||
->execute();
|
||||
try {
|
||||
// Cleanup the batch table and the queue for failed batches.
|
||||
$this->connection->delete('batch')
|
||||
->condition('timestamp', REQUEST_TIME - 864000, '<')
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->catchException($e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,6 +123,32 @@ class BatchStorage implements BatchStorageInterface {
|
|||
public function create(array $batch) {
|
||||
// Ensure that a session is started before using the CSRF token generator.
|
||||
$this->session->start();
|
||||
$try_again = FALSE;
|
||||
try {
|
||||
// The batch table might not yet exist.
|
||||
$this->doCreate($batch);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// If there was an exception, try to create the table.
|
||||
if (!$try_again = $this->ensureTableExists()) {
|
||||
// If the exception happened for other reason than the missing table,
|
||||
// propagate the exception.
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
// Now that the table has been created, try again if necessary.
|
||||
if ($try_again) {
|
||||
$this->doCreate($batch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a batch.
|
||||
*
|
||||
* @param array $batch
|
||||
* The array representing the batch to create.
|
||||
*/
|
||||
protected function doCreate(array $batch) {
|
||||
$this->connection->insert('batch')
|
||||
->fields(array(
|
||||
'bid' => $batch['id'],
|
||||
|
@ -111,4 +159,83 @@ class BatchStorage implements BatchStorageInterface {
|
|||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the table exists and create it if not.
|
||||
*/
|
||||
protected function ensureTableExists() {
|
||||
try {
|
||||
$database_schema = $this->connection->schema();
|
||||
if (!$database_schema->tableExists(static::TABLE_NAME)) {
|
||||
$schema_definition = $this->schemaDefinition();
|
||||
$database_schema->createTable(static::TABLE_NAME, $schema_definition);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
// If another process has already created the batch table, attempting to
|
||||
// recreate it will throw an exception. In this case just catch the
|
||||
// exception and do nothing.
|
||||
catch (SchemaObjectExistsException $e) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Act on an exception when batch might be stale.
|
||||
*
|
||||
* If the table does not yet exist, that's fine, but if the table exists and
|
||||
* yet the query failed, then the batch is stale and the exception needs to
|
||||
* propagate.
|
||||
*
|
||||
* @param $e
|
||||
* The exception.
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function catchException(\Exception $e) {
|
||||
if ($this->connection->schema()->tableExists(static::TABLE_NAME)) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the schema for the batch table.
|
||||
*/
|
||||
public function schemaDefinition() {
|
||||
return [
|
||||
'description' => 'Stores details about batches (processes that run in multiple HTTP requests).',
|
||||
'fields' => [
|
||||
'bid' => [
|
||||
'description' => 'Primary Key: Unique batch ID.',
|
||||
// This is not a serial column, to allow both progressive and
|
||||
// non-progressive batches. See batch_process().
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
],
|
||||
'token' => [
|
||||
'description' => "A string token generated against the current user's session id and the batch id, used to ensure that only the user who submitted the batch can effectively access it.",
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 64,
|
||||
'not null' => TRUE,
|
||||
],
|
||||
'timestamp' => [
|
||||
'description' => 'A Unix timestamp indicating when this batch was submitted for processing. Stale batches are purged at cron time.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
],
|
||||
'batch' => [
|
||||
'description' => 'A serialized array containing the processing data for the batch.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
],
|
||||
],
|
||||
'primary key' => ['bid'],
|
||||
'indexes' => [
|
||||
'token' => ['token'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Batch\BatchStorageInterface.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Batch;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Core\Batch\Percentage.
|
||||
*/
|
||||
|
||||
namespace Drupal\Core\Batch;
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue