function StringDatabaseStorage::dbStringUpdate

Same name and namespace in other branches
  1. 9 core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringUpdate()
  2. 8.9.x core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringUpdate()
  3. 10 core/modules/locale/src/StringDatabaseStorage.php \Drupal\locale\StringDatabaseStorage::dbStringUpdate()

Updates string object in the database.

Parameters

\Drupal\locale\StringInterface $string: The string object.

Return value

bool|int If the record update failed, returns FALSE. If it succeeded, returns SAVED_NEW or SAVED_UPDATED.

Throws

\Drupal\locale\StringStorageException If the string is not suitable for this storage, an exception is thrown.

1 call to StringDatabaseStorage::dbStringUpdate()
StringDatabaseStorage::save in core/modules/locale/src/StringDatabaseStorage.php

File

core/modules/locale/src/StringDatabaseStorage.php, line 497

Class

StringDatabaseStorage
Defines a class to store localized strings in the database.

Namespace

Drupal\locale

Code

protected function dbStringUpdate($string) {
    if ($string->isSource()) {
        $values = $string->getValues([
            'source',
            'context',
            'version',
        ]);
    }
    elseif ($string->isTranslation()) {
        $values = $string->getValues([
            'translation',
            'customized',
        ]);
    }
    if (!empty($values) && ($keys = $this->dbStringKeys($string))) {
        return $this->connection
            ->merge($this->dbStringTable($string), $this->options)
            ->keys($keys)
            ->fields($values)
            ->execute();
    }
    else {
        throw new StringStorageException('The string cannot be updated: ' . $string->getString());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.