class ContentDatabaseStorage in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/Content/ContentDatabaseStorage.php \Drupal\content_sync\Content\ContentDatabaseStorage
Defines the Database storage.
Hierarchy
- class \Drupal\Core\Config\DatabaseStorage implements StorageInterface uses DependencySerializationTrait
- class \Drupal\content_sync\Content\ContentDatabaseStorage
Expanded class hierarchy of ContentDatabaseStorage
3 files declare their use of ContentDatabaseStorage
- ContentExportTrait.php in src/
Form/ ContentExportTrait.php - content_sync.module in ./
content_sync.module - Allows site administrators to modify content.
- ExportQueueResolver.php in src/
DependencyResolver/ ExportQueueResolver.php
File
- src/
Content/ ContentDatabaseStorage.php, line 11
Namespace
Drupal\content_sync\ContentView source
class ContentDatabaseStorage extends DatabaseStorage {
/**
* {@inheritdoc}
*/
public function cs_write($name, array $data, $collection) {
$data = $this
->encode($data);
try {
return $this
->cs_doWrite($name, $data, $collection);
} catch (\Exception $e) {
// If there was an exception, try to create the table.
if ($this
->ensureTableExists()) {
return $this
->cs_doWrite($name, $data, $collection);
}
// Some other failure that we can not recover from.
throw $e;
}
}
/**
* Helper method so we can re-try a write.
*
* @param string $name
* The content name.
* @param string $data
* The content data, already dumped to a string.
* @param string $collection
* The content collection name, entity type + bundle.
*
* @return bool
*/
protected function cs_doWrite($name, $data, $collection) {
$options = [
'return' => Database::RETURN_AFFECTED,
] + $this->options;
$this->connection
->delete($this->table, $options)
->condition('name', $name)
->execute();
return (bool) $this->connection
->merge($this->table, $options)
->keys([
'collection',
'name',
], [
$collection,
$name,
])
->fields([
'data' => $data,
])
->execute();
}
/**
* {@inheritdoc}
*/
public function cs_read($name) {
$data = FALSE;
try {
$raw = $this->connection
->query('SELECT data FROM {' . $this->connection
->escapeTable($this->table) . '} WHERE name = :name', [
':name' => $name,
], $this->options)
->fetchField();
if ($raw !== FALSE) {
$data = $this
->decode($raw);
}
} catch (\Exception $e) {
// If we attempt a read without actually having the database or the table
// available, just return FALSE so the caller can handle it.
}
return $data;
}
/**
* Implements Drupal\Core\Config\StorageInterface::delete().
*
* @throws PDOException
*
* @todo Ignore replica targets for data manipulation operations.
*/
public function cs_delete($name) {
$options = [
'return' => Database::RETURN_AFFECTED,
] + $this->options;
return (bool) $this->connection
->delete($this->table, $options)
->condition('name', $name)
->execute();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentDatabaseStorage:: |
public | function | Implements Drupal\Core\Config\StorageInterface::delete(). | |
ContentDatabaseStorage:: |
protected | function | Helper method so we can re-try a write. | |
ContentDatabaseStorage:: |
public | function | ||
ContentDatabaseStorage:: |
public | function | ||
DatabaseStorage:: |
protected | property | The storage collection. | |
DatabaseStorage:: |
protected | property | The database connection. | |
DatabaseStorage:: |
protected | property | Additional database connection options to use in queries. | |
DatabaseStorage:: |
protected | property | The database table name. | |
DatabaseStorage:: |
public | function |
Creates a collection on the storage. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Implements Drupal\Core\Config\StorageInterface::decode(). Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Implements Drupal\Core\Config\StorageInterface::delete(). Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Deletes configuration objects whose names start with a given prefix. Overrides StorageInterface:: |
|
DatabaseStorage:: |
protected | function | Helper method so we can re-try a write. | |
DatabaseStorage:: |
public | function |
Encodes configuration data into the storage-specific format. Overrides StorageInterface:: |
|
DatabaseStorage:: |
protected | function | Check if the config table exists and create it if not. | |
DatabaseStorage:: |
public | function |
Returns whether a configuration object exists. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Gets the existing collections. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Gets the name of the current collection the storage is using. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Gets configuration object names starting with a given prefix. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Reads configuration data from the storage. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Reads configuration data from the storage. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function |
Implements Drupal\Core\Config\StorageInterface::rename(). Overrides StorageInterface:: |
|
DatabaseStorage:: |
protected static | function | Defines the schema for the configuration table. | |
DatabaseStorage:: |
public | function |
Writes configuration data to the storage. Overrides StorageInterface:: |
|
DatabaseStorage:: |
public | function | Constructs a new DatabaseStorage. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
StorageInterface:: |
constant | The default collection name. |