From fdf6bf90f37a7efd7661538dede28342a2257115 Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Fri, 15 Sep 2017 23:32:45 -0500 Subject: [PATCH] Issue #2863750 by adriancid, tstoeckler: Add inheritdoc function doc comment to schema classes --- .../Core/Database/Driver/mysql/Schema.php | 51 +++++++++++++++++++ .../Core/Database/Driver/pgsql/Schema.php | 42 ++++++++++++++- .../Core/Database/Driver/sqlite/Schema.php | 48 ++++++++++++++++- 3 files changed, 137 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php index 1911d6a88116..878607c55dc1 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Schema.php @@ -226,6 +226,9 @@ protected function processField($field) { return $field; } + /** + * {@inheritdoc} + */ public function getFieldTypeMap() { // Put :normal last so it gets preserved by array_flip. This makes // it much easier for modules (such as schema.module) to map @@ -366,6 +369,9 @@ protected function createKeySql($fields) { return implode(', ', $return); } + /** + * {@inheritdoc} + */ public function renameTable($table, $new_name) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", ['@table' => $table, '@table_new' => $new_name])); @@ -378,6 +384,9 @@ public function renameTable($table, $new_name) { return $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO `' . $info['table'] . '`'); } + /** + * {@inheritdoc} + */ public function dropTable($table) { if (!$this->tableExists($table)) { return FALSE; @@ -387,6 +396,9 @@ public function dropTable($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function addField($table, $field, $spec, $keys_new = []) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", ['@field' => $field, '@table' => $table])); @@ -432,6 +444,9 @@ public function addField($table, $field, $spec, $keys_new = []) { } } + /** + * {@inheritdoc} + */ public function dropField($table, $field) { if (!$this->fieldExists($table, $field)) { return FALSE; @@ -441,6 +456,9 @@ public function dropField($table, $field) { return TRUE; } + /** + * {@inheritdoc} + */ public function fieldSetDefault($table, $field, $default) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); @@ -449,6 +467,9 @@ public function fieldSetDefault($table, $field, $default) { $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` SET DEFAULT ' . $this->escapeDefaultValue($default)); } + /** + * {@inheritdoc} + */ public function fieldSetNoDefault($table, $field) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot remove default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); @@ -457,6 +478,9 @@ public function fieldSetNoDefault($table, $field) { $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT'); } + /** + * {@inheritdoc} + */ public function indexExists($table, $name) { // Returns one row for each column in the index. Result is string or FALSE. // Details at http://dev.mysql.com/doc/refman/5.0/en/show-index.html @@ -464,6 +488,9 @@ public function indexExists($table, $name) { return isset($row['Key_name']); } + /** + * {@inheritdoc} + */ public function addPrimaryKey($table, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add primary key to table @table: table doesn't exist.", ['@table' => $table])); @@ -475,6 +502,9 @@ public function addPrimaryKey($table, $fields) { $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')'); } + /** + * {@inheritdoc} + */ public function dropPrimaryKey($table) { if (!$this->indexExists($table, 'PRIMARY')) { return FALSE; @@ -484,6 +514,9 @@ public function dropPrimaryKey($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function addUniqueKey($table, $name, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add unique key @name to table @table: table doesn't exist.", ['@table' => $table, '@name' => $name])); @@ -495,6 +528,9 @@ public function addUniqueKey($table, $name, $fields) { $this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')'); } + /** + * {@inheritdoc} + */ public function dropUniqueKey($table, $name) { if (!$this->indexExists($table, $name)) { return FALSE; @@ -521,6 +557,9 @@ public function addIndex($table, $name, $fields, array $spec) { $this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($indexes[$name]) . ')'); } + /** + * {@inheritdoc} + */ public function dropIndex($table, $name) { if (!$this->indexExists($table, $name)) { return FALSE; @@ -530,6 +569,9 @@ public function dropIndex($table, $name) { return TRUE; } + /** + * {@inheritdoc} + */ public function changeField($table, $field, $field_new, $spec, $keys_new = []) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", ['@table' => $table, '@name' => $field])); @@ -545,6 +587,9 @@ public function changeField($table, $field, $field_new, $spec, $keys_new = []) { $this->connection->query($sql); } + /** + * {@inheritdoc} + */ public function prepareComment($comment, $length = NULL) { // Truncate comment to maximum comment length. if (isset($length)) { @@ -574,6 +619,9 @@ public function getComment($table, $column = NULL) { return preg_replace('/; InnoDB free:.*$/', '', $comment); } + /** + * {@inheritdoc} + */ public function tableExists($table) { // The information_schema table is very slow to query under MySQL 5.0. // Instead, we try to select from the table in question. If it fails, @@ -591,6 +639,9 @@ public function tableExists($table) { } } + /** + * {@inheritdoc} + */ public function fieldExists($table, $column) { // The information_schema table is very slow to query under MySQL 5.0. // Instead, we try to select from the table and field in question. If it diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php index fcf9d0084d53..9e5e1d9f841c 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Schema.php @@ -383,8 +383,7 @@ protected function processField($field) { } /** - * This maps a generic data type in combination with its data size - * to the engine-specific data type. + * {@inheritdoc} */ public function getFieldTypeMap() { // Put :normal last so it gets preserved by array_flip. This makes @@ -471,6 +470,9 @@ public function tableExists($table) { return (bool) $this->connection->query("SELECT 1 FROM pg_tables WHERE schemaname = :schema AND tablename = :table", [':schema' => $prefixInfo['schema'], ':table' => $prefixInfo['table']])->fetchField(); } + /** + * {@inheritdoc} + */ public function renameTable($table, $new_name) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", ['@table' => $table, '@table_new' => $new_name])); @@ -525,6 +527,9 @@ public function renameTable($table, $new_name) { $this->resetTableInformation($table); } + /** + * {@inheritdoc} + */ public function dropTable($table) { if (!$this->tableExists($table)) { return FALSE; @@ -535,6 +540,9 @@ public function dropTable($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function addField($table, $field, $spec, $new_keys = []) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", ['@field' => $field, '@table' => $table])); @@ -583,6 +591,9 @@ public function addField($table, $field, $spec, $new_keys = []) { $this->resetTableInformation($table); } + /** + * {@inheritdoc} + */ public function dropField($table, $field) { if (!$this->fieldExists($table, $field)) { return FALSE; @@ -593,6 +604,9 @@ public function dropField($table, $field) { return TRUE; } + /** + * {@inheritdoc} + */ public function fieldSetDefault($table, $field, $default) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); @@ -603,6 +617,9 @@ public function fieldSetDefault($table, $field, $default) { $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" SET DEFAULT ' . $default); } + /** + * {@inheritdoc} + */ public function fieldSetNoDefault($table, $field) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot remove default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); @@ -611,6 +628,9 @@ public function fieldSetNoDefault($table, $field) { $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" DROP DEFAULT'); } + /** + * {@inheritdoc} + */ public function indexExists($table, $name) { // Details http://www.postgresql.org/docs/9.1/interactive/view-pg-indexes.html $index_name = $this->ensureIdentifiersLength($table, $name, 'idx'); @@ -651,6 +671,9 @@ public function constraintExists($table, $name) { return (bool) $this->connection->query("SELECT 1 FROM pg_constraint WHERE conname = '$constraint_name'")->fetchField(); } + /** + * {@inheritdoc} + */ public function addPrimaryKey($table, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add primary key to table @table: table doesn't exist.", ['@table' => $table])); @@ -663,6 +686,9 @@ public function addPrimaryKey($table, $fields) { $this->resetTableInformation($table); } + /** + * {@inheritdoc} + */ public function dropPrimaryKey($table) { if (!$this->constraintExists($table, 'pkey')) { return FALSE; @@ -673,6 +699,9 @@ public function dropPrimaryKey($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function addUniqueKey($table, $name, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add unique key @name to table @table: table doesn't exist.", ['@table' => $table, '@name' => $name])); @@ -685,6 +714,9 @@ public function addUniqueKey($table, $name, $fields) { $this->resetTableInformation($table); } + /** + * {@inheritdoc} + */ public function dropUniqueKey($table, $name) { if (!$this->constraintExists($table, $name . '__key')) { return FALSE; @@ -710,6 +742,9 @@ public function addIndex($table, $name, $fields, array $spec) { $this->resetTableInformation($table); } + /** + * {@inheritdoc} + */ public function dropIndex($table, $name) { if (!$this->indexExists($table, $name)) { return FALSE; @@ -720,6 +755,9 @@ public function dropIndex($table, $name) { return TRUE; } + /** + * {@inheritdoc} + */ public function changeField($table, $field, $field_new, $spec, $new_keys = []) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", ['@table' => $table, '@name' => $field])); diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php index 4399ddde94a4..27b6a58fbb6f 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php @@ -22,6 +22,9 @@ class Schema extends DatabaseSchema { */ protected $defaultSchema = 'main'; + /** + * {@inheritdoc} + */ public function tableExists($table) { $info = $this->getPrefixInfo($table); @@ -29,6 +32,9 @@ public function tableExists($table) { return (bool) $this->connection->query('SELECT 1 FROM ' . $info['schema'] . '.sqlite_master WHERE type = :type AND name = :name', [':type' => 'table', ':name' => $info['table']])->fetchField(); } + /** + * {@inheritdoc} + */ public function fieldExists($table, $column) { $schema = $this->introspectSchema($table); return !empty($schema['fields'][$column]); @@ -201,8 +207,7 @@ protected function createFieldSql($name, $spec) { } /** - * This maps a generic data type in combination with its data size - * to the engine-specific data type. + * {@inheritdoc} */ public function getFieldTypeMap() { // Put :normal last so it gets preserved by array_flip. This makes @@ -247,6 +252,9 @@ public function getFieldTypeMap() { return $map; } + /** + * {@inheritdoc} + */ public function renameTable($table, $new_name) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot rename @table to @table_new: table @table doesn't exist.", ['@table' => $table, '@table_new' => $new_name])); @@ -284,6 +292,9 @@ public function renameTable($table, $new_name) { } } + /** + * {@inheritdoc} + */ public function dropTable($table) { if (!$this->tableExists($table)) { return FALSE; @@ -293,6 +304,9 @@ public function dropTable($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function addField($table, $field, $specification, $keys_new = []) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add field @table.@field: table doesn't exist.", ['@field' => $field, '@table' => $table])); @@ -500,6 +514,9 @@ protected function introspectSchema($table) { return $schema; } + /** + * {@inheritdoc} + */ public function dropField($table, $field) { if (!$this->fieldExists($table, $field)) { return FALSE; @@ -531,6 +548,9 @@ public function dropField($table, $field) { return TRUE; } + /** + * {@inheritdoc} + */ public function changeField($table, $field, $field_new, $spec, $keys_new = []) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot change the definition of field @table.@name: field doesn't exist.", ['@table' => $table, '@name' => $field])); @@ -614,12 +634,18 @@ public function addIndex($table, $name, $fields, array $spec) { } } + /** + * {@inheritdoc} + */ public function indexExists($table, $name) { $info = $this->getPrefixInfo($table); return $this->connection->query('PRAGMA ' . $info['schema'] . '.index_info(' . $info['table'] . '_' . $name . ')')->fetchField() != ''; } + /** + * {@inheritdoc} + */ public function dropIndex($table, $name) { if (!$this->indexExists($table, $name)) { return FALSE; @@ -631,6 +657,9 @@ public function dropIndex($table, $name) { return TRUE; } + /** + * {@inheritdoc} + */ public function addUniqueKey($table, $name, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add unique key @name to table @table: table doesn't exist.", ['@table' => $table, '@name' => $name])); @@ -646,6 +675,9 @@ public function addUniqueKey($table, $name, $fields) { } } + /** + * {@inheritdoc} + */ public function dropUniqueKey($table, $name) { if (!$this->indexExists($table, $name)) { return FALSE; @@ -657,6 +689,9 @@ public function dropUniqueKey($table, $name) { return TRUE; } + /** + * {@inheritdoc} + */ public function addPrimaryKey($table, $fields) { if (!$this->tableExists($table)) { throw new SchemaObjectDoesNotExistException(t("Cannot add primary key to table @table: table doesn't exist.", ['@table' => $table])); @@ -673,6 +708,9 @@ public function addPrimaryKey($table, $fields) { $this->alterTable($table, $old_schema, $new_schema); } + /** + * {@inheritdoc} + */ public function dropPrimaryKey($table) { $old_schema = $this->introspectSchema($table); $new_schema = $old_schema; @@ -686,6 +724,9 @@ public function dropPrimaryKey($table) { return TRUE; } + /** + * {@inheritdoc} + */ public function fieldSetDefault($table, $field, $default) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot set default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); @@ -698,6 +739,9 @@ public function fieldSetDefault($table, $field, $default) { $this->alterTable($table, $old_schema, $new_schema); } + /** + * {@inheritdoc} + */ public function fieldSetNoDefault($table, $field) { if (!$this->fieldExists($table, $field)) { throw new SchemaObjectDoesNotExistException(t("Cannot remove default value of field @table.@field: field doesn't exist.", ['@table' => $table, '@field' => $field])); -- GitLab