ContentDatabaseStorage.php in Content Synchronization 8.2
File
src/Content/ContentDatabaseStorage.php
View source
<?php
namespace Drupal\content_sync\Content;
use Drupal\Core\Config\DatabaseStorage;
use Drupal\Core\Database\Database;
class ContentDatabaseStorage extends DatabaseStorage {
public function cs_write($name, array $data, $collection) {
$data = $this
->encode($data);
try {
return $this
->cs_doWrite($name, $data, $collection);
} catch (\Exception $e) {
if ($this
->ensureTableExists()) {
return $this
->cs_doWrite($name, $data, $collection);
}
throw $e;
}
}
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();
}
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) {
}
return $data;
}
public function cs_delete($name) {
$options = [
'return' => Database::RETURN_AFFECTED,
] + $this->options;
return (bool) $this->connection
->delete($this->table, $options)
->condition('name', $name)
->execute();
}
}