Upsert.php in Zircon Profile 8
File
core/lib/Drupal/Core/Database/Driver/mysql/Upsert.php
View source
<?php
namespace Drupal\Core\Database\Driver\mysql;
use Drupal\Core\Database\Query\Upsert as QueryUpsert;
class Upsert extends QueryUpsert {
public function __toString() {
$comments = $this->connection
->makeComment($this->comments);
$insert_fields = array_merge($this->defaultFields, $this->insertFields);
$query = $comments . 'INSERT INTO {' . $this->table . '} (' . implode(', ', $insert_fields) . ') VALUES ';
$values = $this
->getInsertPlaceholderFragment($this->insertValues, $this->defaultFields);
$query .= implode(', ', $values);
unset($insert_fields[$this->key]);
$update = [];
foreach ($insert_fields as $field) {
$update[] = "{$field} = VALUES({$field})";
}
$query .= ' ON DUPLICATE KEY UPDATE ' . implode(', ', $update);
return $query;
}
}