From cef10893892a1c40f73fd972969c3512b0983cd6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Tue, 29 Sep 2009 15:13:57 +0000 Subject: - Patch #570900 by Crell | asimmonds: Changed Destroy remnants of update_sql(). --- includes/common.inc | 10 +-- includes/database/database.inc | 105 ++++++++------------------ includes/database/mysql/schema.inc | 82 ++++++++++---------- includes/database/pgsql/schema.inc | 147 ++++++++++++++---------------------- includes/database/schema.inc | 73 ++++++------------ includes/database/sqlite/schema.inc | 119 ++++++++++++----------------- includes/locale.inc | 10 +-- includes/update.inc | 15 ++-- 8 files changed, 210 insertions(+), 351 deletions(-) (limited to 'includes') diff --git a/includes/common.inc b/includes/common.inc index 47542e937..f3701e50c 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -911,7 +911,7 @@ function _drupal_decode_exception($exception) { // The first element in the stack is the call, the second element gives us the caller. // We skip calls that occurred in one of the classes of the database layer // or in one of its global functions. - $db_functions = array('db_query', 'db_query_range', 'update_sql'); + $db_functions = array('db_query', 'db_query_range'); while (!empty($backtrace[1]) && ($caller = $backtrace[1]) && ((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) || in_array($caller['function'], $db_functions))) { @@ -4790,11 +4790,9 @@ function drupal_install_schema($module) { $schema = drupal_get_schema_unprocessed($module); _drupal_schema_initialize($module, $schema); - $ret = array(); foreach ($schema as $name => $table) { - db_create_table($ret, $name, $table); + db_create_table($name, $table); } - return $ret; } /** @@ -4815,13 +4813,11 @@ function drupal_uninstall_schema($module) { $schema = drupal_get_schema_unprocessed($module); _drupal_schema_initialize($module, $schema); - $ret = array(); foreach ($schema as $table) { if (db_table_exists($table['name'])) { - db_drop_table($ret, $table['name']); + db_drop_table($table['name']); } } - return $ret; } /** diff --git a/includes/database/database.inc b/includes/database/database.inc index cdadd89f2..b20de3979 100644 --- a/includes/database/database.inc +++ b/includes/database/database.inc @@ -2041,22 +2041,6 @@ function db_escape_table($table) { return Database::getConnection()->escapeTable($table); } -/** - * Perform an SQL query and return success or failure. - * - * @param $sql - * A string containing a complete SQL query. %-substitution - * parameters are not supported. - * @return - * An array containing the keys: - * success: a boolean indicating whether the query succeeded - * query: the SQL query executed, passed through check_plain() - */ -function update_sql($sql) { - $result = Database::getConnection()->query($sql); - return array('success' => $result !== FALSE, 'query' => check_plain($sql)); -} - /** * Retrieve the name of the currently active database driver, such as * "mysql" or "pgsql". @@ -2095,16 +2079,14 @@ function db_close(array $options = array()) { /** * Create a new table from a Drupal table definition. * - * @param $ret - * Array to which query results will be added. * @param $name * The name of the table to create. * @param $table * A Schema API table definition array. */ -function db_create_table(&$ret, $name, $table) { +function db_create_table($name, $table) { if (!db_table_exists($name)) { - return Database::getConnection()->schema()->createTable($ret, $name, $table); + return Database::getConnection()->schema()->createTable($name, $table); } } @@ -2165,34 +2147,28 @@ function db_type_map() { /** * Rename a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be renamed. * @param $new_name * The new name for the table. */ -function db_rename_table(&$ret, $table, $new_name) { - return Database::getConnection()->schema()->renameTable($ret, $table, $new_name); +function db_rename_table($table, $new_name) { + return Database::getConnection()->schema()->renameTable($table, $new_name); } /** * Drop a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be dropped. */ -function db_drop_table(&$ret, $table) { - return Database::getConnection()->schema()->dropTable($ret, $table); +function db_drop_table($table) { + return Database::getConnection()->schema()->dropTable($table); } /** * Add a new field to a table. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table to be altered. * @param $field @@ -2212,29 +2188,25 @@ function db_drop_table(&$ret, $table) { * explanation why. * @see db_change_field() */ -function db_add_field(&$ret, $table, $field, $spec, $keys_new = array()) { - return Database::getConnection()->schema()->addField($ret, $table, $field, $spec, $keys_new); +function db_add_field($table, $field, $spec, $keys_new = array()) { + return Database::getConnection()->schema()->addField($table, $field, $spec, $keys_new); } /** * Drop a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be dropped. */ -function db_drop_field(&$ret, $table, $field) { - return Database::getConnection()->schema()->dropField($ret, $table, $field); +function db_drop_field($table, $field) { + return Database::getConnection()->schema()->dropField($table, $field); } /** * Set the default value for a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field @@ -2242,55 +2214,47 @@ function db_drop_field(&$ret, $table, $field) { * @param $default * Default value to be set. NULL for 'default NULL'. */ -function db_field_set_default(&$ret, $table, $field, $default) { - return Database::getConnection()->schema()->fieldSetDefault($ret, $table, $field, $default); +function db_field_set_default($table, $field, $default) { + return Database::getConnection()->schema()->fieldSetDefault($table, $field, $default); } /** * Set a field to have no default value. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be altered. */ -function db_field_set_no_default(&$ret, $table, $field) { - return Database::getConnection()->schema()->fieldSetNoDefault($ret, $table, $field); +function db_field_set_no_default($table, $field) { + return Database::getConnection()->schema()->fieldSetNoDefault($table, $field); } /** * Add a primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $fields * Fields for the primary key. */ -function db_add_primary_key(&$ret, $table, $fields) { - return Database::getConnection()->schema()->addPrimaryKey($ret, $table, $fields); +function db_add_primary_key($table, $fields) { + return Database::getConnection()->schema()->addPrimaryKey($table, $fields); } /** * Drop the primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. */ -function db_drop_primary_key(&$ret, $table) { - return Database::getConnection()->schema()->dropPrimaryKey($ret, $table); +function db_drop_primary_key($table) { + return Database::getConnection()->schema()->dropPrimaryKey($table); } /** * Add a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -2298,29 +2262,25 @@ function db_drop_primary_key(&$ret, $table) { * @param $fields * An array of field names. */ -function db_add_unique_key(&$ret, $table, $name, $fields) { - return Database::getConnection()->schema()->addUniqueKey($ret, $table, $name, $fields); +function db_add_unique_key($table, $name, $fields) { + return Database::getConnection()->schema()->addUniqueKey($table, $name, $fields); } /** * Drop a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the key. */ -function db_drop_unique_key(&$ret, $table, $name) { - return Database::getConnection()->schema()->dropUniqueKey($ret, $table, $name); +function db_drop_unique_key($table, $name) { + return Database::getConnection()->schema()->dropUniqueKey($table, $name); } /** * Add an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -2328,22 +2288,20 @@ function db_drop_unique_key(&$ret, $table, $name) { * @param $fields * An array of field names. */ -function db_add_index(&$ret, $table, $name, $fields) { - return Database::getConnection()->schema()->addIndex($ret, $table, $name, $fields); +function db_add_index($table, $name, $fields) { + return Database::getConnection()->schema()->addIndex($table, $name, $fields); } /** * Drop an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the index. */ -function db_drop_index(&$ret, $table, $name) { - return Database::getConnection()->schema()->dropIndex($ret, $table, $name); +function db_drop_index($table, $name) { + return Database::getConnection()->schema()->dropIndex($table, $name); } /** @@ -2369,8 +2327,8 @@ function db_drop_index(&$ret, $table, $name) { * and you want to change foo.bar to be type serial, leaving it as the * primary key. The correct sequence is: * @code - * db_drop_primary_key($ret, 'foo'); - * db_change_field($ret, 'foo', 'bar', 'bar', + * db_drop_primary_key('foo'); + * db_change_field('foo', 'bar', 'bar', * array('type' => 'serial', 'not null' => TRUE), * array('primary key' => array('bar'))); * @endcode @@ -2393,8 +2351,6 @@ function db_drop_index(&$ret, $table, $name) { * unless you are converting a field to be type serial. You can use * the $keys_new argument in all cases. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table. * @param $field @@ -2408,9 +2364,8 @@ function db_drop_index(&$ret, $table, $name) { * table along with changing the field. The format is the same as a * table specification but without the 'fields' element. */ - -function db_change_field(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) { - return Database::getConnection()->schema()->changeField($ret, $table, $field, $field_new, $spec, $keys_new); +function db_change_field($table, $field, $field_new, $spec, $keys_new = array()) { + return Database::getConnection()->schema()->changeField($table, $field, $field_new, $spec, $keys_new); } /** diff --git a/includes/database/mysql/schema.inc b/includes/database/mysql/schema.inc index 99df5e70e..4fa20abf8 100644 --- a/includes/database/mysql/schema.inc +++ b/includes/database/mysql/schema.inc @@ -243,40 +243,40 @@ class DatabaseSchema_mysql extends DatabaseSchema { } protected function createKeySql($fields) { - $ret = array(); + $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $ret[] = '`' . $field[0] . '`(' . $field[1] . ')'; + $return[] = '`' . $field[0] . '`(' . $field[1] . ')'; } else { - $ret[] = '`' . $field . '`'; + $return[] = '`' . $field . '`'; } } - return implode(', ', $ret); + return implode(', ', $return); } protected function createKeysSqlHelper($fields) { - $ret = array(); + $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $ret[] = '`' . $field[0] . '`(' . $field[1] . ')'; + $return[] = '`' . $field[0] . '`(' . $field[1] . ')'; } else { - $ret[] = '`' . $field . '`'; + $return[] = '`' . $field . '`'; } } - return implode(', ', $ret); + return implode(', ', $return); } - public function renameTable(&$ret, $table, $new_name) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); + public function renameTable($table, $new_name) { + $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); } - public function dropTable(&$ret, $table) { - $ret[] = update_sql('DROP TABLE {' . $table . '}'); + public function dropTable($table) { + $this->connection->query('DROP TABLE {' . $table . '}'); } - public function addField(&$ret, $table, $field, $spec, $keys_new = array()) { + public function addField($table, $field, $spec, $keys_new = array()) { $fixnull = FALSE; if (!empty($spec['not null']) && !isset($spec['default'])) { $fixnull = TRUE; @@ -287,24 +287,23 @@ class DatabaseSchema_mysql extends DatabaseSchema { if (count($keys_new)) { $query .= ', ADD ' . implode(', ADD ', $this->createKeysSql($keys_new)); } - $ret[] = update_sql($query); + $this->connection->query($query); if (isset($spec['initial'])) { - // All this because update_sql does not support %-placeholders. - $sql = 'UPDATE {' . $table . '} SET ' . $field . ' = :value'; - $result = db_query($sql, array(':value' => $spec['initial'])); - $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql . ' (' . $spec['initial'] . ')')); + $this->connection->update($table) + ->fields(array($field, $spec['initial'])) + ->execute(); } if ($fixnull) { $spec['not null'] = TRUE; - $this->changeField($ret, $table, $field, $field, $spec); + $this->changeField($table, $field, $field, $spec); } } - public function dropField(&$ret, $table, $field) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP `' . $field . '`'); + public function dropField($table, $field) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP `' . $field . '`'); } - public function fieldSetDefault(&$ret, $table, $field, $default) { + public function fieldSetDefault($table, $field, $default) { if (is_null($default)) { $default = 'NULL'; } @@ -312,44 +311,43 @@ class DatabaseSchema_mysql extends DatabaseSchema { $default = is_string($default) ? "'$default'" : $default; } - $ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` SET DEFAULT ' . $default); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` SET DEFAULT ' . $default); } - public function fieldSetNoDefault(&$ret, $table, $field) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT'); + public function fieldSetNoDefault($table, $field) { + $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN `' . $field . '` DROP DEFAULT'); } - public function addPrimaryKey(&$ret, $table, $fields) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')'); + public function addPrimaryKey($table, $fields) { + $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . $this->createKeySql($fields) . ')'); } - public function dropPrimaryKey(&$ret, $table) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP PRIMARY KEY'); + public function dropPrimaryKey($table) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP PRIMARY KEY'); } - public function addUniqueKey(&$ret, $table, $name, $fields) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')'); + public function addUniqueKey($table, $name, $fields) { + $this->connection->query('ALTER TABLE {' . $table . '} ADD UNIQUE KEY `' . $name . '` (' . $this->createKeySql($fields) . ')'); } - public function dropUniqueKey(&$ret, $table, $name) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`'); + public function dropUniqueKey($table, $name) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP KEY `' . $name . '`'); } - public function addIndex(&$ret, $table, $name, $fields) { - $query = 'ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')'; - $ret[] = update_sql($query); + public function addIndex($table, $name, $fields) { + $this->connection->query('ALTER TABLE {' . $table . '} ADD INDEX `' . $name . '` (' . $this->createKeySql($fields) . ')'); } - public function dropIndex(&$ret, $table, $name) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`'); + public function dropIndex($table, $name) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP INDEX `' . $name . '`'); } - public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) { + public function changeField($table, $field, $field_new, $spec, $keys_new = array()) { $sql = 'ALTER TABLE {' . $table . '} CHANGE `' . $field . '` ' . $this->createFieldSql($field_new, $this->processField($spec)); if (count($keys_new)) { $sql .= ', ADD ' . implode(', ADD ', $this->createKeysSql($keys_new)); } - $ret[] = update_sql($sql); + $this->connection->query($sql); } public function prepareComment($comment, $length = NULL) { @@ -374,11 +372,11 @@ class DatabaseSchema_mysql extends DatabaseSchema { $condition->condition('column_name', $column); $condition->compile($this->connection, $this); // Don't use {} around information_schema.columns table. - return db_query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField(); + return $this->connection->query("SELECT column_comment FROM information_schema.columns WHERE " . (string) $condition, $condition->arguments())->fetchField(); } $condition->compile($this->connection, $this); // Don't use {} around information_schema.tables table. - $comment = db_query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField(); + $comment = $this->connection->query("SELECT table_comment FROM information_schema.tables WHERE " . (string) $condition, $condition->arguments())->fetchField(); // Work-around for MySQL 5.0 bug http://bugs.mysql.com/bug.php?id=11379 return preg_replace('/; InnoDB free:.*$/', '', $comment); } diff --git a/includes/database/pgsql/schema.inc b/includes/database/pgsql/schema.inc index c99fc78b9..e2aefe108 100644 --- a/includes/database/pgsql/schema.inc +++ b/includes/database/pgsql/schema.inc @@ -52,7 +52,11 @@ class DatabaseSchema_pgsql extends DatabaseSchema { 'sequences' => array(), ); // Don't use {} around information_schema.columns table. - $result = db_query("SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default LIKE :default))", array(':schema' => $schema, ':table' => $table_name, ':default' => '%nextval%')); + $result = $this->connection->query("SELECT column_name, data_type, column_default FROM information_schema.columns WHERE table_schema = :schema AND table_name = :table AND (data_type = 'bytea' OR (numeric_precision IS NOT NULL AND column_default LIKE :default))", array( + ':schema' => $schema, + ':table' => $table_name, + ':default' => '%nextval%', + )); foreach ($result as $column) { if ($column->data_type == 'bytea') { $table_information->blob_fields[$column->column_name] = TRUE; @@ -245,7 +249,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema { 'date:normal' => 'date', 'datetime:normal' => 'timestamp without time zone', - + 'time:normal' => 'time without time zone', 'serial:tiny' => 'serial', @@ -258,49 +262,29 @@ class DatabaseSchema_pgsql extends DatabaseSchema { } protected function _createKeySql($fields) { - $ret = array(); + $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $ret[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')'; + $return[] = 'substr(' . $field[0] . ', 1, ' . $field[1] . ')'; } else { - $ret[] = '"' . $field . '"'; + $return[] = '"' . $field . '"'; } } - return implode(', ', $ret); + return implode(', ', $return); } - /** - * Rename a table. - * - * @param $ret - * Array to which query results will be added. - * @param $table - * The table to be renamed. - * @param $new_name - * The new name for the table. - */ - function renameTable(&$ret, $table, $new_name) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); + function renameTable($table, $new_name) { + $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); } - /** - * Drop a table. - * - * @param $ret - * Array to which query results will be added. - * @param $table - * The table to be dropped. - */ - public function dropTable(&$ret, $table) { - $ret[] = update_sql('DROP TABLE {' . $table . '}'); + public function dropTable($table) { + $this->connection->query('DROP TABLE {' . $table . '}'); } /** * Add a new field to a table. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table to be altered. * @param $field @@ -321,7 +305,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * * @see db_change_field() */ - public function addField(&$ret, $table, $field, $spec, $new_keys = array()) { + public function addField($table, $field, $spec, $new_keys = array()) { $fixnull = FALSE; if (!empty($spec['not null']) && !isset($spec['default'])) { $fixnull = TRUE; @@ -329,44 +313,39 @@ class DatabaseSchema_pgsql extends DatabaseSchema { } $query = 'ALTER TABLE {' . $table . '} ADD COLUMN '; $query .= $this->createFieldSql($field, $this->processField($spec)); - $ret[] = update_sql($query); + $this->connection->query($query); if (isset($spec['initial'])) { - // All this because update_sql does not support %-placeholders. - $sql = 'UPDATE {' . $table . '} SET ' . $field . ' = :value'; - $result = db_query($sql, array(':value' => $spec['initial'])); - $ret[] = array('success' => $result !== FALSE, 'query' => check_plain($sql . ' (' . $spec['initial'] . ')')); + $this->connection->update($table) + ->fields(array($field, $spec['initial'])) + ->execute(); } if ($fixnull) { - $ret[] = update_sql("ALTER TABLE {" . $table . "} ALTER $field SET NOT NULL"); + $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field SET NOT NULL"); } if (isset($new_keys)) { - $this->_createKeys($ret, $table, $new_keys); + $this->_createKeys($table, $new_keys); } // Add column comment. if (!empty($spec['description'])) { - $ret[] = update_sql('COMMENT ON COLUMN {' . $table . '}.' . $field . ' IS ' . $this->prepareComment($spec['description'])); + $this->connection->query('COMMENT ON COLUMN {' . $table . '}.' . $field . ' IS ' . $this->prepareComment($spec['description'])); } } /** * Drop a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be dropped. */ - public function dropField(&$ret, $table, $field) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP COLUMN "' . $field . '"'); + public function dropField($table, $field) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP COLUMN "' . $field . '"'); } /** * Set the default value for a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field @@ -374,7 +353,7 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * @param $default * Default value to be set. NULL for 'default NULL'. */ - public function fieldSetDefault(&$ret, $table, $field, $default) { + public function fieldSetDefault($table, $field, $default) { if (is_null($default)) { $default = 'NULL'; } @@ -382,54 +361,46 @@ class DatabaseSchema_pgsql extends DatabaseSchema { $default = is_string($default) ? "'$default'" : $default; } - $ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" SET DEFAULT ' . $default); + $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" SET DEFAULT ' . $default); } /** * Set a field to have no default value. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be altered. */ - public function fieldSetNoDefault(&$ret, $table, $field) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" DROP DEFAULT'); + public function fieldSetNoDefault($table, $field) { + $this->connection->query('ALTER TABLE {' . $table . '} ALTER COLUMN "' . $field . '" DROP DEFAULT'); } /** * Add a primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $fields * Fields for the primary key. */ - public function addPrimaryKey(&$ret, $table, $fields) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')'); + public function addPrimaryKey($table, $fields) { + $this->connection->query('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . implode(',', $fields) . ')'); } /** * Drop the primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. */ - public function dropPrimaryKey(&$ret, $table) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP CONSTRAINT {' . $table . '}_pkey'); + public function dropPrimaryKey($table) { + $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT {' . $table . '}_pkey'); } /** * Add a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -437,31 +408,27 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * @param $fields * An array of field names. */ - function addUniqueKey(&$ret, $table, $name, $fields) { + function addUniqueKey($table, $name, $fields) { $name = '{' . $table . '}_' . $name . '_key'; - $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD CONSTRAINT "' . $name . '" UNIQUE (' . implode(',', $fields) . ')'); + $this->connection->query('ALTER TABLE {' . $table . '} ADD CONSTRAINT "' . $name . '" UNIQUE (' . implode(',', $fields) . ')'); } /** * Drop a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the key. */ - public function dropUniqueKey(&$ret, $table, $name) { + public function dropUniqueKey($table, $name) { $name = '{' . $table . '}_' . $name . '_key'; - $ret[] = update_sql('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $name . '"'); + $this->connection->query('ALTER TABLE {' . $table . '} DROP CONSTRAINT "' . $name . '"'); } /** * Add an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -469,23 +436,21 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * @param $fields * An array of field names. */ - public function addIndex(&$ret, $table, $name, $fields) { - $ret[] = update_sql($this->_createIndexSql($table, $name, $fields)); + public function addIndex($table, $name, $fields) { + $this->connection->query($this->_createIndexSql($table, $name, $fields)); } /** * Drop an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the index. */ - public function dropIndex(&$ret, $table, $name) { + public function dropIndex($table, $name) { $name = '{' . $table . '}_' . $name . '_idx'; - $ret[] = update_sql('DROP INDEX ' . $name); + $this->connection->query('DROP INDEX ' . $name); } /** @@ -511,8 +476,8 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * and you want to change foo.bar to be type serial, leaving it as the * primary key. The correct sequence is: * @code - * db_drop_primary_key($ret, 'foo'); - * db_change_field($ret, 'foo', 'bar', 'bar', + * db_drop_primary_key('foo'); + * db_change_field('foo', 'bar', 'bar', * array('type' => 'serial', 'not null' => TRUE), * array('primary key' => array('bar'))); * @endcode @@ -535,8 +500,6 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * unless you are converting a field to be type serial. You can use * the $new_keys argument in all cases. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table. * @param $field @@ -550,15 +513,15 @@ class DatabaseSchema_pgsql extends DatabaseSchema { * table along with changing the field. The format is the same as a * table specification but without the 'fields' element. */ - public function changeField(&$ret, $table, $field, $field_new, $spec, $new_keys = array()) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field . '_old"'); + public function changeField($table, $field, $field_new, $spec, $new_keys = array()) { + $this->connection->query('ALTER TABLE {' . $table . '} RENAME "' . $field . '" TO "' . $field . '_old"'); $not_null = isset($spec['not null']) ? $spec['not null'] : FALSE; unset($spec['not null']); if (!array_key_exists('size', $spec)) { $spec['size'] = 'normal'; } - $this->addField($ret, $table, "$field_new", $spec); + $this->addField($table, "$field_new", $spec); // We need to typecast the new column to best be able to transfer the data // Schema_pgsql::getFieldTypeMap() will return possibilities that are not @@ -568,16 +531,16 @@ class DatabaseSchema_pgsql extends DatabaseSchema { if (in_array($typecast, array('serial', 'bigserial', 'numeric'))) { $typecast = 'int'; } - $ret[] = update_sql("UPDATE {" . $table . "} SET $field_new = CAST(" . $field . "_old as " . $typecast . ")"); + $this->connection->query("UPDATE {" . $table . "} SET $field_new = CAST(" . $field . "_old as " . $typecast . ")"); if ($not_null) { - $ret[] = update_sql("ALTER TABLE {" . $table . "} ALTER $field_new SET NOT NULL"); + $this->connection->query("ALTER TABLE {" . $table . "} ALTER $field_new SET NOT NULL"); } - $this->dropField($ret, $table, $field . '_old'); + $this->dropField($table, $field . '_old'); if (isset($new_keys)) { - $this->_createKeys($ret, $table, $new_keys); + $this->_createKeys($table, $new_keys); } } @@ -587,18 +550,18 @@ class DatabaseSchema_pgsql extends DatabaseSchema { return $query; } - protected function _createKeys(&$ret, $table, $new_keys) { + protected function _createKeys($table, $new_keys) { if (isset($new_keys['primary key'])) { - $this->addPrimaryKey($ret, $table, $new_keys['primary key']); + $this->addPrimaryKey($table, $new_keys['primary key']); } if (isset($new_keys['unique keys'])) { foreach ($new_keys['unique keys'] as $name => $fields) { - $this->addUniqueKey($ret, $table, $name, $fields); + $this->addUniqueKey($table, $name, $fields); } } if (isset($new_keys['indexes'])) { foreach ($new_keys['indexes'] as $name => $fields) { - $this->addIndex($ret, $table, $name, $fields); + $this->addIndex($table, $name, $fields); } } } @@ -610,8 +573,8 @@ class DatabaseSchema_pgsql extends DatabaseSchema { $table = $this->connection->prefixTables('{' . $table . '}'); // Don't use {} around pg_class, pg_attribute tables. if (isset($column)) { - return db_query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($table, $column))->fetchField(); + $this->connection->query('SELECT col_description(oid, attnum) FROM pg_class, pg_attribute WHERE attrelid = oid AND relname = ? AND attname = ?', array($table, $column))->fetchField(); } - return db_query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $table))->fetchField(); + $this->connection->query('SELECT obj_description(oid, ?) FROM pg_class WHERE relname = ?', array('pg_class', $table))->fetchField(); } } diff --git a/includes/database/schema.inc b/includes/database/schema.inc index f8fd12ede..749d21da7 100644 --- a/includes/database/schema.inc +++ b/includes/database/schema.inc @@ -267,30 +267,24 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { /** * Rename a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be renamed. * @param $new_name * The new name for the table. */ - abstract public function renameTable(&$ret, $table, $new_name); + abstract public function renameTable($table, $new_name); /** * Drop a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be dropped. */ - abstract public function dropTable(&$ret, $table); + abstract public function dropTable($table); /** * Add a new field to a table. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table to be altered. * @param $field @@ -309,25 +303,21 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * or index including it in this array. @see db_change_field for more * explanation why. */ - abstract public function addField(&$ret, $table, $field, $spec, $keys_new = array()); + abstract public function addField($table, $field, $spec, $keys_new = array()); /** * Drop a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be dropped. */ - abstract public function dropField(&$ret, $table, $field); + abstract public function dropField($table, $field); /** * Set the default value for a field. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field @@ -335,47 +325,39 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * @param $default * Default value to be set. NULL for 'default NULL'. */ - abstract public function fieldSetDefault(&$ret, $table, $field, $default); + abstract public function fieldSetDefault($table, $field, $default); /** * Set a field to have no default value. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be altered. */ - abstract public function fieldSetNoDefault(&$ret, $table, $field); + abstract public function fieldSetNoDefault($table, $field); /** * Add a primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $fields * Fields for the primary key. */ - abstract public function addPrimaryKey(&$ret, $table, $fields); + abstract public function addPrimaryKey($table, $fields); /** * Drop the primary key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. */ - abstract public function dropPrimaryKey(&$ret, $table); + abstract public function dropPrimaryKey($table); /** * Add a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -383,25 +365,21 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * @param $fields * An array of field names. */ - abstract public function addUniqueKey(&$ret, $table, $name, $fields); + abstract public function addUniqueKey($table, $name, $fields); /** * Drop a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the key. */ - abstract public function dropUniqueKey(&$ret, $table, $name); + abstract public function dropUniqueKey($table, $name); /** * Add an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -409,20 +387,17 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * @param $fields * An array of field names. */ - abstract public function addIndex(&$ret, $table, $name, $fields); + abstract public function addIndex($table, $name, $fields); /** * Drop an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the index. */ - abstract public function dropIndex(&$ret, $table, $name); - + abstract public function dropIndex($table, $name); /** * Change a field definition. @@ -447,8 +422,8 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * and you want to change foo.bar to be type serial, leaving it as the * primary key. The correct sequence is: * @code - * db_drop_primary_key($ret, 'foo'); - * db_change_field($ret, 'foo', 'bar', 'bar', + * db_drop_primary_key('foo'); + * db_change_field('foo', 'bar', 'bar', * array('type' => 'serial', 'not null' => TRUE), * array('primary key' => array('bar'))); * @endcode @@ -471,8 +446,6 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * unless you are converting a field to be type serial. You can use * the $keys_new argument in all cases. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table. * @param $field @@ -486,22 +459,20 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * table along with changing the field. The format is the same as a * table specification but without the 'fields' element. */ - abstract public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()); + abstract public function changeField($table, $field, $field_new, $spec, $keys_new = array()); /** * Create a new table from a Drupal table definition. * - * @param $ret - * Array to which query results will be added. * @param $name * The name of the table to create. * @param $table * A Schema API table definition array. */ - public function createTable(&$ret, $name, $table) { - $statements = $this->createTableSql($name, $table); + public function createTable($name, $table) { + $statements = $this->createTableSql($name, $table); foreach ($statements as $statement) { - $ret[] = update_sql($statement); + $this->connection->query($statement); } } @@ -517,16 +488,16 @@ abstract class DatabaseSchema implements QueryPlaceholderInterface { * An array of field names. */ public function fieldNames($fields) { - $ret = array(); + $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $ret[] = $field[0]; + $return[] = $field[0]; } else { - $ret[] = $field; + $return[] = $field; } } - return $ret; + return $return; } /** diff --git a/includes/database/sqlite/schema.inc b/includes/database/sqlite/schema.inc index 4f3df5f74..893f54be7 100644 --- a/includes/database/sqlite/schema.inc +++ b/includes/database/sqlite/schema.inc @@ -86,16 +86,16 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * Build the SQL expression for keys. */ protected function createKeySql($fields) { - $ret = array(); + $return = array(); foreach ($fields as $field) { if (is_array($field)) { - $ret[] = $field[0]; + $return[] = $field[0]; } else { - $ret[] = $field; + $return[] = $field; } } - return implode(', ', $ret); + return implode(', ', $return); } /** @@ -214,34 +214,28 @@ class DatabaseSchema_sqlite extends DatabaseSchema { /** * Rename a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be renamed. * @param $new_name * The new name for the table. */ - public function renameTable(&$ret, $table, $new_name) { - $ret[] = update_sql('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); + public function renameTable($table, $new_name) { + $this->connection->query('ALTER TABLE {' . $table . '} RENAME TO {' . $new_name . '}'); } /** * Drop a table. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be dropped. */ - public function dropTable(&$ret, $table) { - $ret[] = update_sql('DROP TABLE {' . $table . '}'); + public function dropTable($table) { + $this->connection->query('DROP TABLE {' . $table . '}'); } /** * Add a new field to a table. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table to be altered. * @param $field @@ -249,11 +243,11 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * @param $spec * The field specification array, as taken from a schema definition. */ - public function addField(&$ret, $table, $field, $spec, $keys_new = array()) { + public function addField($table, $field, $spec, $keys_new = array()) { // TODO: $keys_new is not supported yet. $query = 'ALTER TABLE {' . $table . '} ADD '; $query .= $this->createFieldSql($field, $this->processField($spec)); - $ret[] = update_sql($query); + $this->connection->query($query); } /** @@ -262,30 +256,32 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * As SQLite does not support ALTER TABLE (with a few exceptions) it is * necessary to create a new table and copy over the old content. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table to be altered. * @param $new_schema * The new schema array for the table. */ - protected function alterTable(&$ret, $table, $new_schema) { + protected function alterTable($table, $new_schema) { $i = 0; do { $new_table = $table . '_' . $i++; } while ($this->tableExists($new_table)); - $this->createTable($ret, $new_table, $new_schema); - $fields = implode(', ', array_keys($new_schema['fields'])); - $ret[] = update_sql('INSERT INTO {' . $new_table . "} ($fields) SELECT $fields FROM {" . $table . '}'); - $old_count = db_query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField(); - $new_count = db_query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchField(); + + $this->createTable($new_table, $new_schema); + + $select = $this->connection->select($table)->fields($new_schema['fields']); + $this->connection->insert($new_table) + ->from($select) + ->execute(); + $old_count = $this->connection->query('SELECT COUNT(*) FROM {' . $table . '}')->fetchField(); + $new_count = $this->connection->query('SELECT COUNT(*) FROM {' . $new_table . '}')->fetchField(); if ($old_count == $new_count) { do { $temp_table = $table . '_' . $i++; } while ($this->tableExists($temp_table)); - $this->renameTable($ret, $table, $temp_table); - $this->renameTable($ret, $new_table, $table); - $this->dropTable($ret, $temp_table); + $this->renameTable($table, $temp_table); + $this->renameTable($new_table, $table); + $this->dropTable($temp_table); } } @@ -305,7 +301,8 @@ class DatabaseSchema_sqlite extends DatabaseSchema { protected function introspectSchema($table) { $mapped_fields = array_flip($this->getFieldTypeMap()); $schema = array(); - foreach (db_query("PRAGMA table_info('{" . $table . "}')") as $row) { + $result = $this->connection->query("PRAGMA table_info('{" . $table . "}')"); + foreach ($result as $row) { if (preg_match('/^([^(]+)\((.*)\)$/', $row->type, $matches)) { $type = $matches[1]; $length = $matches[2]; @@ -334,7 +331,8 @@ class DatabaseSchema_sqlite extends DatabaseSchema { } } $indexes = array(); - foreach (db_query("PRAGMA index_list('{" . $table . "}')") as $row) { + $result = $this->connection->query("PRAGMA index_list('{" . $table . "}')"); + foreach ($result as $row) { if (strpos($row->name, 'sqlite_autoindex_') !== 0) { $indexes[] = array( 'schema_key' => $row->unique ? 'unique keys' : 'indexes', @@ -346,7 +344,8 @@ class DatabaseSchema_sqlite extends DatabaseSchema { foreach ($indexes as $index) { $name = $index['name']; $index_name = substr($name, $n); - foreach (db_query("PRAGMA index_info('$name')") as $row) { + $result = $this->connection->query("PRAGMA index_info('$name')"); + foreach ($result as $row) { $schema[$index['schema_key']][$index_name][] = $row->name; } } @@ -359,14 +358,12 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be dropped. */ - public function dropField(&$ret, $table, $field) { + public function dropField($table, $field) { $new_schema = $this->introspectSchema($table); unset($new_schema['fields'][$field]); foreach ($new_schema['indexes'] as $index => $fields) { @@ -380,7 +377,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { unset($new_schema['indexes'][$index]); } } - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** @@ -389,8 +386,6 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command. * - * @param $ret - * Array to which query results will be added. * @param $table * Name of the table. * @param $field @@ -404,7 +399,7 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * table along with changing the field. The format is the same as a * table specification but without the 'fields' element. */ - public function changeField(&$ret, $table, $field, $field_new, $spec, $keys_new = array()) { + public function changeField($table, $field, $field_new, $spec, $keys_new = array()) { $new_schema = $this->introspectSchema($table); unset($new_schema['fields'][$field]); $new_schema['fields'][$field_new] = $spec; @@ -417,14 +412,12 @@ class DatabaseSchema_sqlite extends DatabaseSchema { $new_schema[$k] = $keys_new[$k] + $new_schema[$k]; } } - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** * Add an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -432,33 +425,29 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * @param $fields * An array of field names. */ - public function addIndex(&$ret, $table, $name, $fields) { + public function addIndex($table, $name, $fields) { $schema['indexes'][$name] = $fields; $statements = $this->createIndexSql($table, $schema); foreach ($statements as $statement) { - $ret[] = update_sql($statement); + $this->connection->query($statement); } } /** * Drop an index. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the index. */ - public function dropIndex(&$ret, $table, $name) { - $ret[] = update_sql('DROP INDEX ' . '{' . $table . '}_' . $name); + public function dropIndex($table, $name) { + $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name); } /** * Add a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name @@ -466,26 +455,24 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * @param $fields * An array of field names. */ - public function addUniqueKey(&$ret, $table, $name, $fields) { + public function addUniqueKey($table, $name, $fields) { $schema['unique keys'][$name] = $fields; $statements = $this->createIndexSql($table, $schema); foreach ($statements as $statement) { - $ret[] = update_sql($statement); + $this->connection->query($statement); } } /** * Drop a unique key. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $name * The name of the key. */ - public function dropUniqueKey(&$ret, $table, $name) { - $ret[] = update_sql('DROP INDEX ' . '{' . $table . '}_' . $name); + public function dropUniqueKey($table, $name) { + $this->connection->query('DROP INDEX ' . '{' . $table . '}_' . $name); } /** @@ -494,17 +481,15 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $fields * Fields for the primary key. */ - public function addPrimaryKey(&$ret, $table, $fields) { + public function addPrimaryKey($table, $fields) { $new_schema = $this->introspectSchema($table); $new_schema['primary key'] = $fields; - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** @@ -513,15 +498,13 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command.` * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. */ - public function dropPrimaryKey(&$ret, $table) { + public function dropPrimaryKey($table) { $new_schema = $this->introspectSchema($table); unset($new_schema['primary key']); - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** @@ -530,8 +513,6 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field @@ -539,10 +520,10 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * @param $default * Default value to be set. NULL for 'default NULL'. */ - public function fieldSetDefault(&$ret, $table, $field, $default) { + public function fieldSetDefault($table, $field, $default) { $new_schema = $this->introspectSchema($table); $new_schema['fields'][$field]['default'] = $default; - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** @@ -551,17 +532,15 @@ class DatabaseSchema_sqlite extends DatabaseSchema { * This implementation can't use ALTER TABLE directly, because SQLite only * supports a limited subset of that command. * - * @param $ret - * Array to which query results will be added. * @param $table * The table to be altered. * @param $field * The field to be altered. */ - public function fieldSetNoDefault(&$ret, $table, $field) { + public function fieldSetNoDefault($table, $field) { $new_schema = $this->introspectSchema($table); unset($new_schema['fields'][$field]['default']); - $this->alterTable($ret, $table, $new_schema); + $this->alterTable($table, $new_schema); } /** diff --git a/includes/locale.inc b/includes/locale.inc index 6ee5baa82..8e7cc3cd4 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -765,7 +765,7 @@ function locale_translate_import_form_submit($form, &$form_state) { } // Now import strings into the language - if ($ret = _locale_import_po($file, $langcode, $form_state['values']['mode'], $form_state['values']['group']) == FALSE) { + if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode'], $form_state['values']['group']) == FALSE) { $variables = array('%filename' => $file->filename); drupal_set_message(t('The translation import of %filename failed.', $variables), 'error'); watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR); @@ -2175,7 +2175,7 @@ function _locale_export_string($str) { */ function _locale_export_wrap($str, $len) { $words = explode(' ', $str); - $ret = array(); + $return = array(); $cur = ""; $nstr = 1; @@ -2186,16 +2186,16 @@ function _locale_export_wrap($str, $len) { $nstr = 0; } elseif (strlen("$cur $word") > $len) { - $ret[] = $cur . " "; + $return[] = $cur . " "; $cur = $word; } else { $cur = "$cur $word"; } } - $ret[] = $cur; + $return[] = $cur; - return implode("\n", $ret); + return implode("\n", $return); } /** diff --git a/includes/update.inc b/includes/update.inc index f8a885531..89deb3ba9 100644 --- a/includes/update.inc +++ b/includes/update.inc @@ -14,7 +14,6 @@ * current version of Drupal core. */ function update_fix_compatibility() { - $ret = array(); $incompatible = array(); $result = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')"); foreach ($result as $row) { @@ -23,9 +22,11 @@ function update_fix_compatibility() { } } if (!empty($incompatible)) { - $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('" . implode("','", $incompatible) . "')"); + db_update('system') + ->fields(array('status' => 0)) + ->condition('name', $incompatible, 'IN') + ->execute(); } - return $ret; } /** @@ -113,7 +114,6 @@ function update_prepare_d7_bootstrap() { */ function update_fix_d7_requirements() { global $conf; - $ret = array(); // Rewrite the settings.php file if necessary. // @see update_prepare_d7_bootstrap(). @@ -126,11 +126,11 @@ function update_fix_d7_requirements() { // Add the cache_path table. $schema['cache_path'] = drupal_get_schema_unprocessed('system', 'cache'); $schema['cache_path']['description'] = 'Cache table used for path alias lookups.'; - db_create_table($ret, 'cache_path', $schema['cache_path']); + db_create_table('cache_path', $schema['cache_path']); // Add column for locale context. if (db_table_exists('locales_source')) { - db_add_field($ret, 'locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The context this string applies to.')); + db_add_field('locales_source', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '', 'description' => 'The context this string applies to.')); } // Rename 'site_offline_message' variable to 'maintenance_mode_message'. @@ -144,8 +144,6 @@ function update_fix_d7_requirements() { } update_fix_d7_install_profile(); - - return $ret; } /** @@ -161,7 +159,6 @@ function update_fix_d7_requirements() { function update_fix_d7_install_profile() { $profile = drupal_get_profile(); - $results = db_select('system', 's') ->fields('s', array('name', 'schema_version')) ->condition('name', $profile) -- cgit v1.2.3