Commit 4638a004 authored by Dries's avatar Dries

Issue #2194897 by sun: Rename Database\Query\Merge::key() to keys(), retain a BC alias for key().

parent 1b23600f
......@@ -208,7 +208,7 @@ function _drupal_session_write($sid, $value) {
}
db_merge('sessions')
->key($key)
->keys($key)
->fields($fields)
->execute();
}
......
......@@ -196,7 +196,7 @@ protected function doSet($cid, $data, $expire, $tags) {
}
$this->connection->merge($this->bin)
->key(array('cid' => $cid))
->key('cid', $cid)
->fields($fields)
->execute();
}
......@@ -248,7 +248,7 @@ public function deleteTags(array $tags) {
$this->connection->merge('cache_tags')
->insertFields(array('deletions' => 1))
->expression('deletions', 'deletions + 1')
->key(array('tag' => $tag))
->key('tag', $tag)
->execute();
}
catch (\Exception $e) {
......@@ -317,7 +317,7 @@ public function invalidateTags(array $tags) {
$this->connection->merge('cache_tags')
->insertFields(array('invalidations' => 1))
->expression('invalidations', 'invalidations + 1')
->key(array('tag' => $tag))
->key('tag', $tag)
->execute();
}
}
......
......@@ -116,7 +116,7 @@ public function write($name, array $data) {
$data = $this->encode($data);
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
return (bool) $this->connection->merge($this->table, $options)
->key(array('name' => $name))
->key('name', $name)
->fields(array('data' => $data))
->execute();
}
......
......@@ -282,7 +282,7 @@ public function fields(array $fields, array $values = array()) {
}
/**
* Sets the key field(s) to be used as conditions for this query.
* Sets the key fields to be used as conditions for this query.
*
* This method should only be called once. It may be called either
* with a single associative array or two indexed arrays. If called
......@@ -300,10 +300,9 @@ public function fields(array $fields, array $values = array()) {
* An array of values to set into the database. The values must be
* specified in the same order as the $fields array.
*
* @return \Drupal\Core\Database\Query\Merge
* The called object.
* @return $this
*/
public function key(array $fields, array $values = array()) {
public function keys(array $fields, array $values = array()) {
if ($values) {
$fields = array_combine($fields, $values);
}
......@@ -314,6 +313,32 @@ public function key(array $fields, array $values = array()) {
return $this;
}
/**
* Sets a single key field to be used as condition for this query.
*
* Same as \Drupal\Core\Database\Query\Merge::keys() but offering a signature
* that is more natural for the case of a single key.
*
* @param string $field
* The name of the field to set.
* @param mixed $value
* The value to set into the database.
*
* @return $this
*
* @see \Drupal\Core\Database\Query\Merge::keys()
*/
public function key($field, $value = NULL) {
// @todo D9: Remove this backwards-compatibility shim.
if (is_array($field)) {
$this->keys($field, isset($value) ? $value : array());
}
else {
$this->keys(array($field => $value));
}
return $this;
}
/**
* Implements Drupal\Core\Database\Query\ConditionInterface::condition().
*/
......
......@@ -87,7 +87,7 @@ public function getAll() {
*/
public function set($key, $value) {
$this->connection->merge($this->table)
->key(array(
->keys(array(
'name' => $key,
'collection' => $this->collection,
))
......
......@@ -91,7 +91,7 @@ function setWithExpire($key, $value, $expire) {
// the end of this request.
$this->needsGarbageCollection = TRUE;
$this->connection->merge($this->table)
->key(array(
->keys(array(
'name' => $key,
'collection' => $this->collection,
))
......
......@@ -83,7 +83,7 @@ public function updateEntityStatistics(CommentInterface $comment) {
'last_comment_name' => $last_reply->uid ? '' : $last_reply->name,
'last_comment_uid' => $last_reply->uid,
))
->key(array(
->keys(array(
'entity_id' => $comment->getCommentedEntityId(),
'entity_type' => $comment->getCommentedEntityTypeId(),
'field_id' => $comment->getFieldId(),
......
......@@ -50,7 +50,7 @@ public function __construct(Connection $connection, $table = 'file_usage') {
*/
public function add(File $file, $module, $type, $id, $count = 1) {
$this->connection->merge($this->tableName)
->key(array(
->keys(array(
'fid' => $file->id(),
'module' => $module,
'type' => $type,
......
......@@ -107,7 +107,7 @@ function history_write($nid, $account = NULL) {
if ($account->isAuthenticated()) {
db_merge('history')
->key(array(
->keys(array(
'uid' => $account->id(),
'nid' => $nid,
))
......
......@@ -155,7 +155,7 @@ protected function updateLocation($string) {
elseif ($lid === TRUE) {
// This is a new location to add, take care not to duplicate.
$this->connection->merge('locales_location', $this->options)
->key(array('sid' => $string->getId(), 'type' => $type, 'name' => $name))
->keys(array('sid' => $string->getId(), 'type' => $type, 'name' => $name))
->fields(array('version' => \Drupal::VERSION))
->execute();
$created = TRUE;
......@@ -506,7 +506,7 @@ protected function dbStringUpdate($string) {
}
if (!empty($values) && $keys = $this->dbStringKeys($string)) {
return $this->connection->merge($this->dbStringTable($string), $this->options)
->key($keys)
->keys($keys)
->fields($values)
->execute();
}
......
......@@ -103,7 +103,7 @@ function locale_translation_build_projects() {
// Create or update the project record.
db_merge('locale_project')
->key(array('name' => $project->name))
->key('name', $project->name)
->fields(array(
'name' => $project->name,
'project_type' => $project->project_type,
......
......@@ -431,7 +431,7 @@ public function saveIdMapping(Row $row, array $destination_id_values, $source_ro
}
if ($keys) {
$this->getDatabase()->merge($this->mapTableName)
->key($keys)
->keys($keys)
->fields($fields)
->execute();
}
......
......@@ -144,7 +144,7 @@ function node_access_test_node_update(NodeInterface $node) {
*/
function _node_access_test_node_write(NodeInterface $node) {
db_merge('node_access_test')
->key(array('nid' => $node->id()))
->key('nid', $node->id())
->fields(array('private' => (int) $node->private->value))
->execute();
}
......
......@@ -249,7 +249,7 @@ function search_update_totals() {
// Apply Zipf's law to equalize the probability distribution.
$total = log10(1 + 1/(max(1, $total)));
db_merge('search_total')
->key(array('word' => $word))
->key('word', $word)
->fields(array('count' => $total))
->execute();
}
......@@ -532,7 +532,7 @@ function search_index($sid, $type, $text, $langcode) {
// appropriately. If not, we create a new record with the appropriate
// starting score.
db_merge('search_index')
->key(array(
->keys(array(
'word' => $word,
'sid' => $sid,
'langcode' => $langcode,
......
......@@ -30,7 +30,7 @@ public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) {
*/
public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
db_merge('shortcut_set_users')
->key(array('uid' => $account->id()))
->key('uid', $account->id())
->fields(array('set_name' => $shortcut_set->id()))
->execute();
drupal_static_reset('shortcut_current_displayed_set');
......
......@@ -17,7 +17,7 @@
$nid = filter_input(INPUT_POST, 'nid', FILTER_VALIDATE_INT);
if ($nid) {
\Drupal::database()->merge('node_counter')
->key(array('nid' => $nid))
->key('nid', $nid)
->fields(array(
'daycount' => 1,
'totalcount' => 1,
......
......@@ -30,7 +30,7 @@ function testMergeInsert() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$result = db_merge('test_people')
->key(array('job' => 'Presenter'))
->key('job', 'Presenter')
->fields(array(
'age' => 31,
'name' => 'Tiffany',
......@@ -55,7 +55,7 @@ function testMergeUpdate() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
$result = db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->fields(array(
'age' => 31,
'name' => 'Tiffany',
......@@ -83,7 +83,7 @@ function testMergeUpdateExcept() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->insertFields(array('age' => 31))
->updateFields(array('name' => 'Tiffany'))
->execute();
......@@ -104,7 +104,7 @@ function testMergeUpdateExplicit() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->insertFields(array(
'age' => 31,
'name' => 'Tiffany',
......@@ -137,7 +137,7 @@ function testMergeUpdateExpression() {
// once as an expression. This test will only pass if the expression wins,
// which is what is supposed to happen.
db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->fields(array('name' => 'Tiffany'))
->insertFields(array('age' => 31))
->expression('age', 'age + :age', array(':age' => 4))
......@@ -159,7 +159,7 @@ function testMergeInsertWithoutUpdate() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
db_merge('test_people')
->key(array('job' => 'Presenter'))
->key('job', 'Presenter')
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
......@@ -178,7 +178,7 @@ function testMergeUpdateWithoutUpdate() {
$num_records_before = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->execute();
$num_records_after = db_query('SELECT COUNT(*) FROM {test_people}')->fetchField();
......@@ -190,7 +190,7 @@ function testMergeUpdateWithoutUpdate() {
$this->assertEqual($person->job, 'Speaker', 'Job skipped correctly.');
db_merge('test_people')
->key(array('job' => 'Speaker'))
->key('job', 'Speaker')
->insertFields(array('age' => 31))
->execute();
......
......@@ -52,7 +52,7 @@ public function testGarbageCollection() {
// Manually expire the data.
for ($i = 0; $i <= 3; $i++) {
db_merge('key_value_expire')
->key(array(
->keys(array(
'name' => 'key_' . $i,
'collection' => $collection,
))
......
......@@ -12,46 +12,46 @@
// Update system settings to known values.
db_merge('variable')
->key(array('name' => 'node_cron_views_scale'))
->keys(array('name' => 'node_cron_views_scale'))
->fields(array('value' => serialize(1.0 / 2000)))
->execute();
db_merge('variable')
->key(array('name' => 'statistics_day_timestamp'))
->keys(array('name' => 'statistics_day_timestamp'))
->fields(array('value' => serialize(1352070595)))
->execute();
db_merge('variable')
->key(array('name' => 'tracker_index_nid'))
->keys(array('name' => 'tracker_index_nid'))
->fields(array('value' => serialize(0)))
->execute();
db_merge('variable')
->key(array('name' => 'update_last_check'))
->keys(array('name' => 'update_last_check'))
->fields(array('value' => serialize(1304208000)))
->execute();
db_merge('variable')
->key(array('name' => 'update_last_email_notification'))
->keys(array('name' => 'update_last_email_notification'))
->fields(array('value' => serialize(1304208000)))
->execute();
db_merge('variable')
->key(array('name' => 'node_access_needs_rebuild'))
->keys(array('name' => 'node_access_needs_rebuild'))
->fields(array('value' => serialize(TRUE)))
->execute();
db_merge('variable')
->key(array('name' => 'node_cron_last'))
->keys(array('name' => 'node_cron_last'))
->fields(array('value' => serialize(1304208001)))
->execute();
db_merge('variable')
->key(array('name' => 'cron_last'))
->keys(array('name' => 'cron_last'))
->fields(array('value' => serialize(1304208002)))
->execute();
db_merge('variable')
->key(array('name' => 'cron_key'))
->keys(array('name' => 'cron_key'))
->fields(array('value' => serialize('kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M')))
->execute();
db_merge('variable')
->key(array('name' => 'drupal_private_key'))
->keys(array('name' => 'drupal_private_key'))
->fields(array('value' => serialize('G38mKqASKus8VGMkMzVuXImYbzspCQ1iRT2iEZpMYmQ')))
->execute();
db_merge('variable')
->key(array('name' => 'node_cron_comments_scale'))
->keys(array('name' => 'node_cron_comments_scale'))
->fields(array('value' => serialize(1.0 / 1000)))
->execute();
......@@ -262,7 +262,7 @@ function _tracker_add($nid, $uid, $changed) {
// Update the node-level data.
db_merge('tracker_node')
->key(array('nid' => $nid))
->key('nid', $nid)
->fields(array(
'changed' => $changed,
'published' => $node->status,
......@@ -271,7 +271,7 @@ function _tracker_add($nid, $uid, $changed) {
// Create or update the user-level data.
db_merge('tracker_user')
->key(array(
->keys(array(
'nid' => $nid,
'uid' => $uid,
))
......
......@@ -89,7 +89,7 @@ public function set($module, $uid, $name, $value) {
$serialized = 1;
}
$this->connection->merge('users_data')
->key(array(
->keys(array(
'uid' => $uid,
'module' => $module,
'name' => $name,
......
......@@ -422,7 +422,7 @@ function hook_user_role_insert($role) {
function hook_user_role_update($role) {
// Save extra fields provided by the module to user roles.
db_merge('my_module_table')
->key(array('rid' => $role->id()))
->key('rid', $role->id())
->fields(array(
'role_description' => $role->description
))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment