Skip to content

Commit

Permalink
#10 Update Drupal to 7.89
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hunt committed May 5, 2022
1 parent 8eb03f7 commit 781b787
Show file tree
Hide file tree
Showing 167 changed files with 784 additions and 441 deletions.
5 changes: 5 additions & 0 deletions docroot/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Drupal 7.89, 2022-03-02
-----------------------
- Bug fixes for PHP 8.1
- Fix tests for PostgreSQL

Drupal 7.88, 2022-02-15
-----------------------
- Fixed security issues:
Expand Down
4 changes: 2 additions & 2 deletions docroot/includes/bootstrap.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* The current system version.
*/
define('VERSION', '7.88');
define('VERSION', '7.89');

/**
* Core API compatibility.
Expand Down Expand Up @@ -1905,7 +1905,7 @@ function format_string($string, array $args = array()) {
* @ingroup sanitization
*/
function check_plain($text) {
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
return htmlspecialchars((string) $text, ENT_QUOTES, 'UTF-8');
}

/**
Expand Down
3 changes: 2 additions & 1 deletion docroot/includes/database/pgsql/database.inc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
case Database::RETURN_AFFECTED:
return $stmt->rowCount();
case Database::RETURN_INSERT_ID:
return $this->connection->lastInsertId($options['sequence_name']);
$sequence_name = isset($options['sequence_name']) ? $options['sequence_name'] : NULL;
return $this->connection->lastInsertId($sequence_name);
case Database::RETURN_NULL:
return;
default:
Expand Down
4 changes: 2 additions & 2 deletions docroot/includes/database/pgsql/query.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class InsertQuery_pgsql extends InsertQuery {
foreach ($this->insertFields as $idx => $field) {
if (isset($table_information->blob_fields[$field])) {
$blobs[$blob_count] = fopen('php://memory', 'a');
fwrite($blobs[$blob_count], $insert_values[$idx]);
fwrite($blobs[$blob_count], (string) $insert_values[$idx]);
rewind($blobs[$blob_count]);

$stmt->bindParam(':db_insert_placeholder_' . $max_placeholder++, $blobs[$blob_count], PDO::PARAM_LOB);
Expand Down Expand Up @@ -182,7 +182,7 @@ class UpdateQuery_pgsql extends UpdateQuery {

if (isset($table_information->blob_fields[$field])) {
$blobs[$blob_count] = fopen('php://memory', 'a');
fwrite($blobs[$blob_count], $value);
fwrite($blobs[$blob_count], (string) $value);
rewind($blobs[$blob_count]);
$stmt->bindParam($placeholder, $blobs[$blob_count], PDO::PARAM_LOB);
++$blob_count;
Expand Down
148 changes: 135 additions & 13 deletions docroot/includes/database/pgsql/schema.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,64 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
*/
protected $tableInformation = array();

/**
* The maximum allowed length for index, primary key and constraint names.
*
* Value will usually be set to a 63 chars limit but PostgreSQL allows
* to higher this value before compiling, so we need to check for that.
*
* @var int
*/
protected $maxIdentifierLength;

/**
* Make sure to limit identifiers according to PostgreSQL compiled in length.
*
* PostgreSQL allows in standard configuration identifiers no longer than 63
* chars for table/relation names, indexes, primary keys, and constraints. So
* we map all identifiers that are too long to drupal_base64hash_tag, where
* tag is one of:
* - idx for indexes
* - key for constraints
* - pkey for primary keys
* - seq for sequences
*
* @param string $table_identifier_part
* The first argument used to build the identifier string. This usually
* refers to a table/relation name.
* @param string $column_identifier_part
* The second argument used to build the identifier string. This usually
* refers to one or more column names.
* @param string $tag
* The identifier tag. It can be one of 'idx', 'key', 'pkey' or 'seq'.
*
* @return string
* The index/constraint/pkey identifier.
*/
protected function ensureIdentifiersLength($table_identifier_part, $column_identifier_part, $tag) {
$info = $this->getPrefixInfo($table_identifier_part);
$table_identifier_part = $info['table'];

// Filters out potentially empty $column_identifier_part to ensure
// compatibility with old naming convention (see prefixNonTable()).
$identifiers = array_filter(array($table_identifier_part, $column_identifier_part, $tag));
$identifierName = implode('_', $identifiers);

// Retrieve the max identifier length which is usually 63 characters
// but can be altered before PostgreSQL is compiled so we need to check.
if (empty($this->maxIdentifierLength)) {
$this->maxIdentifierLength = $this->connection->query("SHOW max_identifier_length")->fetchField();
}

if (strlen($identifierName) > $this->maxIdentifierLength) {
$saveIdentifier = 'drupal_' . $this->hashBase64($identifierName) . '_' . $tag;
}
else {
$saveIdentifier = $identifierName;
}
return $saveIdentifier;
}

/**
* Fetch the list of blobs and sequences used on a table.
*
Expand Down Expand Up @@ -124,11 +182,11 @@ class DatabaseSchema_pgsql extends DatabaseSchema {

$sql_keys = array();
if (isset($table['primary key']) && is_array($table['primary key'])) {
$sql_keys[] = 'PRIMARY KEY (' . implode(', ', $table['primary key']) . ')';
$sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name, '', 'pkey') . ' PRIMARY KEY (' . implode(', ', $table['primary key']) . ')';
}
if (isset($table['unique keys']) && is_array($table['unique keys'])) {
foreach ($table['unique keys'] as $key_name => $key) {
$sql_keys[] = 'CONSTRAINT ' . $this->prefixNonTable($name, $key_name, 'key') . ' UNIQUE (' . implode(', ', $key) . ')';
$sql_keys[] = 'CONSTRAINT ' . $this->ensureIdentifiersLength($name, $key_name, 'key') . ' UNIQUE (' . implode(', ', $key) . ')';
}
}

Expand Down Expand Up @@ -328,10 +386,31 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
// rename them when renaming the table.
$indexes = $this->connection->query('SELECT indexname FROM pg_indexes WHERE schemaname = :schema AND tablename = :table', array(':schema' => $old_schema, ':table' => $old_table_name));
foreach ($indexes as $index) {
if (preg_match('/^' . preg_quote($old_full_name) . '_(.*)$/', $index->indexname, $matches)) {
// Get the index type by suffix, e.g. idx/key/pkey
$index_type = substr($index->indexname, strrpos($index->indexname, '_') + 1);

// If the index is already rewritten by ensureIdentifiersLength() to not
// exceed the 63 chars limit of PostgreSQL, we need to take care of that.
// Example (drupal_Gk7Su_T1jcBHVuvSPeP22_I3Ni4GrVEgTYlIYnBJkro_idx).
if (strpos($index->indexname, 'drupal_') !== FALSE) {
preg_match('/^drupal_(.*)_' . preg_quote($index_type) . '/', $index->indexname, $matches);
$index_name = $matches[1];
$this->connection->query('ALTER INDEX ' . $index->indexname . ' RENAME TO {' . $new_name . '}_' . $index_name);
}
else {
if ($index_type == 'pkey') {
// Primary keys do not have a specific name in D7.
$index_name = '';
}
else {
// Make sure to remove the suffix from index names, because
// ensureIdentifiersLength() will add the suffix again and thus
// would result in a wrong index name.
preg_match('/^' . preg_quote($old_full_name) . '_(.*)_' . preg_quote($index_type) . '/', $index->indexname, $matches);
$index_name = $matches[1];
}
}

$this->connection->query('ALTER INDEX ' . $index->indexname . ' RENAME TO ' . $this->ensureIdentifiersLength($new_name, $index_name, $index_type));
}

// Now rename the table.
Expand Down Expand Up @@ -415,8 +494,8 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
}

public function indexExists($table, $name) {
// Details http://www.postgresql.org/docs/8.3/interactive/view-pg-indexes.html
$index_name = '{' . $table . '}_' . $name . '_idx';
// Details https://www.postgresql.org/docs/10/view-pg-indexes.html
$index_name = $this->ensureIdentifiersLength($table, $name, 'idx');
return (bool) $this->connection->query("SELECT 1 FROM pg_indexes WHERE indexname = '$index_name'")->fetchField();
}

Expand All @@ -429,7 +508,18 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
* The name of the constraint (typically 'pkey' or '[constraint]_key').
*/
protected function constraintExists($table, $name) {
$constraint_name = '{' . $table . '}_' . $name;
// ensureIdentifiersLength() expects three parameters, thus we split our
// constraint name in a proper name and a suffix.
if ($name == 'pkey') {
$suffix = $name;
$name = '';
}
else {
$pos = strrpos($name, '_');
$suffix = substr($name, $pos + 1);
$name = substr($name, 0, $pos);
}
$constraint_name = $this->ensureIdentifiersLength($table, $name, $suffix);
return (bool) $this->connection->query("SELECT 1 FROM pg_constraint WHERE conname = '$constraint_name'")->fetchField();
}

Expand All @@ -441,15 +531,15 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
throw new DatabaseSchemaObjectExistsException(t("Cannot add primary key to table @table: primary key already exists.", array('@table' => $table)));
}

$this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')');
$this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT ' . $this->ensureIdentifiersLength($table, '', 'pkey') . ' PRIMARY KEY (' . implode(',', $fields) . ')');
}

