summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/common.inc10
-rw-r--r--includes/database/database.inc105
-rw-r--r--includes/database/mysql/schema.inc82
-rw-r--r--includes/database/pgsql/schema.inc147
-rw-r--r--includes/database/schema.inc73
-rw-r--r--includes/database/sqlite/schema.inc119
-rw-r--r--includes/locale.inc10
-rw-r--r--includes/update.inc15
-rw-r--r--modules/aggregator/aggregator.install5
-rw-r--r--modules/block/block.install12
-rw-r--r--modules/comment/comment.install42
-rw-r--r--modules/contact/contact.install1
-rw-r--r--modules/dblog/dblog.install14
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.module26
-rw-r--r--modules/filter/filter.install62
-rw-r--r--modules/forum/forum.install7
-rw-r--r--modules/locale/locale.install6
-rw-r--r--modules/node/node.install50
-rw-r--r--modules/poll/poll.install10
-rw-r--r--modules/profile/profile.install6
-rw-r--r--modules/search/search.install13
-rw-r--r--modules/simpletest/drupal_web_test_case.php2
-rw-r--r--modules/simpletest/simpletest.module3
-rw-r--r--modules/simpletest/tests/database_test.test29
-rw-r--r--modules/simpletest/tests/field_test.module4
-rw-r--r--modules/simpletest/tests/schema.test21
-rw-r--r--modules/statistics/statistics.install4
-rw-r--r--modules/system/system.api.php42
-rw-r--r--modules/system/system.install366
-rw-r--r--modules/taxonomy/taxonomy.install9
-rw-r--r--modules/tracker/tracker.install4
-rw-r--r--modules/trigger/trigger.install14
-rw-r--r--modules/upload/upload.install5
-rw-r--r--modules/user/user.install54
34 files changed, 602 insertions, 770 deletions
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
@@ -2042,22 +2042,6 @@ function db_escape_table($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)
diff --git a/modules/aggregator/aggregator.install b/modules/aggregator/aggregator.install
index cc4d2258a..8cfb79c6f 100644
--- a/modules/aggregator/aggregator.install
+++ b/modules/aggregator/aggregator.install
@@ -266,10 +266,9 @@ function aggregator_schema() {
* Add hash column to aggregator_feed table.
*/
function aggregator_update_7000() {
- $ret = array();
- db_add_field($ret, 'aggregator_feed', 'hash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
- return $ret;
+ db_add_field('aggregator_feed', 'hash', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''));
}
+
/**
* Add aggregator teaser length to settings from old global default teaser length
*/
diff --git a/modules/block/block.install b/modules/block/block.install
index f1b2b3e7a..33275506b 100644
--- a/modules/block/block.install
+++ b/modules/block/block.install
@@ -223,9 +223,10 @@ function block_install() {
* so before block module runs, there will not be much to alter.
*/
function block_update_7000() {
- $ret = array();
- $ret[] = update_sql("UPDATE {system} SET weight = -5 WHERE name = 'block'");
- return $ret;
+ db_update('system')
+ ->fields(array('weight', '-5'))
+ ->condition('name', 'block')
+ ->execute();
}
@@ -233,8 +234,6 @@ function block_update_7000() {
* Add the block_node_type table.
*/
function block_update_7001() {
- $ret = array();
-
$schema['block_node_type'] = array(
'description' => 'Sets up display criteria for blocks based on content types',
'fields' => array(
@@ -263,6 +262,5 @@ function block_update_7001() {
),
);
- db_create_table($ret, 'block_node_type', $schema['block_node_type']);
- return $ret;
+ db_create_table('block_node_type', $schema['block_node_type']);
}
diff --git a/modules/comment/comment.install b/modules/comment/comment.install
index 1b63d4aa3..300534544 100644
--- a/modules/comment/comment.install
+++ b/modules/comment/comment.install
@@ -58,40 +58,42 @@ function comment_update_7000() {
foreach ($types as $type => $object) {
variable_del('comment_default_order' . $type);
}
- return array(array('success' => TRUE, 'query' => 'Comment order settings removed.'));
+ return t('Comment order settings removed.');
}
/**
* Change comment status from published being 0 to being 1
*/
function comment_update_7001() {
- $ret = array();
- $ret[] = update_sql("UPDATE {comments} SET status = 3 WHERE status = 0");
- $ret[] = update_sql("UPDATE {comments} SET status = 0 WHERE status = 1");
- $ret[] = update_sql("UPDATE {comments} SET status = 1 WHERE status = 3");
+ $changes = array(
+ 3 => 0,
+ 0 => 1,
+ 1 => 3,
+ );
- return $ret;
+ foreach ($changes as $old => $new) {
+ db_update('comments')
+ ->fields(array('status', $new))
+ ->condition('status', $old)
+ ->execute();
+ }
}
/**
* Rename {comments} table to {comment}.
*/
function comment_update_7002() {
- $ret = array();
- db_rename_table($ret, 'comments', 'comment');
- return $ret;
+ db_rename_table('comments', 'comment');
}
/**
* Improve indexes on the comment table.
*/
function comment_update_7003() {
- $ret = array();
- db_drop_index($ret, 'comment', 'status');
- db_drop_index($ret, 'comment', 'pid');
- db_add_index($ret, 'comment', 'comment_pid_status', array('pid', 'status'));
- db_add_index($ret, 'comment', 'comment_num_new', array('nid', 'timestamp', 'status'));
- return $ret;
+ db_drop_index('comment', 'status');
+ db_drop_index('comment', 'pid');
+ db_add_index('comment', 'comment_pid_status', array('pid', 'status'));
+ db_add_index('comment', 'comment_num_new', array('nid', 'timestamp', 'status'));
}
/**
@@ -108,29 +110,23 @@ function comment_update_7004() {
variable_set('comment_default_mode_' . $type, 0);
}
}
- return array();
}
/**
* Create comment Field API bundles.
*/
function comment_update_7005() {
- $ret = array();
-
foreach (node_type_get_types() as $info) {
field_attach_create_bundle('comment_node_' . $info->type);
}
- return $ret;
}
/**
* Create user related indexes.
*/
function comment_update_7006() {
- $ret = array();
- db_add_index($ret, 'comment', 'comment_uid', array('uid'));
- db_add_index($ret, 'node_comment_statistics', 'last_comment_uid', array('last_comment_uid'));
- return $ret;
+ db_add_index('comment', 'comment_uid', array('uid'));
+ db_add_index('node_comment_statistics', 'last_comment_uid', array('last_comment_uid'));
}
/**
diff --git a/modules/contact/contact.install b/modules/contact/contact.install
index 7b3e57b71..0ebe73c9e 100644
--- a/modules/contact/contact.install
+++ b/modules/contact/contact.install
@@ -85,7 +85,6 @@ function contact_schema() {
function contact_update_7000() {
variable_set('contact_threshold_limit', variable_get('contact_hourly_threshold', 5));
variable_del('contact_hourly_threshold');
- return array();
}
/**
diff --git a/modules/dblog/dblog.install b/modules/dblog/dblog.install
index fef784fb7..cb417c0fb 100644
--- a/modules/dblog/dblog.install
+++ b/modules/dblog/dblog.install
@@ -96,26 +96,20 @@ function dblog_schema() {
* Allow NULL values for links and longer referers.
*/
function dblog_update_7001() {
- $ret = array();
- db_change_field($ret, 'watchdog', 'link', 'link', array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => ''));
- db_change_field($ret, 'watchdog', 'referer', 'referer', array('type' => 'text', 'not null' => FALSE));
- return $ret;
+ db_change_field('watchdog', 'link', 'link', array('type' => 'varchar', 'length' => 255, 'not null' => FALSE, 'default' => ''));
+ db_change_field('watchdog', 'referer', 'referer', array('type' => 'text', 'not null' => FALSE));
}
/**
* Add index on uid.
*/
function dblog_update_7002() {
- $ret = array();
- db_add_index($ret, 'watchdog', 'uid', array('uid'));
- return $ret;
+ db_add_index('watchdog', 'uid', array('uid'));
}
/**
* Allow longer type values.
*/
function dblog_update_7003() {
- $ret = array();
- db_change_field($ret, 'watchdog', 'type', 'type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''));
- return $ret;
+ db_change_field('watchdog', 'type', 'type', array('type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''));
}
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.module b/modules/field/modules/field_sql_storage/field_sql_storage.module
index 09dee368a..fd06e2ea1 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -211,7 +211,7 @@ function _field_sql_storage_schema($field) {
function field_sql_storage_field_storage_create_field($field) {
$schema = _field_sql_storage_schema($field);
foreach ($schema as $name => $table) {
- db_create_table($ret, $name, $table);
+ db_create_table($name, $table);
}
}
@@ -231,17 +231,15 @@ function field_sql_storage_field_update_forbid($field, $prior_field, $has_data)
* Implement hook_field_storage_update_field().
*/
function field_sql_storage_field_storage_update_field($field, $prior_field, $has_data) {
- $ret = array();
-
if (! $has_data) {
// There is no data. Re-create the tables completely.
$prior_schema = _field_sql_storage_schema($prior_field);
foreach ($prior_schema as $name => $table) {
- db_drop_table($ret, $name, $table);
+ db_drop_table($name, $table);
}
$schema = _field_sql_storage_schema($field);
foreach ($schema as $name => $table) {
- db_create_table($ret, $name, $table);
+ db_create_table($name, $table);
}
}
else {
@@ -253,8 +251,8 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has
foreach ($prior_field['indexes'] as $name => $columns) {
if (!isset($field['indexes'][$name]) || $columns != $field['indexes'][$name]) {
$real_name = _field_sql_storage_indexname($field['field_name'], $name);
- db_drop_index($ret, $table, $real_name);
- db_drop_index($ret, $revision_table, $real_name);
+ db_drop_index($table, $real_name);
+ db_drop_index($revision_table, $real_name);
}
}
$table = _field_sql_storage_tablename($field);
@@ -266,8 +264,8 @@ function field_sql_storage_field_storage_update_field($field, $prior_field, $has
foreach ($columns as $column_name) {
$real_columns[] = _field_sql_storage_columnname($field['field_name'], $column_name);
}
- db_add_index($ret, $table, $real_name, $real_columns);
- db_add_index($ret, $revision_table, $real_name, $real_columns);
+ db_add_index($table, $real_name, $real_columns);
+ db_add_index($revision_table, $real_name, $real_columns);
}
}
}
@@ -286,12 +284,11 @@ function field_sql_storage_field_storage_delete_field($field) {
->execute();
// Move the table to a unique name while the table contents are being deleted.
- $ret = array();
$field['deleted'] = 1;
$new_table = _field_sql_storage_tablename($field);
$revision_new_table = _field_sql_storage_revision_tablename($field);
- db_rename_table($ret, $table, $new_table);
- db_rename_table($ret, $revision_table, $revision_new_table);
+ db_rename_table($table, $new_table);
+ db_rename_table($revision_table, $revision_new_table);
drupal_get_schema(NULL, TRUE);
}
@@ -655,10 +652,9 @@ function field_sql_storage_field_attach_rename_bundle($bundle_old, $bundle_new)
* that is left is to delete the table.
*/
function field_sql_storage_field_storage_purge_field($field) {
- $ret = array();
$table_name = _field_sql_storage_tablename($field);
$revision_name = _field_sql_storage_revision_tablename($field);
- db_drop_table($ret, $table_name);
- db_drop_table($ret, $revision_name);
+ db_drop_table($table_name);
+ db_drop_table($revision_name);
}
diff --git a/modules/filter/filter.install b/modules/filter/filter.install
index 5685ea577..deda8bc32 100644
--- a/modules/filter/filter.install
+++ b/modules/filter/filter.install
@@ -113,42 +113,44 @@ function filter_schema() {
* Add a weight column to the filter formats table.
*/
function filter_update_7000() {
- $ret = array();
- db_add_field($ret, 'filter_formats', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
- return $ret;
+ db_add_field('filter_formats', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
}
/**
* Break out "escape HTML filter" option to its own filter.
*/
function filter_update_7001() {
- $ret = array();
$result = db_query("SELECT format FROM {filter_formats}");
+ $insert = db_insert('filters')->fields(array('format', 'module', 'delta', 'weight'));
+
foreach ($result as $format) {
// Deprecated constants FILTER_HTML_STRIP = 1 and FILTER_HTML_ESCAPE = 2.
if (variable_get('filter_html_' . $format->format, 1) == 2) {
- $ret[] = update_sql("INSERT INTO {filters} (format, module, delta, weight) VALUES (" . $format->format . ", 'filter', 4, 0)");
+ $insert->values(array(
+ 'format' => $format->format,
+ 'filter' => 'filter',
+ 'delta' => 4,
+ 'weight' => 0,
+ ));
}
variable_del('filter_html_' . $format->format);
}
- return $ret;
+
+ $insert->execute();
}
/**
* Rename {filters} table to {filter} and {filter_formats} table to {filter_format}.
*/
function filter_update_7002() {
- $ret = array();
- db_rename_table($ret, 'filters', 'filter');
- db_rename_table($ret, 'filter_formats', 'filter_format');
- return $ret;
+ db_rename_table('filters', 'filter');
+ db_rename_table('filter_formats', 'filter_format');
}
/**
* Remove hardcoded numeric deltas from all filters in core.
*/
function filter_update_7003() {
- $ret = array();
// Get an array of the renamed filter deltas, organized by module.
$renamed_deltas = array(
'filter' => array(
@@ -164,9 +166,9 @@ function filter_update_7003() {
);
// Rename field 'delta' to 'name'.
- db_drop_unique_key($ret, 'filter', 'fmd');
- db_drop_index($ret, 'filter', 'list');
- db_change_field($ret, 'filter', 'delta', 'name',
+ db_drop_unique_key('filter', 'fmd');
+ db_drop_index('filter', 'list');
+ db_change_field('filter', 'delta', 'name',
array(
'type' => 'varchar',
'length' => 32,
@@ -187,10 +189,13 @@ function filter_update_7003() {
// Loop through each filter and make changes to the core filter table.
foreach ($renamed_deltas as $module => $deltas) {
foreach ($deltas as $old_delta => $new_delta) {
- $ret[] = update_sql("UPDATE {filter} SET name = '" . $new_delta . "' WHERE module = '" . $module . "' AND name = '" . $old_delta . "'");
+ db_update('filter')
+ ->fields(array('name', $new_delta))
+ ->condition('module', $module)
+ ->condition('name', $old_delta)
+ ->execute();
}
}
- return $ret;
}
/**
@@ -202,10 +207,9 @@ function filter_update_7003() {
* - Add {filter}.settings.
*/
function filter_update_7004() {
- $ret = array();
- db_drop_field($ret, 'filter', 'fid');
- db_add_primary_key($ret, 'filter', array('format', 'name'));
- db_add_field($ret, 'filter', 'status',
+ db_drop_field('filter', 'fid');
+ db_add_primary_key('filter', array('format', 'name'));
+ db_add_field('filter', 'status',
array(
'type' => 'int',
'not null' => TRUE,
@@ -213,7 +217,7 @@ function filter_update_7004() {
'description' => 'Filter enabled status. (1 = enabled, 0 = disabled)',
)
);
- db_add_field($ret, 'filter', 'settings',
+ db_add_field('filter', 'settings',
array(
'type' => 'text',
'not null' => FALSE,
@@ -224,7 +228,9 @@ function filter_update_7004() {
);
// Enable all existing filters ({filter} contained only enabled previously).
- $ret[] = update_sql("UPDATE {filter} SET status = 1");
+ db_update('filter')
+ ->fields('status', '1')
+ ->execute();
// Move filter settings from system variables into {filter}.settings.
$filters = db_query("SELECT * FROM {filter} WHERE module = :name", array(':name' => 'filter'));
@@ -251,11 +257,13 @@ function filter_update_7004() {
}
}
if (!empty($settings)) {
- $ret[] = update_sql("UPDATE {filter} SET settings = '" . serialize($settings) . "' WHERE format = {$filter->format} AND name = '{$filter->name}'");
+ db_upddate('filter')
+ ->fields(array('settings' => serialize($settings)))
+ ->condition('format', $filter->format)
+ ->condition('name', $filter->name)
+ ->execute();
}
}
-
- return $ret;
}
/**
@@ -267,7 +275,6 @@ function filter_update_7004() {
* in cases that used to rely on a single site-wide default.
*/
function filter_update_7005() {
- $ret = array();
// Move role data from the filter system to the user permission system.
$all_roles = array_keys(user_roles());
@@ -286,7 +293,7 @@ function filter_update_7005() {
}
// Drop the roles field from the {filter_format} table.
- db_drop_field($ret, 'filter_format', 'roles');
+ db_drop_field('filter_format', 'roles');
// Add a fallback text format which outputs plain text and appears last on
// the list for all users. Generate a unique name for it, starting with
@@ -336,7 +343,6 @@ function filter_update_7005() {
// We do not delete the 'filter_default_format' variable, since other modules
// may need it in their update functions.
// @todo This variable can be deleted in Drupal 8.
- return $ret;
}
/**
diff --git a/modules/forum/forum.install b/modules/forum/forum.install
index c42490e2e..df6ccf48d 100644
--- a/modules/forum/forum.install
+++ b/modules/forum/forum.install
@@ -116,9 +116,6 @@ function forum_schema() {
* Add new index to forum table.
*/
function forum_update_7000() {
- $ret = array();
- db_drop_index($ret, 'forum', 'nid');
- db_add_index($ret, 'forum', 'forum_topic', array('nid', 'tid'));
-
- return $ret;
+ db_drop_index('forum', 'nid');
+ db_add_index('forum', 'forum_topic', array('nid', 'tid'));
}
diff --git a/modules/locale/locale.install b/modules/locale/locale.install
index d487803c1..73d8814e1 100644
--- a/modules/locale/locale.install
+++ b/modules/locale/locale.install
@@ -36,10 +36,8 @@ function locale_install() {
* Allow longer location.
*/
function locale_update_7000() {
- $ret = array();
- db_drop_index($ret, 'locales_source', 'source');
- db_add_index($ret, 'locales_source', 'source_context', array(array('source', 30), 'context'));
- return $ret;
+ db_drop_index('locales_source', 'source');
+ db_add_index('locales_source', 'source_context', array(array('source', 30), 'context'));
}
/**
diff --git a/modules/node/node.install b/modules/node/node.install
index 6ac772029..947757605 100644
--- a/modules/node/node.install
+++ b/modules/node/node.install
@@ -360,42 +360,34 @@ function node_schema() {
* Fix node type 'module' attribute to avoid name-space conflicts.
*/
function node_update_7000() {
- $ret = array();
-
- $ret[] = update_sql("UPDATE {node_type} SET module = 'node_content' WHERE module = 'node'");
- db_change_field($ret, 'node_type', 'module', 'base', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
-
- return $ret;
+ db_update('node_type')
+ ->fields(array('module' => 'node_content'))
+ ->condition('module', 'node')
+ ->execute();
}
/**
* Rename {node_revisions} table to {node_revision}.
*/
function node_update_7001() {
- $ret = array();
- db_rename_table($ret, 'node_revisions', 'node_revision');
- return $ret;
+ db_rename_table('node_revisions', 'node_revision');
}
/**
* Extend the node_promote_status index to include all fields required for the node page query.
*/
function node_update_7002() {
- $ret = array();
- db_drop_index($ret, 'node', 'node_promote_status');
- db_add_index($ret, 'node', 'node_frontpage', array('promote', 'status', 'sticky', 'created'));
- return $ret;
+ db_drop_index('node', 'node_promote_status');
+ db_add_index('node', 'node_frontpage', array('promote', 'status', 'sticky', 'created'));
}
/**
* Remove the node_counter if the statistics module is uninstalled.
*/
function node_update_7003() {
- $ret = array();
if (drupal_get_installed_schema_version('statistics') == SCHEMA_UNINSTALLED) {
- db_drop_table($ret, 'node_counter');
+ db_drop_table('node_counter');
}
- return $ret;
}
/**
@@ -418,30 +410,26 @@ function node_update_7004() {
}
// Delete old variable but leave 'teaser_length' for aggregator module upgrade.
variable_del('node_preview');
-
- return array();
}
/**
* Add status/comment/promote and sticky columns to the {node_revision} table.
*/
function node_update_7005() {
- $ret = array();
foreach(array('status', 'comment', 'promote', 'sticky') as $column) {
- db_add_field($ret, 'node_revision', $column, array(
+ db_add_field('node_revision', $column, array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
));
}
- return $ret;
}
/**
* Convert body and teaser from node properties to fields, and migrate status/comment/promote and sticky columns to the {node_revision} table.
*/
function node_update_7006(&$context) {
- $ret = array('#finished' => 0);
+ $context['#finished'] = 0;
// Get node type info for every invocation.
drupal_static_reset('_node_types_build');
@@ -536,33 +524,29 @@ function node_update_7006(&$context) {
}
}
- $ret['#finished'] = min(0.99, $context['count'] / $context['total']);
+ $context['#finished'] = min(0.99, $context['count'] / $context['total']);
}
if (!$found) {
// All nodes are processed.
- $ret[] = array('success' => TRUE, 'query' => "{$context['total']} node body and teaser properties migrated to the 'body' field.");
// Remove the now-obsolete body info from node_revision.
- db_drop_field($ret, 'node_revision', 'body');
- db_drop_field($ret, 'node_revision', 'teaser');
- db_drop_field($ret, 'node_revision', 'format');
+ db_drop_field('node_revision', 'body');
+ db_drop_field('node_revision', 'teaser');
+ db_drop_field('node_revision', 'format');
// We're done.
- $ret['#finished'] = 1;
+ $context['#finished'] = 1;
+ return t("!number node body and teaser properties migrated to the 'body' field.", array('!number' => $context['total']));
}
}
-
- return $ret;
}
/**
* Remove column min_word_count.
*/
function node_update_7007() {
- $ret = array();
- db_drop_field($ret, 'node_type', 'min_word_count');
- return $ret;
+ db_drop_field('node_type', 'min_word_count');
}
/**
diff --git a/modules/poll/poll.install b/modules/poll/poll.install
index 880b317fc..4bd7a214f 100644
--- a/modules/poll/poll.install
+++ b/modules/poll/poll.install
@@ -141,22 +141,18 @@ function poll_schema() {
* Rename {poll_choices} table to {poll_choice} and {poll_votes} to {poll_vote}.
*/
function poll_update_7001() {
- $ret = array();
- db_rename_table($ret, 'poll_choices', 'poll_choice');
- db_rename_table($ret, 'poll_votes', 'poll_vote');
- return $ret;
+ db_rename_table('poll_choices', 'poll_choice');
+ db_rename_table('poll_votes', 'poll_vote');
}
/**
* Add timestamp field to {poll_votes}.
*/
function poll_update_7002() {
- $ret = array();
$field = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
);
- db_add_field($ret, 'poll_votes', 'timestamp', $field);
- return $ret;
+ db_add_field('poll_votes', 'timestamp', $field);
}
diff --git a/modules/profile/profile.install b/modules/profile/profile.install
index b07780671..153f30959 100644
--- a/modules/profile/profile.install
+++ b/modules/profile/profile.install
@@ -151,8 +151,6 @@ function profile_schema() {
* Rename {profile_fields} table to {profile_field} and {profile_values} to {profile_value}.
*/
function profile_update_7001() {
- $ret = array();
- db_rename_table($ret, 'profile_fields', 'profile_field');
- db_rename_table($ret, 'profile_values', 'profile_value');
- return $ret;
+ db_rename_table('profile_fields', 'profile_field');
+ db_rename_table('profile_values', 'profile_value');
}
diff --git a/modules/search/search.install b/modules/search/search.install
index 5cb6f887b..8582fc0d3 100644
--- a/modules/search/search.install
+++ b/modules/search/search.install
@@ -154,13 +154,10 @@ function search_schema() {
* Replace unique keys in 'search_dataset' and 'search_index' by primary keys.
*/
function search_update_7000() {
- $ret = array();
- db_drop_unique_key($ret, 'search_dataset', 'sid_type');
- db_add_primary_key($ret, 'search_dataset', array('sid', 'type'));
+ db_drop_unique_key('search_dataset', 'sid_type');
+ db_add_primary_key('search_dataset', array('sid', 'type'));
- db_drop_index($ret, 'search_index', 'word');
- db_drop_unique_key($ret, 'search_index', 'word_sid_type');
- db_add_primary_key($ret, 'search_index', array('word', 'sid', 'type'));
-
- return $ret;
+ db_drop_index('search_index', 'word');
+ db_drop_unique_key('search_index', 'word_sid_type');
+ db_add_primary_key('search_index', array('word', 'sid', 'type'));
}
diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php
index 455a1213a..1a49c9b5b 100644
--- a/modules/simpletest/drupal_web_test_case.php
+++ b/modules/simpletest/drupal_web_test_case.php
@@ -1180,7 +1180,7 @@ class DrupalWebTestCase extends DrupalTestCase {
$schema = drupal_get_schema(NULL, TRUE);
$ret = array();
foreach ($schema as $name => $table) {
- db_drop_table($ret, $name);
+ db_drop_table($name);
}
// Return the database prefix to the original.
diff --git a/modules/simpletest/simpletest.module b/modules/simpletest/simpletest.module
index b494622e4..84ce85e71 100644
--- a/modules/simpletest/simpletest.module
+++ b/modules/simpletest/simpletest.module
@@ -413,12 +413,11 @@ function simpletest_clean_environment() {
function simpletest_clean_database() {
$tables = db_find_tables(Database::getConnection()->prefixTables('{simpletest}') . '%');
$schema = drupal_get_schema_unprocessed('simpletest');
- $ret = array();
foreach (array_diff_key($tables, $schema) as $table) {
// Strip the prefix and skip tables without digits following "simpletest",
// e.g. {simpletest_test_id}.
if (preg_match('/simpletest\d+.*/', $table, $matches)) {
- db_drop_table($ret, $matches[0]);
+ db_drop_table($matches[0]);
}
}
diff --git a/modules/simpletest/tests/database_test.test b/modules/simpletest/tests/database_test.test
index 1e3a52fe7..5499cee43 100644
--- a/modules/simpletest/tests/database_test.test
+++ b/modules/simpletest/tests/database_test.test
@@ -40,12 +40,11 @@ class DatabaseTestCase extends DrupalWebTestCase {
*/
function installTables($schema) {
// This ends up being a test for table drop and create, too, which is nice.
- $ret = array();
foreach ($schema as $name => $data) {
if (db_table_exists($name)) {
- db_drop_table($ret, $name);
+ db_drop_table($name);
}
- db_create_table($ret, $name, $data);
+ db_create_table($name, $data);
}
foreach ($schema as $name => $data) {
@@ -1369,14 +1368,14 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$query_1->union($query_2);
$names = $query_1->execute()->fetchCol();
-
+
// Ensure we only get 2 records.
$this->assertEqual(count($names), 2, t('UNION correctly discarded duplicates.'));
$this->assertEqual($names[0], 'George', t('First query returned correct name.'));
$this->assertEqual($names[1], 'Ringo', t('Second query returned correct name.'));
}
-
+
/**
* Test that we can UNION ALL multiple Select queries together.
*/
@@ -1384,7 +1383,7 @@ class DatabaseSelectTestCase extends DatabaseTestCase {
$query_1 = db_select('test', 't')
->fields('t', array('name'))
->condition('age', array(27, 28), 'IN');
-
+
$query_2 = db_select('test', 't')
->fields('t', array('name'))
->condition('age', 28);
@@ -2904,9 +2903,8 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
),
),
);
- $ret = array();
- db_create_table($ret, 'date_table', $date_table);
- $this->assertEqual($ret[0]['success'], 1, t('Created table with date field'));
+ db_create_table('date_table', $date_table);
+ $this->assertTrue(db_table_exists('date_table'), t('Created table with date field'));
db_insert('date_table')->fields(array('date_field'))
->values(array('date_field' => '2001-01-01'))
@@ -2926,8 +2924,8 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
$this->assertEqual($date, '2100-06-30', t('Date retrieved in order @date', array('@date' => $date)));
- db_drop_table($ret, 'date_table');
- $this->assertEqual($ret[1]['success'], 1, t('Dropped table with date field'));
+ db_drop_table('date_table');
+ $this->assertFalse(db_table_exists('date_table'), t('Dropped table with date field'));
} catch (Exception $e) {
$this->fail($e->getMessage());
@@ -2949,9 +2947,8 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
),
),
);
- $ret = array();
- db_create_table($ret, 'time_table', $time_table);
- $this->assertEqual($ret[0]['success'], 1, t('Created table with time field'));
+ db_create_table('time_table', $time_table);
+ $this->assertTrue(db_table_exists('time_table'), t('Created table with time field'));
db_insert('time_table')->fields(array('time_field'))
->values(array('time_field' => '12:59:00'))
@@ -2970,8 +2967,8 @@ class DatabaseExtraTypesTestCase extends DrupalWebTestCase {
$time = $res->fetch()->time_field;
$this->assertEqual($time, '23:17:00', t('Time retrieved in order @time', array('@time' => $time)));
- db_drop_table($ret, 'time_table');
- $this->assertEqual($ret[1]['success'], 1, t('Dropped table with time field'));
+ db_drop_table('time_table');
+ $this->assertFalse(db_table_exists('time_table'), t('Dropped table with time field'));
} catch (Exception $e) {
$this->fail($e->getMessage());
}
diff --git a/modules/simpletest/tests/field_test.module b/modules/simpletest/tests/field_test.module
index 93b8084e5..6d463daee 100644
--- a/modules/simpletest/tests/field_test.module
+++ b/modules/simpletest/tests/field_test.module
@@ -1115,9 +1115,9 @@ function field_test_memorize($key = NULL, $value = NULL) {
$memorize = &drupal_static(__FUNCTION__, NULL);
if (is_null($key)) {
- $ret = $memorize;
+ $return = $memorize;
$memorize = array();
- return $ret;
+ return $return;
}
if (is_array($memorize)) {
$memorize[$key][] = $value;
diff --git a/modules/simpletest/tests/schema.test b/modules/simpletest/tests/schema.test
index 3054a1e7c..da48b9395 100644
--- a/modules/simpletest/tests/schema.test
+++ b/modules/simpletest/tests/schema.test
@@ -37,8 +37,7 @@ class SchemaTestCase extends DrupalWebTestCase {
),
),
);
- $ret = array();
- db_create_table($ret, 'test_table', $table_specification);
+ db_create_table('test_table', $table_specification);
// Assert that the table exists.
$this->assertTrue(db_table_exists('test_table'), t('The table exists.'));
@@ -53,19 +52,19 @@ class SchemaTestCase extends DrupalWebTestCase {
$this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
// Add a default value to the column.
- db_field_set_default($ret, 'test_table', 'test_field', 0);
+ db_field_set_default('test_table', 'test_field', 0);
// The insert should now succeed.
$this->assertTrue($this->tryInsert(), t('Insert with a default succeeded.'));
// Remove the default.
- db_field_set_no_default($ret, 'test_table', 'test_field');
+ db_field_set_no_default('test_table', 'test_field');
// The insert should fail again.
$this->assertFalse($this->tryInsert(), t('Insert without a default failed.'));
// Rename the table.
- db_rename_table($ret, 'test_table', 'test_table2');
+ db_rename_table('test_table', 'test_table2');
// We need the default so that we can insert after the rename.
- db_field_set_default($ret, 'test_table2', 'test_field', 0);
+ db_field_set_default('test_table2', 'test_field', 0);
$this->assertFalse($this->tryInsert(), t('Insert into the old table failed.'));
$this->assertTrue($this->tryInsert('test_table2'), t('Insert into the new table succeeded.'));
@@ -74,19 +73,19 @@ class SchemaTestCase extends DrupalWebTestCase {
$this->assertEqual($count, 2, t('Two fields were successfully inserted.'));
// Try to drop the table.
- db_drop_table($ret, 'test_table2');
+ db_drop_table('test_table2');
$this->assertFalse(db_table_exists('test_table2'), t('The dropped table does not exist.'));
// Recreate the table.
- db_create_table($ret, 'test_table', $table_specification);
- db_field_set_default($ret, 'test_table', 'test_field', 0);
- db_add_field($ret, 'test_table', 'test_serial', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Added column description.'));
+ db_create_table('test_table', $table_specification);
+ db_field_set_default('test_table', 'test_field', 0);
+ db_add_field('test_table', 'test_serial', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'description' => 'Added column description.'));
// Assert that the column comment has been set.
$this->checkSchemaComment('Added column description.', 'test_table', 'test_serial');
// Change the new field to a serial column.
- db_change_field($ret, 'test_table', 'test_serial', 'test_serial', array('type' => 'serial', 'not null' => TRUE, 'description' => 'Changed column description.'), array('primary key' => array('test_serial')));
+ db_change_field('test_table', 'test_serial', 'test_serial', array('type' => 'serial', 'not null' => TRUE, 'description' => 'Changed column description.'), array('primary key' => array('test_serial')));
// Assert that the column comment has been set.
$this->checkSchemaComment('Changed column description.', 'test_table', 'test_serial');
diff --git a/modules/statistics/statistics.install b/modules/statistics/statistics.install
index 396faab80..5fd499707 100644
--- a/modules/statistics/statistics.install
+++ b/modules/statistics/statistics.install
@@ -142,9 +142,7 @@ function statistics_schema() {
* Allow longer referrers.
*/
function statistics_update_7000() {
- $ret = array();
- db_change_field($ret, 'accesslog', 'url', 'url', array('type' => 'text', 'not null' => FALSE));
- return $ret;
+ db_change_field('accesslog', 'url', 'url', array('type' => 'text', 'not null' => FALSE));
}
/**
diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 559d64761..c49f1e95c 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -684,7 +684,7 @@ function hook_image_toolkits() {
* An array containing the message data. Keys in this array include:
* - 'id':
* The drupal_mail() id of the message. Look at module source code or
- * drupal_mail() for possible id values.
+ * drupal_mail() for possible id values.
* - 'to':
* The address or addresses the message will be sent to. The
* formatting of this string must comply with RFC 2822.
@@ -696,7 +696,7 @@ function hook_image_toolkits() {
* characters, or the email may not be sent properly.
* - 'body':
* An array of strings containing the message text. The message body is
- * created by concatenating the individual array strings into a single text
+ * created by concatenating the individual array strings into a single text
* string using "\n\n" as a separator.
* - 'headers':
* Associative array containing mail headers, such as From, Sender,
@@ -1897,30 +1897,28 @@ function hook_install() {
* If your update task is potentially time-consuming, you'll need to implement a
* multipass update to avoid PHP timeouts. Multipass updates use the $sandbox
* parameter provided by the batch API (normally, $context['sandbox']) to store
- * information between successive calls, and the $ret['#finished'] return value
+ * information between successive calls, and the $sandbox['#finished'] value
* to provide feedback regarding completion level.
*
* See the batch operations page for more information on how to use the batch API:
* @link http://drupal.org/node/146843 http://drupal.org/node/146843 @endlink
*
- * @return An array with the results of the calls to update_sql(). An upate
- * function can force the current and all later updates for this
- * module to abort by returning a $ret array with an element like:
- * $ret['#abort'] = array('success' => FALSE, 'query' => 'What went wrong');
- * The schema version will not be updated in this case, and all the
- * aborted updates will continue to appear on update.php as updates that
- * have not yet been run. Multipass update functions will also want to pass
- * back the $ret['#finished'] variable to inform the batch API of progress.
+ * @throws DrupalUpdateException, PDOException
+ * In case of error, update hooks should throw an instance of DrupalUpdateException
+ * with a meaningful message for the user. If a database query fails for whatever
+ * reason, it will throw a PDOException.
+ *
+ * @return
+ * Optionally update hooks may return a translated string that will be displayed
+ * to the user. If no message is returned, no message will be presented to the
+ * user.
*/
function hook_update_N(&$sandbox = NULL) {
// For most updates, the following is sufficient.
- $ret = array();
- db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.'));
- return $ret;
+ db_add_field('mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE, 'description' => 'My new integer column.'));
// However, for more complex operations that may take a long time,
// you may hook into Batch API as in the following example.
- $ret = array();
// Update 3 users at a time to have an exclamation point after their names.
// (They're really happy that we can do batch API in this hook!)
@@ -1938,15 +1936,23 @@ function hook_update_N(&$sandbox = NULL) {
->execute();
foreach ($users as $user) {
$user->name .= '!';
- $ret[] = update_sql("UPDATE {users} SET name = '$user->name' WHERE uid = $user->uid");
+ db_update('users')
+ ->fields(array('name' => $user->name))
+ ->condition('uid', $user->uid)
+ ->execute();
$sandbox['progress']++;
$sandbox['current_uid'] = $user->uid;
}
- $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+ $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+
+ // To display a message to the user when the update is completed, return it.
+ // If you do not want to display a completion message, simply return nothing.
+ return t('The update did what it was supposed to do.');
- return $ret;
+ // In case of an error, simply throw an exception with an error message.
+ throw new DrupalUpdateException('Something went wrong; here is what you should do.');
}
/**
diff --git a/modules/system/system.install b/modules/system/system.install
index 3245fc303..0f337467e 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -1527,7 +1527,6 @@ function system_update_last_removed() {
* Rename blog and forum permissions to be consistent with other content types.
*/
function system_update_7000() {
- $ret = array();
$result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
foreach ($result as $role) {
$renamed_permission = preg_replace('/(?<=^|,\ )create\ blog\ entries(?=,|$)/', 'create blog content', $role->perm);
@@ -1543,28 +1542,25 @@ function system_update_7000() {
$renamed_permission = preg_replace('/(?<=^|,\ )edit\ own\ forum\ topics(?=,|$)/', 'edit own forum content', $role->perm);
if ($renamed_permission != $role->perm) {
- $ret[] = update_sql("UPDATE {permission} SET perm = '$renamed_permission' WHERE rid = $role->rid");
+ db_update('permission')
+ ->fields(array('perm' => $renamed_permission))
+ ->condition('rid', $role->rid)
+ ->execute();
}
}
-
- return $ret;
}
/**
* Generate a cron key and save it in the variables table.
*/
function system_update_7001() {
- $ret = array();
variable_set('cron_key', md5(mt_rand()));
- $ret[] = array('success' => TRUE, 'query' => "variable_set('cron_key')");
- return $ret;
}
/**
* Add a table to store blocked IP addresses.
*/
function system_update_7002() {
- $ret = array();
$schema['blocked_ips'] = array(
'description' => 'Stores blocked IP addresses.',
'fields' => array(
@@ -1588,16 +1584,14 @@ function system_update_7002() {
'primary key' => array('iid'),
);
- db_create_table($ret, 'blocked_ips', $schema['blocked_ips']);
-
- return $ret;
+ db_create_table('blocked_ips', $schema['blocked_ips']);
}
/**
* Update {blocked_ips} with valid IP addresses from {access}.
*/
function system_update_7003() {
- $ret = array();
+ $messages = array();
$type = 'host';
$result = db_query("SELECT mask FROM {access} WHERE status = :status AND type = :type", array(
':status' => 0,
@@ -1605,16 +1599,17 @@ function system_update_7003() {
));
foreach ($result as $blocked) {
if (filter_var($blocked->mask, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE) !== FALSE) {
- $ret[] = update_sql("INSERT INTO {blocked_ips} (ip) VALUES ('$blocked->mask')");
+ db_insert('blocked_ips')
+ ->fields(array('ip' => $blocked->mask))
+ ->execute();
}
else {
$invalid_host = check_plain($blocked->mask);
- $ret[] = array('success' => TRUE, 'query' => 'The host ' . $invalid_host . ' is no longer blocked because it is not a valid IP address.');
+ $messages[] = t('The host !host is no longer blocked because it is not a valid IP address.', array('!host' => $invalid_host ));
}
}
if (isset($invalid_host)) {
drupal_set_message('Drupal no longer supports wildcard IP address blocking. Visitors whose IP addresses match ranges you have previously set using <em>access rules</em> will no longer be blocked from your site when you put the site online. See the <a href="http://drupal.org/node/24302">IP address and referrer blocking Handbook page</a> for alternative methods.', 'warning');
- $ret[] = array('success' => TRUE, 'query' => '');
}
// Make sure not to block any IP addresses that were specifically allowed by access rules.
if (!empty($result)) {
@@ -1622,19 +1617,22 @@ function system_update_7003() {
':status' => 1,
':type' => $type,
));
+ $or = db_condition('or');
foreach ($result as $allowed) {
- $ret[] = update_sql("DELETE FROM {blocked_ips} WHERE LOWER(ip) LIKE LOWER('$allowed->mask')");
+ $or->where('LOWER(ip) LIKE LOWER(:mask)', array(':mask' => $allowed->mask));
+ }
+ if (count($or)) {
+ db_delete('blocked_ips')
+ ->condition($or)
+ ->execute();
}
}
-
- return $ret;
}
/**
* Remove hardcoded numeric deltas from all blocks in core.
*/
function system_update_7004(&$sandbox) {
- $ret = array();
// Get an array of the renamed block deltas, organized by module.
$renamed_deltas = array(
'blog' => array('0' => 'recent'),
@@ -1672,7 +1670,11 @@ function system_update_7004(&$sandbox) {
))
->fetchField();
if ($block_exists) {
- $ret[] = update_sql("UPDATE {" . $table . "} SET delta = '" . $new_delta . "' WHERE module = '" . $module . "' AND delta = '" . $old_delta . "'");
+ db_update($table)
+ ->fields(array('delta' => $new_delta))
+ ->condition('module', $module)
+ ->condition('delta', $old_delta)
+ ->execute();
}
}
}
@@ -1728,24 +1730,20 @@ function system_update_7004(&$sandbox) {
}
// Indicate our current progress to the batch update system.
if ($sandbox['progress'] < $sandbox['max']) {
- $ret['#finished'] = $sandbox['progress'] / $sandbox['max'];
+ $sandbox['#finished'] = $sandbox['progress'] / $sandbox['max'];
}
- return $ret;
}
/**
* Remove throttle columns and variables.
*/
function system_update_7005() {
- $ret = array();
- db_drop_field($ret, 'blocks', 'throttle');
- db_drop_field($ret, 'system', 'throttle');
+ db_drop_field('blocks', 'throttle');
+ db_drop_field('system', 'throttle');
variable_del('throttle_user');
variable_del('throttle_anonymous');
variable_del('throttle_level');
variable_del('throttle_probability_limiter');
-
- return $ret;
}
/**
@@ -1753,7 +1751,6 @@ function system_update_7005() {
* longer needed.
*/
function system_update_7006() {
- $ret = array();
$schema['registry'] = array(
'fields' => array(
'name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
@@ -1787,11 +1784,10 @@ function system_update_7006() {
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
- db_create_table($ret, 'cache_registry', $schema['cache_registry']);
- db_create_table($ret, 'registry', $schema['registry']);
- db_create_table($ret, 'registry_file', $schema['registry_file']);
+ db_create_table('cache_registry', $schema['cache_registry']);
+ db_create_table('registry', $schema['registry']);
+ db_create_table('registry_file', $schema['registry_file']);
registry_rebuild();
- return $ret;
}
/**
@@ -1801,8 +1797,6 @@ function system_update_7006() {
* all modules can use the updated permission scheme during their updates.
*/
function system_update_7007() {
- $ret = array();
-
$schema['role_permission'] = array(
'fields' => array(
'rid' => array(
@@ -1823,9 +1817,10 @@ function system_update_7007() {
),
);
- db_create_table($ret, 'role_permission', $schema['role_permission']);
+ db_create_table('role_permission', $schema['role_permission']);
// Copy the permissions from the old {permission} table to the new {role_permission} table.
+ $messages = array();
$result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
$query = db_insert('role_permission')->fields(array('rid', 'permission'));
foreach ($result as $role) {
@@ -1835,12 +1830,12 @@ function system_update_7007() {
'permission' => $perm,
));
}
- $ret[] = array('success' => TRUE, 'query' => "Inserted into {role_permission} the permissions for role ID " . $role->rid);
+ $messages[] = t('Inserted into {role_permission} the permissions for role ID !id', array('!id' => $role->rid));
}
$query->execute();
- db_drop_table($ret, 'permission');
+ db_drop_table('permission');
- return $ret;
+ return implode(', ', $messages);
}
@@ -1849,20 +1844,18 @@ function system_update_7007() {
* the choice order. Rename chorder to weight.
*/
function system_update_7008() {
- $ret = array();
if (db_table_exists('poll_votes')) {
// Add chid column and convert existing votes.
- db_add_field($ret, 'poll_votes', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
- db_add_index($ret, 'poll_votes', 'chid', array('chid'));
- $ret[] = update_sql("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid)");
+ db_add_field('poll_votes', 'chid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
+ db_add_index('poll_votes', 'chid', array('chid'));
+ db_query("UPDATE {poll_votes} SET chid = (SELECT chid FROM {poll_choices} c WHERE {poll_votes}.chorder = c.chorder AND {poll_votes}.nid = c.nid)");
// Remove old chorder column.
- db_drop_field($ret, 'poll_votes', 'chorder');
+ db_drop_field('poll_votes', 'chorder');
}
if (db_table_exists('poll_choices')) {
// Change the chorder column to weight in poll_choices.
- db_change_field($ret, 'poll_choices', 'chorder', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
+ db_change_field('poll_choices', 'chorder', 'weight', array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny'));
}
- return $ret;
}
/**
@@ -1870,30 +1863,29 @@ function system_update_7008() {
*
*/
function system_update_7009() {
- $ret = array();
- $ret[] = update_sql("UPDATE {variable} SET name = 'menu_main_links_source' WHERE name = 'menu_primary_links_source'");
-
- return $ret;
+ db_update('variable')
+ ->fields(array('name' => 'main_menu_links_source'))
+ ->condition('name', 'menu_primary_links_source')
+ ->execute();
}
/**
* Moved to system_update_6048().
*/
function system_update_7010() {
- return array();
+ return '';
}
/**
* Split the 'bypass node access' permission from 'administer nodes'.
*/
function system_update_7011() {
- $ret = array();
// Get existing roles that can 'administer nodes'.
$rids = array();
$rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer nodes'))->fetchCol();
// None found.
if (empty($rids)) {
- return $ret;
+ return;
}
$insert = db_insert('role_permission')->fields(array('rid', 'permission'));
foreach ($rids as $rid) {
@@ -1903,7 +1895,6 @@ function system_update_7011() {
));
}
$insert->execute();
- return $ret;
}
/**
@@ -1911,18 +1902,15 @@ function system_update_7011() {
* {boxes} to {box}.
*/
function system_update_7012() {
- $ret = array();
- db_rename_table($ret, 'blocks', 'block');
- db_rename_table($ret, 'blocks_roles', 'block_role');
- db_rename_table($ret, 'boxes', 'box');
- return $ret;
+ db_rename_table('blocks', 'block');
+ db_rename_table('blocks_roles', 'block_role');
+ db_rename_table('boxes', 'box');
}
/**
* Convert default time zone offset to default time zone name.
*/
function system_update_7013() {
- $ret = array();
$timezone = NULL;
$timezones = system_time_zones();
// If the contributed Date module set a default time zone name, use this
@@ -1956,32 +1944,33 @@ function system_update_7013() {
}
variable_set('date_default_timezone', $timezone);
drupal_set_message('The default time zone has been set to <em>' . check_plain($timezone) . '</em>. Please check the ' . l('date and time configuration page', 'admin/config/regional/settings') . ' to configure it correctly.', 'warning');
- return $ret;
}
/**
* Drop the bootstrap column from the {system} table. This was reverted.
*/
function system_update_7014() {
- $ret = array();
- return $ret;
}
/**
* Change the user logout path.
*/
function system_update_7015() {
- $ret = array();
- $ret[] = update_sql("UPDATE {menu_links} SET link_path = 'user/logout' WHERE link_path = 'logout'");
- $ret[] = update_sql("UPDATE {menu_links} SET router_path = 'user/logout' WHERE router_path = 'logout'");
- return $ret;
+ db_update('menu_links')
+ ->fields(array('link_path' => 'user/logout'))
+ ->condition('link_path', 'logout')
+ ->execute();
+
+ db_update('menu_links')
+ ->fields(array('router_path' => 'user/logout'))
+ ->condition('router_path', 'logout')
+ ->execute();
}
/**
* Remove custom datatype *_unsigned in PostgreSQL.
*/
function system_update_7016() {
- $ret = array();
// Only run these queries if the driver used is pgsql.
if (db_driver() == 'pgsql') {
$result = db_query("SELECT c.relname AS table, a.attname AS field,
@@ -2001,28 +1990,25 @@ function system_update_7016() {
$datatype = 'bigint';
break;
}
- $ret[] = update_sql('ALTER TABLE ' . $row->table . ' ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype);
- $ret[] = update_sql('ALTER TABLE ' . $row->table . ' ADD CHECK (' . $row->field . ' >= 0)');
+ db_query('ALTER TABLE ' . $row->table . ' ALTER COLUMN ' . $row->field . ' TYPE ' . $datatype);
+ db_query('ALTER TABLE ' . $row->table . ' ADD CHECK (' . $row->field . ' >= 0)');
}
- $ret[] = update_sql('DROP DOMAIN smallint_unsigned');
- $ret[] = update_sql('DROP DOMAIN int_unsigned');
- $ret[] = update_sql('DROP DOMAIN bigint_unsigned');
+ db_query('DROP DOMAIN smallint_unsigned');
+ db_query('DROP DOMAIN int_unsigned');
+ db_query('DROP DOMAIN bigint_unsigned');
}
- return $ret;
}
/**
* Change the theme setting 'toggle_node_info' into a per content type variable.
*/
function system_update_7017() {
- $ret = array();
$types = node_type_get_types();
if (count($types)) {
foreach ($types as $type) {
$node_info = theme_get_setting('toggle_node_info_' . $type->type);
if ($node_info !== NULL) {
variable_set('node_submitted_' . $type->type, $node_info);
- $ret[] = array('success' => TRUE, 'query' => "variable_set('node_submitted_$type->type')");
}
}
}
@@ -2035,85 +2021,148 @@ function system_update_7017() {
}
}
variable_set('theme_settings', $theme_settings);
- $ret[] = array('success' => TRUE, 'query' => "variable_set('theme_settings')");
-
- return $ret;
}
/**
* Shorten the {system}.type column and add an index on type and name.
*/
function system_update_7018() {
- $ret = array();
- db_drop_index($ret, 'system', 'modules');
- db_drop_index($ret, 'system', 'type_name');
- db_change_field($ret, 'system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
- db_add_index($ret, 'system', 'modules', array('type', 'status', 'weight', 'name'));
- db_add_index($ret, 'system', 'type_name', array('type', 'name'));
- return $ret;
+ db_drop_index('system', 'modules');
+ db_drop_index('system', 'type_name');
+ db_change_field('system', 'type', 'type', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
+ db_add_index('system', 'modules', array('type', 'status', 'weight', 'name'));
+ db_add_index('system', 'type_name', array('type', 'name'));
}
/**
* Enable field module.
*/
function system_update_7020() {
- $ret = array();
$module_list = array('field_sql_storage', 'field');
drupal_install_modules($module_list);
module_enable($module_list);
- return $ret;
}
/**
* Add new blocks to new regions, migrate custom variables to blocks.
*/
function system_update_7021() {
- $ret = array();
-
// Collect a list of themes with blocks.
$themes_with_blocks = array();
$result = db_query("SELECT s.name FROM {system} s INNER JOIN {block} b ON s.name = b.theme WHERE s.type = 'theme' GROUP by s.name");
+
+ $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($result as $theme) {
$themes_with_blocks[] = $theme->name;
// Add new system generated help block.
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('system', 'help', '" . $theme->name . "', 1, 0, 'help', '', 1)");
+ $insert->values(array(
+ 'module' => 'system',
+ 'delta' => 'help',
+ 'theme' => $theme->name,
+ 'status' => 1,
+ 'weight' => 0,
+ 'region' => 'help',
+ 'pages' => '',
+ 'cache' => 1,
+ ));
// Add new system generated main page content block.
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('system', 'main', '" . $theme->name . "', 1, 0, 'content', '', -1)");
+ $insert->values(array(
+ 'module' => 'system',
+ 'delta' => 'main',
+ 'theme' => $theme->name,
+ 'status' => 1,
+ 'weight' => 0,
+ 'region' => 'content',
+ 'pages' => '',
+ 'cache' => -1,
+ ));
}
+ $insert->execute();
// Migrate blocks from left/right regions to first/second regions.
- $ret[] = update_sql("UPDATE {block} SET region = 'sidebar_first' WHERE region = 'left'");
- $ret[] = update_sql("UPDATE {block} SET region = 'sidebar_second' WHERE region = 'right'");
+ db_update('block')
+ ->fields(array('region' => 'sidebar_first'))
+ ->condition('region', 'left')
+ ->execute();
+ db_update('block')
+ ->fields(array('region' => 'sidebar_second'))
+ ->condition('region', 'right')
+ ->execute();
// Migrate contact form information.
$default_format = variable_get('filter_default_format', 1);
if ($contact_help = variable_get('contact_form_information', '')) {
- $bid = db_insert('box')->fields(array('body' => $contact_help, 'info' => 'Contact page help', 'format' => $default_format))->execute();
+ $bid = db_insert('box')
+ ->fields(array(
+ 'body' => $contact_help,
+ 'info' => 'Contact page help',
+ 'format' => $default_format,
+ ))
+ ->execute();
+
+ $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'visibility', 'pages', 'cache'));
foreach ($themes_with_blocks as $theme) {
// Add contact help block for themes, which had blocks.
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 5, 'help', 1, 'contact', -1)");
+ $insert->values(array(
+ 'module' => 'block',
+ 'delta' => $bid,
+ 'theme' => $theme,
+ 'status' => 1,
+ 'weight' => 5,
+ 'region' => 'help',
+ 'visibility' => 1,
+ 'pages' => 'contact',
+ 'cache' => -1,
+ ));
}
drupal_set_message('The contact form information setting was migrated to <a href="' . url('admin/structure/block/configure/block/' . $bid) . '">a custom block</a> and set up to only show on the site-wide contact page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
}
+ $insert->execute();
// Migrate user help setting.
if ($user_help = variable_get('user_registration_help', '')) {
$bid = db_insert('box')->fields(array('body' => $user_help, 'info' => 'User registration guidelines', 'format' => $default_format))->execute();
+
+ $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'visibility', 'pages', 'cache'));
foreach ($themes_with_blocks as $theme) {
// Add user registration help block for themes, which had blocks.
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 5, 'help', 1, 'user/register', -1)");
+ $insert->values(array(
+ 'module' => 'block',
+ 'delta' => $bid,
+ 'theme' => $theme,
+ 'status' => 1,
+ 'weight' => 5,
+ 'region' => 'help',
+ 'visibility' => 1,
+ 'pages' => 'user/register',
+ 'cache' => -1,
+ ));
}
drupal_set_message('The user registration guidelines were migrated to <a href="' . url('admin/structure/block/configure/block/' . $bid) . '">a custom block</a> and set up to only show on the user registration page. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right.');
+ $insert->execute();
}
// Migrate site mission setting.
if ($mission = variable_get('site_mission')) {
$bid = db_insert('box')->fields(array('body' => $mission, 'info' => 'Site mission', 'format' => $default_format))->execute();
+
+ $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'visibility', 'pages', 'cache'));
foreach ($themes_with_blocks as $theme) {
// Add mission block for themes, which had blocks.
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, visibility, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, 0, 'highlight', 1, '<front>', -1)");
+ $insert->values(array(
+ 'module' => 'block',
+ 'delta' => $bid,
+ 'theme' => $theme,
+ 'status' => 1,
+ 'weight' => 0,
+ 'region' => 'highlight',
+ 'visibility' => 1,
+ 'pages' => '<front>',
+ 'cache' => -1,
+ ));
}
drupal_set_message('The site mission was migrated to <a href="' . url('admin/structure/block/configure/block/' . $bid) . '">a custom block</a> and set up to only show on the front page in the highlighted content region. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a highlighted content region, you might need to <a href="' . url('admin/structure/block') . '">relocate the block</a>.');
+ $insert->execute();
// Migrate mission to RSS site description.
variable_set('feed_description', $mission);
}
@@ -2121,13 +2170,25 @@ function system_update_7021() {
// Migrate site footer message to a custom block.
if ($footer_message = variable_get('site_footer', '')) {
$bid = db_insert('box')->fields(array('body' => $footer_message, 'info' => 'Footer message', 'format' => $default_format))->execute();
+
+ $insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($themes_with_blocks as $theme) {
// Add site footer block for themes, which had blocks.
// Set low weight, so the block comes early (it used to be
// before the other blocks).
- $ret[] = update_sql("INSERT INTO {block} (module, delta, theme, status, weight, region, pages, cache) VALUES ('block', '" . $bid . "', '" . $theme . "', 1, -10, 'footer', '', -1)");
+ $insert->values(array(
+ 'module' => 'block',
+ 'delta' => $bid,
+ 'theme' => $theme,
+ 'status' => 1,
+ 'weight' => -10,
+ 'region' => 'footer',
+ 'pages' => '',
+ 'cache' => -1,
+ ));
}
drupal_set_message('The footer message was migrated to <a href="' . url('admin/structure/block/configure/block/' . $bid) . '">a custom block</a> and set up to appear in the footer. The block was set to use the default text format, which might differ from the HTML based format used before. Please check the block and ensure that the output is right. If your theme does not have a footer region, you might need to <a href="' . url('admin/structure/block') . '">relocate the block</a>.');
+ $insert->execute();
}
// Remove the variables (even if they were saved empty on the admin interface),
@@ -2139,16 +2200,12 @@ function system_update_7021() {
// Rebuild theme data, so the new 'help' region is identified.
system_get_theme_data();
-
- return $ret;
}
/**
* Add the queue tables.
*/
function system_update_7022() {
- $ret = array();
-
$schema['queue'] = array(
'description' => 'Stores items in queues.',
'fields' => array(
@@ -2209,19 +2266,19 @@ function system_update_7022() {
),
'primary key' => array('consumer_id'),
);
- db_create_table($ret, 'queue', $schema['queue']);
- db_create_table($ret, 'queue_consumer_id', $schema['queue_consumer_id']);
- return $ret;
+ db_create_table('queue', $schema['queue']);
+ db_create_table('queue_consumer_id', $schema['queue_consumer_id']);
}
/**
* Change the PHP for settings permission.
*/
function system_update_7023() {
- $ret = array();
- $ret[] = update_sql("UPDATE {role_permission} SET permission = 'use PHP for settings' WHERE permission = 'use PHP for block visibility'");
- return $ret;
+ db_update('role_permission')
+ ->fields(array('permission' => 'use PHP for settings'))
+ ->condition('permission', 'use PHP for block visibility')
+ ->execute();
}
/**
@@ -2231,28 +2288,22 @@ function system_update_7023() {
* for driver-specific updates yet.
*/
function system_update_7024() {
- $ret = array();
-
if (db_driver() == 'pgsql') {
- $ret[] = update_sql('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
+ db_query('CREATE OR REPLACE FUNCTION "substring_index"(text, text, integer) RETURNS text AS
\'SELECT array_to_string((string_to_array($1, $2)) [1:$3], $2);\'
LANGUAGE \'sql\''
);
}
-
- return $ret;
}
/**
* Improve indexes on the {url_alias} table.
*/
function system_update_7025() {
- $ret = array();
- db_drop_index($ret, 'url_alias', 'src_language');
- db_drop_index($ret, 'url_alias', 'dst_language');
- db_add_index($ret, 'url_alias', 'dst_language_pid', array('dst', 'language', 'pid'));
- db_add_index($ret, 'url_alias', 'src_language_pid', array('src', 'language', 'pid'));
- return $ret;
+ db_drop_index('url_alias', 'src_language');
+ db_drop_index('url_alias', 'dst_language');
+ db_add_index('url_alias', 'dst_language_pid', array('dst', 'language', 'pid'));
+ db_add_index('url_alias', 'src_language_pid', array('src', 'language', 'pid'));
}
/**
@@ -2260,38 +2311,34 @@ function system_update_7025() {
*
*/
function system_update_7026() {
- $ret = array();
- db_change_field($ret, 'url_alias', 'src', 'src', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
- db_change_field($ret, 'url_alias', 'dst', 'dst', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
- return $ret;
+ db_change_field('url_alias', 'src', 'src', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
+ db_change_field('url_alias', 'dst', 'dst', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE));
}
/**
* Enable field type modules.
*/
function system_update_7027() {
- $ret = array();
$module_list = array('text', 'number', 'list', 'options');
- db_delete('system')->condition('type', 'module')->condition('name', $module_list)->execute();
+ db_delete('system')
+ ->condition('type', 'module')
+ ->condition('name', $module_list)
+ ->execute();
drupal_install_modules($module_list);
module_enable($module_list);
- return $ret;
}
/**
* Rename taxonomy tables.
*/
function system_update_7028() {
- $ret = array();
- db_rename_table($ret, 'term_data', 'taxonomy_term_data');
- db_rename_table($ret, 'term_hierarchy', 'taxonomy_term_hierarchy');
- db_rename_table($ret, 'term_node', 'taxonomy_term_node');
- db_rename_table($ret, 'term_relation', 'taxonomy_term_relation');
- db_rename_table($ret, 'term_synonym', 'taxonomy_term_synonym');
- db_rename_table($ret, 'vocabulary', 'taxonomy_vocabulary');
- db_rename_table($ret, 'vocabulary_node_types', 'taxonomy_vocabulary_node_type');
-
- return $ret;
+ db_rename_table('term_data', 'taxonomy_term_data');
+ db_rename_table('term_hierarchy', 'taxonomy_term_hierarchy');
+ db_rename_table('term_node', 'taxonomy_term_node');
+ db_rename_table('term_relation', 'taxonomy_term_relation');
+ db_rename_table('term_synonym', 'taxonomy_term_synonym');
+ db_rename_table('vocabulary', 'taxonomy_vocabulary');
+ db_rename_table('vocabulary_node_types', 'taxonomy_vocabulary_node_type');
}
/**
@@ -2299,62 +2346,51 @@ function system_update_7028() {
* Preserves legacy behavior from Drupal 6.x.
*/
function system_update_7029() {
- $ret = array();
db_insert('role_permission')
->fields(array(
'rid' => DRUPAL_AUTHENTICATED_RID,
'permission' => 'view own unpublished content',
))
->execute();
- return $ret;
}
/**
* Add an index to node_comment_statistics on comment_count.
*/
function system_update_7030() {
- $ret = array();
- db_add_index($ret, 'node_comment_statistics', 'comment_count', array('comment_count'));
- return $ret;
+ db_add_index('node_comment_statistics', 'comment_count', array('comment_count'));
}
/**
* Add a missing index on the {menu_router} table.
*/
function system_update_7031() {
- $ret = array();
- db_add_index($ret, 'menu_router', 'tab_root_weight_title', array(array('tab_root', 64), 'weight', 'title'));
- return $ret;
+ db_add_index('menu_router', 'tab_root_weight_title', array(array('tab_root', 64), 'weight', 'title'));
}
/**
* Alter field hostname to identifier in the {flood} table.
*/
function system_update_7032() {
- $ret = array();
- db_drop_index($ret, 'flood', 'allow');
- db_change_field($ret, 'flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
- db_add_index($ret, 'flood', 'allow', array('event', 'identifier', 'timestamp'));
- return $ret;
+ db_drop_index('flood', 'allow');
+ db_change_field('flood', 'hostname', 'identifier', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
+ db_add_index('flood', 'allow', array('event', 'identifier', 'timestamp'));
}
/**
* Move CACHE_AGGRESSIVE to CACHE_NORMAL.
*/
function system_update_7033() {
- $ret = array();
if (variable_get('cache') == 2) {
variable_set('cache', CACHE_NORMAL);
- $ret[] = array('success' => TRUE, 'query' => "Aggressive caching was disabled and replaced with normal caching, please read the page caching section in default.settings.php for more information on how to enable similar functionality.");
+ return t('Aggressive caching was disabled and replaced with normal caching, please read the page caching section in default.settings.php for more information on how to enable similar functionality.');
}
- return $ret;
}
/**
* Migrate the file_downloads setting and create the new {file} table.
*/
function system_update_7034() {
- $ret = array();
$files_directory = variable_get('file_directory_path', NULL);
if (variable_get('file_downloads', 1) == 1) {
// Our default is public, so we don't need to set anything.
@@ -2438,18 +2474,18 @@ function system_update_7034() {
),
'primary key' => array('fid'),
);
- db_create_table($ret, 'file', $schema['file']);
- return $ret;
+
+ db_create_table('file', $schema['file']);
}
/**
* Migrate upload module files to the new {file} table.
*/
function system_update_7035() {
- $ret = array();
if (!db_table_exists('upload')) {
- return $ret;
+ return;
}
+
// The old {files} tables still exists. We migrate core data from upload
// module, but any contrib module using it will need to do its own update.
$result = db_query('SELECT fid, uid, filename, filepath AS uri, filemime, filesize, status, timestamp FROM {files} f INNER JOIN {upload} u ON u.fid = f.fid', array(), array('fetch' => PDO::FETCH_ASSOC));
@@ -2459,7 +2495,7 @@ function system_update_7035() {
$basename = variable_get('file_directory_path', conf_path() . '/files');
$scheme = variable_get('file_default_scheme', 'public') . '://';
$fids = array();
- // TODO: does this function need to run in batch mode?
+ // TODO: does this function need to run in batch mode, or should we use a multi-insert?
foreach ($result as $file) {
$file['uri'] = $scheme . str_replace($basename, '', $file['uri']);
$file['uri'] = file_stream_wrapper_uri_normalize($file['uri']);
@@ -2467,19 +2503,17 @@ function system_update_7035() {
$fids[] = $file['fid'];
}
// TODO: delete the found fids from {files}?
- return $ret;
}
/**
* Split the 'access site in maintenance mode' permission from 'administer site configuration'.
*/
function system_update_7036() {
- $ret = array();
// Get existing roles that can 'administer site configuration'.
$rids = db_query("SELECT rid FROM {role_permission} WHERE permission = :perm", array(':perm' => 'administer site configuration'))->fetchCol();
// None found.
if (empty($rids)) {
- return $ret;
+ return;
}
$insert = db_insert('role_permission')->fields(array('rid', 'permission'));
foreach ($rids as $rid) {
@@ -2493,26 +2527,20 @@ function system_update_7036() {
// Remove obsolete variable 'site_offline_message'.
// @see update_fix_d7_requirements().
variable_del('site_offline_message');
-
- return $ret;
}
/**
* Rename {box} table to {block_custom}.
*/
function system_update_7037() {
- $ret = array();
- db_rename_table($ret, 'box', 'block_custom');
- return $ret;
+ db_rename_table('box', 'block_custom');
}
/**
* Rename action description to label.
*/
function system_update_7038() {
- $ret = array();
- db_change_field($ret, 'actions', 'description', 'label', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'));
- return $ret;
+ db_change_field('actions', 'description', 'label', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'));
}
/**
diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install
index c4c2a542c..5aaaa4ef2 100644
--- a/modules/taxonomy/taxonomy.install
+++ b/modules/taxonomy/taxonomy.install
@@ -293,7 +293,6 @@ function taxonomy_schema() {
* Add vocabulary machine_name column.
*/
function taxonomy_update_7002() {
- $ret = array();
$field = array(
'type' => 'varchar',
'length' => 255,
@@ -302,7 +301,7 @@ function taxonomy_update_7002() {
'description' => 'The vocabulary machine name.',
);
- db_add_field($ret, 'taxonomy_vocabulary', 'machine_name', $field);
+ db_add_field('taxonomy_vocabulary', 'machine_name', $field);
foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) {
$machine_name = 'vocabulary_' . $vid;
@@ -312,7 +311,6 @@ function taxonomy_update_7002() {
->execute();
field_attach_create_bundle($machine_name);
}
- return $ret;
}
/**
@@ -322,8 +320,5 @@ function taxonomy_update_7002() {
* itself is retained to allow for data to be upgraded.
*/
function taxonomy_update_7003() {
- $ret = array();
- db_drop_field($ret, 'taxonomy_vocabulary', 'relations');
-
- return $ret;
+ db_drop_field('taxonomy_vocabulary', 'relations');
}
diff --git a/modules/tracker/tracker.install b/modules/tracker/tracker.install
index 1ceff152a..7e997a01e 100644
--- a/modules/tracker/tracker.install
+++ b/modules/tracker/tracker.install
@@ -197,16 +197,14 @@ function tracker_update_7000() {
),
);
- $ret = array();
foreach ($schema as $name => $table) {
- db_create_table($ret, $name, $table);
+ db_create_table($name, $table);
}
$max_nid = db_query('SELECT MAX(nid) FROM {node}')->fetchField();
if ($max_nid != 0) {
variable_set('tracker_index_nid', $max_nid);
}
- return $ret;
}
/**
diff --git a/modules/trigger/trigger.install b/modules/trigger/trigger.install
index b8553e48c..95fb4fb2e 100644
--- a/modules/trigger/trigger.install
+++ b/modules/trigger/trigger.install
@@ -54,13 +54,15 @@ function trigger_schema() {
* Adds operation names to the hook names and drops the "op" field.
*/
function trigger_update_7000() {
- $ret = array();
$result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
- while ($row = db_fetch_object($result)) {
- $ret[] = update_sql("UPDATE {trigger_assignments} SET hook = '%s' WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $row->hook . '_' . $row->op, $row->hook, $row->op, $row->aid);
+ foreach ($result as $record) {
+ db_update('trigger_assignments')
+ ->fields(array('hook' => $record->hook . '_' . $record->op))
+ ->condition('hook', $record->hook)
+ ->condition('op', $record->op)
+ ->condition('aid', $record->aid)
+ ->execute();
}
- $ret[] = update_sql("ALTER TABLE {trigger_assignments} DROP op");
-
- return $ret;
+ db_drop_field('trigger_assignments', 'op');
}
diff --git a/modules/upload/upload.install b/modules/upload/upload.install
index 62acef717..87f817f81 100644
--- a/modules/upload/upload.install
+++ b/modules/upload/upload.install
@@ -82,7 +82,6 @@ function upload_schema() {
* Migrate upload module files from {files} to {file}.
*/
function upload_update_7000(&$sandbox) {
- $ret = array();
/*
TODO: Fix the updates. This is broken. See http://drupal.org/node/329301#comment-1404336
@@ -128,8 +127,6 @@ function upload_update_7000(&$sandbox) {
// Indicate our current progress to the batch update system. If there's no
// max value then there's nothing to update and we're finished.
- $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
-
- return $ret;
+ $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
}
diff --git a/modules/user/user.install b/modules/user/user.install
index 889756e96..610d3d566 100644
--- a/modules/user/user.install
+++ b/modules/user/user.install
@@ -255,12 +255,12 @@ function user_schema() {
* lengthy process, and is performed batch-wise.
*/
function user_update_7000(&$sandbox) {
- $ret = array('#finished' => 0);
+ $sandbox['#finished'] = 0;
// Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
$hash_count_log2 = 11;
// Multi-part update.
if (!isset($sandbox['user_from'])) {
- db_change_field($ret, 'users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
+ db_change_field('users', 'pass', 'pass', array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''));
$sandbox['user_from'] = 0;
$sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
}
@@ -283,14 +283,13 @@ function user_update_7000(&$sandbox) {
->execute();
}
}
- $ret['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
+ $sandbox['#finished'] = $sandbox['user_from']/$sandbox['user_count'];
$sandbox['user_from'] += $count;
if (!$has_rows) {
- $ret['#finished'] = 1;
- $ret[] = array('success' => TRUE, 'query' => "UPDATE {users} SET pass = 'U' . user_hash_password(pass) WHERE uid > 0");
+ $sandbox['#finished'] = 1;
+ return t('User passwords rehashed to improve security');
}
}
- return $ret;
}
/**
@@ -300,23 +299,20 @@ function user_update_7000(&$sandbox) {
*/
function user_update_7001() {
- $ret = array();
- db_drop_field($ret, 'users', 'threshold');
- db_drop_field($ret, 'users', 'mode');
- db_drop_field($ret, 'users', 'sort');
-
- return $ret;
+ db_drop_field('users', 'threshold');
+ db_drop_field('users', 'mode');
+ db_drop_field('users', 'sort');
}
/**
* Convert user time zones from time zone offsets to time zone names.
*/
function user_update_7002(&$sandbox) {
- $ret = array('#finished' => 0);
+ $sandbox['#finished'] = 0;
// Multi-part update.
if (!isset($sandbox['user_from'])) {
- db_change_field($ret, 'users', 'timezone', 'timezone', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE));
+ db_change_field('users', 'timezone', 'timezone', array('type' => 'varchar', 'length' => 32, 'not null' => FALSE));
$sandbox['user_from'] = 0;
$sandbox['user_count'] = db_query("SELECT COUNT(uid) FROM {users}")->fetchField();
$sandbox['user_not_migrated'] = 0;
@@ -355,25 +351,30 @@ function user_update_7002(&$sandbox) {
}
}
if ($timezone) {
- db_query("UPDATE {users} SET timezone = :timezone WHERE uid = :uid", array(':timezone' => $timezone, ':uid' => $account->uid));
+ db_update('users')
+ ->fields(array('timezone' => $timezone))
+ ->condition('uid', $account->uid)
+ ->execute();
}
else {
$sandbox['user_not_migrated']++;
- db_query("UPDATE {users} SET timezone = NULL WHERE uid = :uid", array(':uid' => $account->uid));
+ db_update('users')
+ ->fields(array('timezone', NULL))
+ ->condition('uid', $account->uid)
+ ->execute();
}
$sandbox['user_from']++;
}
- $ret['#finished'] = $sandbox['user_from'] / $sandbox['user_count'];
+ $sandbox['#finished'] = $sandbox['user_from'] / $sandbox['user_count'];
if ($sandbox['user_from'] == $sandbox['user_count']) {
- $ret[] = array('success' => TRUE, 'query' => "Migrate user time zones.");
if ($sandbox['user_not_migrated'] > 0) {
variable_set('empty_timezone_message', 1);
drupal_set_message('Some user time zones have been emptied and need to be set to the correct values. Use the new ' . l('time zone options', 'admin/config/regional/settings') . ' to choose whether to remind users at login to set the correct time zone.', 'warning');
}
+ return t('Migrated user time zones');
}
}
- return $ret;
}
/**
@@ -384,7 +385,6 @@ function user_update_7002(&$sandbox) {
* which is the same as the 'user_cancel_reassign' method now.
*/
function user_update_7003() {
- $ret = array();
// Set the default account cancellation method.
variable_set('user_cancel_method', 'user_cancel_reassign');
// Re-assign notification setting.
@@ -401,14 +401,12 @@ function user_update_7003() {
variable_set('user_mail_status_canceled_body', $setting);
variable_del('user_mail_status_deleted_body');
}
- return $ret;
}
/**
* Add the user's pictures to the {file} table and make them managed files.
*/
function user_update_7004(&$sandbox) {
- $ret = array();
$picture_field = array(
'type' => 'int',
@@ -422,7 +420,7 @@ function user_update_7004(&$sandbox) {
// update.
if (!db_column_exists('users', 'picture_fid')) {
// Add a new field for the fid.
- db_add_field($ret, 'users', 'picture_fid', $picture_field);
+ db_add_field('users', 'picture_fid', $picture_field);
}
// Initialize batch update information.
@@ -469,16 +467,14 @@ function user_update_7004(&$sandbox) {
// Indicate our current progress to the batch update system. If there's no
// max value then there's nothing to update and we're finished.
- $ret['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
+ $sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
// When we're finished, drop the old picture field and rename the new one to
// replace it.
- if (isset($ret['#finished']) && $ret['#finished'] == 1) {
- db_drop_field($ret, 'user', 'picture');
- db_change_field($ret, 'user', 'picture_fid', 'picture', $picture_field);
+ if (isset($sandbox['#finished']) && $sandbox['#finished'] == 1) {
+ db_drop_field('user', 'picture');
+ db_change_field('user', 'picture_fid', 'picture', $picture_field);
}
-
- return $ret;
}
/**