1.20.x config_database_storage.inc public ConfigDatabaseStorage::write($name, array $data)

Writes configuration data to the storage.

Parameters

string $name: The name of a configuration object to save.

array $data: The configuration data to write.

Return value

bool: TRUE on success, FALSE in case of an error.

Overrides ConfigStorageInterface::write

File

drivers/config_database/config_database_storage.inc, line 203

Class

ConfigDatabaseStorage
Defines the database storage controller.

Code

public function write($name, array $data) {
  // Ensure that the config name is included in the written file.
  $data = array_merge(array('_config_name' => $name), $data);
  $data = $this->encode($data) . "\n";
  $file_path = $this->getFilePath($name);
  try {
    $result = db_merge($this->table, array('target' => $this->database))
      ->key(array('name' => $name))
      ->fields(array(
        'name' => $name,
        'data' => $data,
      ))
      ->execute();
    if ($result == MergeQuery::STATUS_INSERT) {
      db_update($this->table, array('target' => $this->database))
        ->fields(array('ctime' => time()))
        ->condition('name', $name)
        ->condition('ctime', 0)
        ->execute();
    }
  }
  catch (\Exception $e) {
    throw new ConfigStorageException('Failed to write configuration file: ' . $this->getFilePath($name), 0, $e);
  }
  return TRUE;
}