public function dropPrimaryKey($table) {
if (!$this->constraintExists($table, 'pkey')) {
return FALSE;
}

$this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT ' . $this->prefixNonTable($table, 'pkey'));
$this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT ' . $this->ensureIdentifiersLength($table, '', 'pkey'));
return TRUE;
}

Expand All @@ -461,15 +551,15 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
throw new DatabaseSchemaObjectExistsException(t("Cannot add unique key @name to table @table: unique key already exists.", array('@table' => $table, '@name' => $name)));
}

$this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT "' . $this->prefixNonTable($table, $name, 'key') . '" UNIQUE (' . implode(',', $fields) . ')');
$this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT "' . $this->ensureIdentifiersLength($table, $name, 'key') . '" UNIQUE (' . implode(',', $fields) . ')');
}

public function dropUniqueKey($table, $name) {
if (!$this->constraintExists($table, $name . '_key')) {
return FALSE;
}

$this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $this->prefixNonTable($table, $name, 'key') . '"');
$this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $this->ensureIdentifiersLength($table, $name, 'key') . '"');
return TRUE;
}

Expand All @@ -489,7 +579,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
return FALSE;
}

$this->connection->query('DROP INDEX ' . $this->prefixNonTable($table, $name, 'idx'));
$this->connection->query('DROP INDEX ' . $this->ensureIdentifiersLength($table, $name, 'idx'));
return TRUE;
}

Expand Down Expand Up @@ -580,7 +670,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
}

protected function _createIndexSql($table, $name, $fields) {
$query = 'CREATE INDEX "' . $this->prefixNonTable($table, $name, 'idx') . '" ON {' . $table . '} (';
$query = 'CREATE INDEX "' . $this->ensureIdentifiersLength($table, $name, 'idx') . '" ON {' . $table . '} (';
$query .= $this->_createKeySql($fields) . ')';
return $query;
}
Expand Down Expand Up @@ -614,4 +704,36 @@ class DatabaseSchema_pgsql extends DatabaseSchema {
return $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $info['table']))->fetchField();
}
}

/**
* Calculates a base-64 encoded, PostgreSQL-safe sha-256 hash per PostgreSQL
* documentation: 4.1. Lexical Structure.
*
* @param $data
* String to be hashed.
*
* @return string
* A base-64 encoded sha-256 hash, with + and / replaced with _ and any =
* padding characters removed.
*/
protected function hashBase64($data) {
// Ensure lowercase as D7's pgsql driver does not quote identifiers
// consistently, and they are therefore folded to lowercase by PostgreSQL.
$hash = strtolower(base64_encode(hash('sha256', $data, TRUE)));
// Modify the hash so it's safe to use in PostgreSQL identifiers.
return strtr($hash, array('+' => '_', '/' => '_', '=' => ''));
}

/**
* Build a condition to match a table name against a standard information_schema.
*
* In PostgreSQL "unquoted names are always folded to lower case." The pgsql
* driver does not quote table names, so they are therefore always lowercase.
*
* @see https://www.postgresql.org/docs/14/sql-syntax-lexical.html
*/
protected function buildTableNameCondition($table_name, $operator = '=', $add_prefix = TRUE) {
return parent::buildTableNameCondition(strtolower($table_name), $operator, $add_prefix);
}

}
6 changes: 3 additions & 3 deletions docroot/modules/aggregator/aggregator.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ files[] = aggregator.test
configure = admin/config/services/aggregator/settings
stylesheets[all][] = aggregator.css

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/aggregator/tests/aggregator_test.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/block/block.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ core = 7.x
files[] = block.test
configure = admin/structure/block

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/block/tests/block_test.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = VERSION
core = 7.x
hidden = TRUE

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ regions[footer] = Footer
regions[highlighted] = Highlighted
regions[help] = Help

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/blog/blog.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = VERSION
core = 7.x
files[] = blog.test

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/book/book.info
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ files[] = book.test
configure = admin/content/book/settings
stylesheets[all][] = book.css

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/color/color.info
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = VERSION
core = 7.x
files[] = color.test

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/comment/comment.info
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ files[] = comment.test
configure = admin/content/comment
stylesheets[all][] = comment.css

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
6 changes: 3 additions & 3 deletions docroot/modules/contact/contact.info
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ core = 7.x
files[] = contact.test
configure = admin/structure/contact

; Information added by Drupal.org packaging script on 2022-02-16
version = "7.88"
; Information added by Drupal.org packaging script on 2022-03-02
version = "7.89"
project = "drupal"
datestamp = "1645030312"
datestamp = "1646219151"
Loading

0 comments on commit 781b787

Please sign in to comment.