#564394 by Berdir and Crell: Removed database BC layer. nah nah nah nah... hey hey hey... gooood byeeee...
parent
6a1217aff0
commit
e18feedfdb
|
@ -881,7 +881,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', 'pager_query', 'db_query_range', 'db_query_temporary', 'update_sql');
|
||||
$db_functions = array('db_query', 'db_query_range', 'update_sql');
|
||||
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))) {
|
||||
|
|
|
@ -23,9 +23,10 @@
|
|||
* inherits much of its syntax and semantics.
|
||||
*
|
||||
* Most Drupal database SELECT queries are performed by a call to db_query() or
|
||||
* db_query_range(). Module authors should also consider using pager_query() for
|
||||
* queries that return results that need to be presented on multiple pages, and
|
||||
* tablesort_sql() for generating appropriate queries for sortable tables.
|
||||
* db_query_range(). Module authors should also consider using the PagerDefault
|
||||
* Extender for queries that return results that need to be presented on
|
||||
* multiple pages, and the Tablesort Extender for generating appropriate queries
|
||||
* for sortable tables.
|
||||
*
|
||||
* For example, one might wish to return a list of the most recent 10 nodes
|
||||
* authored by a given user. Instead of directly issuing the SQL query
|
||||
|
@ -943,7 +944,7 @@ abstract class DatabaseConnection extends PDO {
|
|||
* A database query result resource, or NULL if the query was not executed
|
||||
* correctly.
|
||||
*/
|
||||
abstract public function queryRange($query, array $args, $from, $count, array $options = array());
|
||||
abstract public function queryRange($query, $from, $count, array $args = array(), array $options = array());
|
||||
|
||||
/**
|
||||
* Generate a temporary table name.
|
||||
|
@ -977,7 +978,7 @@ abstract class DatabaseConnection extends PDO {
|
|||
* @return
|
||||
* The name of the temporary table.
|
||||
*/
|
||||
abstract function queryTemporary($query, array $args, array $options = array());
|
||||
abstract function queryTemporary($query, array $args = array(), array $options = array());
|
||||
|
||||
/**
|
||||
* Returns the type of database driver.
|
||||
|
@ -1812,12 +1813,10 @@ class DatabaseStatementBase extends PDOStatement implements DatabaseStatementInt
|
|||
* @return
|
||||
* A prepared statement object, already executed.
|
||||
*/
|
||||
function db_query($query, $args = array(), $options = array()) {
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
function db_query($query, array $args = array(), array $options = array()) {
|
||||
if (empty($options['target'])) {
|
||||
$options['target'] = 'default';
|
||||
}
|
||||
list($query, $args, $options) = _db_query_process_args($query, $args, $options);
|
||||
|
||||
return Database::getConnection($options['target'])->query($query, $args, $options);
|
||||
}
|
||||
|
@ -1830,30 +1829,26 @@ function db_query($query, $args = array(), $options = array()) {
|
|||
* The prepared statement query to run. Although it will accept both
|
||||
* named and unnamed placeholders, named placeholders are strongly preferred
|
||||
* as they are more self-documenting.
|
||||
* @param $from
|
||||
* The first record from the result set to return.
|
||||
* @param $limit
|
||||
* The number of records to return from the result set.
|
||||
* @param $args
|
||||
* An array of values to substitute into the query. If the query uses named
|
||||
* placeholders, this is an associative array in any order. If the query uses
|
||||
* unnamed placeholders (?), this is an indexed array and the order must match
|
||||
* the order of placeholders in the query string.
|
||||
* @param $from
|
||||
* The first record from the result set to return.
|
||||
* @param $limit
|
||||
* The number of records to return from the result set.
|
||||
* @param $options
|
||||
* An array of options to control how the query operates.
|
||||
* @return
|
||||
* A prepared statement object, already executed.
|
||||
*/
|
||||
function db_query_range($query, $args, $from = 0, $count = 0, $options = array()) {
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
$count = array_pop($args);
|
||||
$from = array_pop($args);
|
||||
function db_query_range($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
if (empty($options['target'])) {
|
||||
$options['target'] = 'default';
|
||||
}
|
||||
list($query, $args, $options) = _db_query_process_args($query, $args, $options);
|
||||
|
||||
return Database::getConnection($options['target'])->queryRange($query, $args, $from, $count, $options);
|
||||
return Database::getConnection($options['target'])->queryRange($query, $from, $count, $args, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1874,12 +1869,10 @@ function db_query_range($query, $args, $from = 0, $count = 0, $options = array()
|
|||
* @return
|
||||
* The name of the temporary table.
|
||||
*/
|
||||
function db_query_temporary($query, $args, $options = array()) {
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
function db_query_temporary($query, array $args = array(), array $options = array()) {
|
||||
if (empty($options['target'])) {
|
||||
$options['target'] = 'default';
|
||||
}
|
||||
list($query, $args, $options) = _db_query_process_args($query, $args, $options);
|
||||
|
||||
return Database::getConnection($options['target'])->queryTemporary($query, $args, $options);
|
||||
}
|
||||
|
@ -2064,26 +2057,6 @@ function update_sql($sql) {
|
|||
return array('success' => $result !== FALSE, 'query' => check_plain($sql));
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps the given table.field entry with a DISTINCT(). The wrapper is added to
|
||||
* the SELECT list entry of the given query and the resulting query is returned.
|
||||
* This function only applies the wrapper if a DISTINCT doesn't already exist in
|
||||
* the query.
|
||||
*
|
||||
* @todo Remove this.
|
||||
* @param $table
|
||||
* Table containing the field to set as DISTINCT
|
||||
* @param $field
|
||||
* Field to set as DISTINCT
|
||||
* @param $query
|
||||
* Query to apply the wrapper to
|
||||
* @return
|
||||
* SQL query with the DISTINCT wrapper surrounding the given table.field.
|
||||
*/
|
||||
function db_distinct_field($table, $field, $query) {
|
||||
return Database::getConnection()->distinctField($table, $field, $query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the name of the currently active database driver, such as
|
||||
* "mysql" or "pgsql".
|
||||
|
@ -2475,24 +2448,6 @@ function db_ignore_slave() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup database-legacy
|
||||
*
|
||||
* These functions are no longer necessary, as the DatabaseStatementInterface interface
|
||||
* offers this and much more functionality. They are kept temporarily for backward
|
||||
* compatibility during conversion and should be removed as soon as possible.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
function db_fetch_object(DatabaseStatementInterface $statement) {
|
||||
return $statement->fetch(PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
function db_result(DatabaseStatementInterface $statement) {
|
||||
return $statement->fetchField();
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect the user to the installation script if Drupal has not been
|
||||
* installed yet (i.e., if no $databases array has been defined in the
|
||||
|
@ -2504,152 +2459,4 @@ function _db_check_install_needed() {
|
|||
include_once DRUPAL_ROOT . '/includes/install.inc';
|
||||
install_goto('install.php');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Backward-compatibility utility.
|
||||
*
|
||||
* This function should be removed after all queries have been converted
|
||||
* to the new API. It is temporary only.
|
||||
*
|
||||
* @todo Remove this once the query conversion is complete.
|
||||
*/
|
||||
function _db_query_process_args($query, $args, $options) {
|
||||
|
||||
if (!is_array($options)) {
|
||||
$options = array();
|
||||
}
|
||||
if (empty($options['target'])) {
|
||||
$options['target'] = 'default';
|
||||
}
|
||||
|
||||
// Temporary backward-compatibility hacks. Remove later.
|
||||
$old_query = $query;
|
||||
$query = str_replace(array('%n', '%d', '%f', '%b', "'%s'", '%s'), '?', $old_query);
|
||||
if ($old_query !== $query) {
|
||||
$args = array_values($args); // The old system allowed named arrays, but PDO doesn't if you use ?.
|
||||
}
|
||||
|
||||
return array($query, $args, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for db_rewrite_sql.
|
||||
*
|
||||
* Collects JOIN and WHERE statements via hook_db_rewrite_sql()
|
||||
* Decides whether to select primary_key or DISTINCT(primary_key)
|
||||
*
|
||||
* @todo Remove this function when all code has been converted to query_alter.
|
||||
* @param $query
|
||||
* Query to be rewritten.
|
||||
* @param $primary_table
|
||||
* Name or alias of the table which has the primary key field for this query.
|
||||
* Typical table names would be: {block}, {comment}, {forum}, {node},
|
||||
* {menu}, {taxonomy_term_data} or {taxonomy_vocabulary}. However, in most cases the usual
|
||||
* table alias (b, c, f, n, m, t or v) is used instead of the table name.
|
||||
* @param $primary_field
|
||||
* Name of the primary field.
|
||||
* @param $args
|
||||
* Array of additional arguments.
|
||||
* @return
|
||||
* An array: join statements, where statements, field or DISTINCT(field).
|
||||
*/
|
||||
function _db_rewrite_sql($query = '', $primary_table = 'n', $primary_field = 'nid', $args = array()) {
|
||||
$where = array();
|
||||
$join = array();
|
||||
$distinct = FALSE;
|
||||
foreach (module_implements('db_rewrite_sql') as $module) {
|
||||
$result = module_invoke($module, 'db_rewrite_sql', $query, $primary_table, $primary_field, $args);
|
||||
if (isset($result) && is_array($result)) {
|
||||
if (isset($result['where'])) {
|
||||
$where[] = $result['where'];
|
||||
}
|
||||
if (isset($result['join'])) {
|
||||
$join[] = $result['join'];
|
||||
}
|
||||
if (isset($result['distinct']) && $result['distinct']) {
|
||||
$distinct = TRUE;
|
||||
}
|
||||
}
|
||||
elseif (isset($result)) {
|
||||
$where[] = $result;
|
||||
}
|
||||
}
|
||||
|
||||
$where = empty($where) ? '' : '(' . implode(') AND (', $where) . ')';
|
||||
$join = empty($join) ? '' : implode(' ', $join);
|
||||
|
||||
return array($join, $where, $distinct);
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrites node, taxonomy and comment queries. Use it for listing queries. Do not
|
||||
* use FROM table1, table2 syntax, use JOIN instead.
|
||||
*
|
||||
* @todo Remove this function when all code has been converted to query_alter.
|
||||
* @param $query
|
||||
* Query to be rewritten.
|
||||
* @param $primary_table
|
||||
* Name or alias of the table which has the primary key field for this query.
|
||||
* Typical table names would be: {block}, {comment}, {forum}, {node},
|
||||
* {menu}, {taxonomy_term_data} or {taxonomy_vocabulary}. However, it is more common to use the
|
||||
* the usual table aliases: b, c, f, n, m, t or v.
|
||||
* @param $primary_field
|
||||
* Name of the primary field.
|
||||
* @param $args
|
||||
* An array of arguments, passed to the implementations of hook_db_rewrite_sql.
|
||||
* @return
|
||||
* The original query with JOIN and WHERE statements inserted from
|
||||
* hook_db_rewrite_sql implementations. nid is rewritten if needed.
|
||||
*/
|
||||
function db_rewrite_sql($query, $primary_table = 'n', $primary_field = 'nid', $args = array()) {
|
||||
list($join, $where, $distinct) = _db_rewrite_sql($query, $primary_table, $primary_field, $args);
|
||||
|
||||
if ($distinct) {
|
||||
$query = db_distinct_field($primary_table, $primary_field, $query);
|
||||
}
|
||||
|
||||
if (!empty($where) || !empty($join)) {
|
||||
$pattern = '{
|
||||
# Beginning of the string
|
||||
^
|
||||
((?P<anonymous_view>
|
||||
# Everything within this set of parentheses is named "anonymous view"
|
||||
(?:
|
||||
[^()]++ # anything not parentheses
|
||||
|
|
||||
\( (?P>anonymous_view) \) # an open parenthesis, more "anonymous view" and finally a close parenthesis.
|
||||
)*
|
||||
)[^()]+WHERE)
|
||||
}x';
|
||||
preg_match($pattern, $query, $matches);
|
||||
if ($where) {
|
||||
$n = strlen($matches[1]);
|
||||
$second_part = substr($query, $n);
|
||||
$first_part = substr($matches[1], 0, $n - 5) . " $join WHERE $where AND ( ";
|
||||
foreach (array('GROUP', 'ORDER', 'LIMIT') as $needle) {
|
||||
$pos = strrpos($second_part, $needle);
|
||||
if ($pos !== FALSE) {
|
||||
// All needles are five characters long.
|
||||
$pos += 5;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($pos === FALSE) {
|
||||
$query = $first_part . $second_part . ')';
|
||||
}
|
||||
else {
|
||||
$query = $first_part . substr($second_part, 0, -$pos) . ')' . substr($second_part, -$pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$query = $matches[1] . " $join " . substr($query, strlen($matches[1]));
|
||||
}
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "ingroup database-legacy".
|
||||
*/
|
||||
}
|
|
@ -46,11 +46,11 @@ class DatabaseConnection_mysql extends DatabaseConnection {
|
|||
$this->exec("SET sql_mode='ANSI,TRADITIONAL'");
|
||||
}
|
||||
|
||||
public function queryRange($query, array $args, $from, $count, array $options = array()) {
|
||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
|
||||
}
|
||||
|
||||
public function queryTemporary($query, array $args, array $options = array()) {
|
||||
public function queryTemporary($query, array $args = array(), array $options = array()) {
|
||||
$tablename = $this->generateTemporaryTableName();
|
||||
$this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} Engine=MEMORY SELECT', $query), $args, $options);
|
||||
return $tablename;
|
||||
|
@ -68,15 +68,6 @@ class DatabaseConnection_mysql extends DatabaseConnection {
|
|||
// We don't want to override any of the defaults.
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Remove this as soon as db_rewrite_sql() has been exterminated.
|
||||
*/
|
||||
public function distinctField($table, $field, $query) {
|
||||
$field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
|
||||
// (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
|
||||
return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -99,11 +99,11 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
|
|||
}
|
||||
}
|
||||
|
||||
public function queryRange($query, array $args, $from, $count, array $options = array()) {
|
||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
return $this->query($query . ' LIMIT ' . $count . ' OFFSET ' . $from, $args, $options);
|
||||
}
|
||||
|
||||
public function queryTemporary($query, array $args, array $options = array()) {
|
||||
public function queryTemporary($query, array $args = array(), array $options = array()) {
|
||||
$tablename = $this->generateTemporaryTableName();
|
||||
$this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} AS SELECT', $query), $args, $options);
|
||||
return $tablename;
|
||||
|
@ -126,15 +126,6 @@ class DatabaseConnection_pgsql extends DatabaseConnection {
|
|||
|
||||
return isset($specials[$operator]) ? $specials[$operator] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Remove this as soon as db_rewrite_sql() has been exterminated.
|
||||
*/
|
||||
public function distinctField($table, $field, $query) {
|
||||
$field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
|
||||
// (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
|
||||
return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1084,7 +1084,7 @@ class SelectQuery extends Query implements SelectQueryInterface {
|
|||
$args = $this->getArguments();
|
||||
|
||||
if (!empty($this->range)) {
|
||||
return $this->connection->queryRange((string)$this, $args, $this->range['start'], $this->range['length'], $this->queryOptions);
|
||||
return $this->connection->queryRange((string)$this, $this->range['start'], $this->range['length'], $args, $this->queryOptions);
|
||||
}
|
||||
return $this->connection->query((string)$this, $args, $this->queryOptions);
|
||||
}
|
||||
|
|
|
@ -135,11 +135,11 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
|||
return parent::prepare($query, $options);
|
||||
}
|
||||
|
||||
public function queryRange($query, array $args, $from, $count, array $options = array()) {
|
||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
return $this->query($query . ' LIMIT ' . $from . ', ' . $count, $args, $options);
|
||||
}
|
||||
|
||||
public function queryTemporary($query, array $args, array $options = array()) {
|
||||
public function queryTemporary($query, array $args = array(), array $options = array()) {
|
||||
$tablename = $this->generateTemporaryTableName();
|
||||
$this->query(preg_replace('/^SELECT/i', 'CREATE TEMPORARY TABLE {' . $tablename . '} AS SELECT', $query), $args, $options);
|
||||
return $tablename;
|
||||
|
@ -164,15 +164,6 @@ class DatabaseConnection_sqlite extends DatabaseConnection {
|
|||
// DatabaseStatement_sqlite::execute() and cannot be cached.
|
||||
return $this->prepare($this->prefixTables($query));
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo Remove this as soon as db_rewrite_sql() has been exterminated.
|
||||
*/
|
||||
public function distinctField($table, $field, $query) {
|
||||
$field_to_select = 'DISTINCT(' . $table . '.' . $field . ')';
|
||||
// (?<!text) is a negative look-behind (no need to rewrite queries that already use DISTINCT).
|
||||
return preg_replace('/(SELECT.*)(?:' . $table . '\.|\s)(?<!DISTINCT\()(?<!DISTINCT\(' . $table . '\.)' . $field . '(.*FROM )/AUsi', '\1 ' . $field_to_select . '\2', $query);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -170,76 +170,6 @@ class PagerDefault extends SelectQueryExtender {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a paged database query.
|
||||
*
|
||||
* Use this function when doing select queries you wish to be able to page. The
|
||||
* pager uses LIMIT-based queries to fetch only the records required to render a
|
||||
* certain page. However, it has to learn the total number of records returned
|
||||
* by the query to compute the number of pages (the number of records / records
|
||||
* per page). This is done by inserting "COUNT(*)" in the original query. For
|
||||
* example, the query "SELECT nid, type FROM node WHERE status = '1' ORDER BY
|
||||
* sticky DESC, created DESC" would be rewritten to read "SELECT COUNT(*) FROM
|
||||
* node WHERE status = '1' ORDER BY sticky DESC, created DESC". Rewriting the
|
||||
* query is accomplished using a regular expression.
|
||||
*
|
||||
* Unfortunately, the rewrite rule does not always work as intended for queries
|
||||
* that already have a "COUNT(*)" or a "GROUP BY" clause, and possibly for
|
||||
* other complex queries. In those cases, you can optionally pass a query that
|
||||
* will be used to count the records.
|
||||
*
|
||||
* For example, if you want to page the query "SELECT COUNT(*), TYPE FROM node
|
||||
* GROUP BY TYPE", pager_query() would invoke the incorrect query "SELECT
|
||||
* COUNT(*) FROM node GROUP BY TYPE". So instead, you should pass "SELECT
|
||||
* COUNT(DISTINCT(TYPE)) FROM node" as the optional $count_query parameter.
|
||||
*
|
||||
* @param $query
|
||||
* The SQL query that needs paging.
|
||||
* @param $limit
|
||||
* The number of query results to display per page.
|
||||
* @param $element
|
||||
* An optional integer to distinguish between multiple pagers on one page.
|
||||
* @param $count_query
|
||||
* An SQL query used to count matching records.
|
||||
* @param ...
|
||||
* A variable number of arguments which are substituted into the query (and
|
||||
* the count query) using printf() syntax. Instead of a variable number of
|
||||
* query arguments, you may also pass a single array containing the query
|
||||
* arguments.
|
||||
* @return
|
||||
* A database query result resource, or FALSE if the query was not executed
|
||||
* correctly.
|
||||
*
|
||||
* @ingroup database
|
||||
*/
|
||||
function pager_query($query, $limit = 10, $element = 0, $count_query = NULL) {
|
||||
global $pager_page_array, $pager_total, $pager_total_items, $pager_limits;
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : '';
|
||||
|
||||
// Substitute in query arguments.
|
||||
$args = func_get_args();
|
||||
$args = array_slice($args, 4);
|
||||
// Alternative syntax for '...'
|
||||
if (isset($args[0]) && is_array($args[0])) {
|
||||
$args = $args[0];
|
||||
}
|
||||
|
||||
// Construct a count query if none was given.
|
||||
if (!isset($count_query)) {
|
||||
$count_query = preg_replace(array('/SELECT.*?FROM /As', '/ORDER BY .*/'), array('SELECT COUNT(*) FROM ', ''), $query);
|
||||
}
|
||||
|
||||
// Convert comma-separated $page to an array, used by other functions.
|
||||
$pager_page_array = explode(',', $page);
|
||||
|
||||
// We calculate the total of pages as ceil(items / limit).
|
||||
$pager_total_items[$element] = db_query($count_query, $args)->fetchField();
|
||||
$pager_total[$element] = ceil($pager_total_items[$element] / $limit);
|
||||
$pager_page_array[$element] = max(0, min((int)$pager_page_array[$element], ((int)$pager_total[$element]) - 1));
|
||||
$pager_limits[$element] = $limit;
|
||||
return db_query_range($query, $args, $pager_page_array[$element] * $limit, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compose a query string to append to pager requests.
|
||||
*
|
||||
|
|
|
@ -145,37 +145,6 @@ function tablesort_init($header) {
|
|||
return $ts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an SQL sort clause.
|
||||
*
|
||||
* This function produces the ORDER BY clause to insert in your SQL queries,
|
||||
* assuring that the returned database table rows match the sort order chosen
|
||||
* by the user.
|
||||
*
|
||||
* @param $header
|
||||
* An array of column headers in the format described in theme_table().
|
||||
* @param $before
|
||||
* An SQL string to insert after ORDER BY and before the table sorting code.
|
||||
* Useful for sorting by important attributes like "sticky" first.
|
||||
* @return
|
||||
* An SQL string to append to the end of a query.
|
||||
*
|
||||
* @ingroup database
|
||||
*/
|
||||
function tablesort_sql($header, $before = '') {
|
||||
$ts = tablesort_init($header);
|
||||
if ($ts['sql']) {
|
||||
// Based on code from db_escape_table(), but this can also contain a dot.
|
||||
$field = preg_replace('/[^A-Za-z0-9_.]+/', '', $ts['sql']);
|
||||
|
||||
// Sort order can only be ASC or DESC.
|
||||
$sort = drupal_strtoupper($ts['sort']);
|
||||
$sort = in_array($sort, array('ASC', 'DESC')) ? $sort : '';
|
||||
|
||||
return " ORDER BY $before $field $sort";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a column header.
|
||||
*
|
||||
|
|
|
@ -131,10 +131,10 @@ function db_change_column(&$ret, $table, $column, $column_new, $type, $attribute
|
|||
function update_fix_compatibility() {
|
||||
$ret = array();
|
||||
$incompatible = array();
|
||||
$query = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
|
||||
while ($result = db_fetch_object($query)) {
|
||||
if (update_check_incompatibility($result->name, $result->type)) {
|
||||
$incompatible[] = $result->name;
|
||||
$result = db_query("SELECT name, type, status FROM {system} WHERE status = 1 AND type IN ('module','theme')");
|
||||
foreach ($result as $row) {
|
||||
if (update_check_incompatibility($row->name, $row->type)) {
|
||||
$incompatible[] = $row->name;
|
||||
}
|
||||
}
|
||||
if (!empty($incompatible)) {
|
||||
|
|
|
@ -756,8 +756,8 @@ function install_system_module(&$install_state) {
|
|||
*/
|
||||
function install_verify_completed_task() {
|
||||
try {
|
||||
if ($result = db_query("SELECT value FROM {variable} WHERE name = '%s'", 'install_task')) {
|
||||
$task = unserialize(db_result($result));
|
||||
if ($result = db_query("SELECT value FROM {variable} WHERE name = :name", array('name' => 'install_task'))) {
|
||||
$task = unserialize($result->fetchField());
|
||||
}
|
||||
}
|
||||
// Do not trigger an error if the database query fails, since the database
|
||||
|
|
|
@ -377,7 +377,7 @@ function aggregator_block_view($delta = '') {
|
|||
case 'feed':
|
||||
if ($feed = db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE block <> 0 AND fid = :fid', array(':fid' => $id))->fetchObject()) {
|
||||
$block['subject'] = check_plain($feed->title);
|
||||
$result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", array(':fid' => $id), 0, $feed->block);
|
||||
$result = db_query_range("SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC", 0, $feed->block, array(':fid' => $id));
|
||||
$read_more = theme('more_link', url('aggregator/sources/' . $feed->fid), t("View this feed's recent news."));
|
||||
}
|
||||
break;
|
||||
|
@ -385,7 +385,7 @@ function aggregator_block_view($delta = '') {
|
|||
case 'category':
|
||||
if ($category = db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = :cid', array(':cid' => $id))->fetchObject()) {
|
||||
$block['subject'] = check_plain($category->title);
|
||||
$result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', array(':cid' => $category->cid), 0, $category->block);
|
||||
$result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = :cid ORDER BY i.timestamp DESC, i.iid DESC', 0, $category->block, array(':cid' => $category->cid));
|
||||
$read_more = theme('more_link', url('aggregator/categories/' . $category->cid), t("View this category's recent news."));
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -90,10 +90,10 @@ function aggregator_feed_items_load($type, $data = NULL) {
|
|||
$result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', 0, $range_limit);
|
||||
break;
|
||||
case 'source':
|
||||
$result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC', array(':fid' => $data->fid), 0, $range_limit);
|
||||
$result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = :fid ORDER BY timestamp DESC, iid DESC', 0, $range_limit, array(':fid' => $data->fid));
|
||||
break;
|
||||
case 'category':
|
||||
$result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', array(':cid' => $data['cid']), 0, $range_limit);
|
||||
$result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', 0, $range_limit, array(':cid' => $data['cid']));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ function aggregator_page_sources() {
|
|||
// Most recent items:
|
||||
$summary_items = array();
|
||||
if (variable_get('aggregator_summary_items', 3)) {
|
||||
$items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = :fid ORDER BY i.timestamp DESC', array(':fid' => $feed->fid), 0, variable_get('aggregator_summary_items', 3));
|
||||
$items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = :fid ORDER BY i.timestamp DESC', 0, variable_get('aggregator_summary_items', 3), array(':fid' => $feed->fid));
|
||||
foreach ($items as $item) {
|
||||
$summary_items[] = theme('aggregator_summary_item', $item);
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ function aggregator_page_categories() {
|
|||
foreach ($result as $category) {
|
||||
if (variable_get('aggregator_summary_items', 3)) {
|
||||
$summary_items = array();
|
||||
$items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = :cid ORDER BY i.timestamp DESC', array(':cid' => $category->cid), 0, variable_get('aggregator_summary_items', 3));
|
||||
$items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = :cid ORDER BY i.timestamp DESC', 0, variable_get('aggregator_summary_items', 3), array(':cid' => $category->cid));
|
||||
foreach ($items as $item) {
|
||||
$summary_items[] = theme('aggregator_summary_item', $item);
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ function aggregator_page_rss() {
|
|||
// arg(2) is the passed cid, only select for that category.
|
||||
if (arg(2)) {
|
||||
$category = db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject();
|
||||
$result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', array(':cid' => $category->cid), 0, variable_get('feed_default_items', 10));
|
||||
$result = db_query_range('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = :cid ORDER BY timestamp DESC, i.iid DESC', 0, variable_get('feed_default_items', 10), array(':cid' => $category->cid));
|
||||
}
|
||||
// Or, get the default aggregator items.
|
||||
else {
|
||||
|
|
|
@ -333,10 +333,10 @@ function block_admin_configure(&$form_state, $module = NULL, $delta = 0) {
|
|||
|
||||
function block_admin_configure_validate($form, &$form_state) {
|
||||
if ($form_state['values']['module'] == 'block') {
|
||||
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', array(
|
||||
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE bid <> :bid AND info = :info', 0, 1, array(
|
||||
':bid' => $form_state['values']['delta'],
|
||||
':info' => $form_state['values']['info'],
|
||||
), 0, 1)->fetchField();
|
||||
))->fetchField();
|
||||
if (empty($form_state['values']['info']) || $custom_block_exists) {
|
||||
form_set_error('info', t('Please ensure that each block description is unique.'));
|
||||
}
|
||||
|
@ -411,7 +411,7 @@ function block_add_block_form(&$form_state) {
|
|||
}
|
||||
|
||||
function block_add_block_form_validate($form, &$form_state) {
|
||||
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', array(':info' => $form_state['values']['info']), 0, 1)->fetchField();
|
||||
$custom_block_exists = (bool) db_query_range('SELECT 1 FROM {block_custom} WHERE info = :info', 0, 1, array(':info' => $form_state['values']['info']))->fetchField();
|
||||
|
||||
if (empty($form_state['values']['info']) || $custom_block_exists) {
|
||||
form_set_error('info', t('Please ensure that each block description is unique.'));
|
||||
|
|
|
@ -440,7 +440,7 @@ function block_system_themes_form_submit(&$form, &$form_state) {
|
|||
}
|
||||
if ($form_state['values']['admin_theme'] && $form_state['values']['admin_theme'] !== variable_get('admin_theme', 0)) {
|
||||
// If we're changing themes, make sure the theme has its blocks initialized.
|
||||
$has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', array(':theme' => $form_state['values']['admin_theme']), 0, 1)->fetchField();
|
||||
$has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $form_state['values']['admin_theme']))->fetchField();
|
||||
if (!$has_blocks) {
|
||||
block_theme_initialize($form_state['values']['admin_theme']);
|
||||
}
|
||||
|
@ -461,7 +461,7 @@ function block_system_themes_form_submit(&$form, &$form_state) {
|
|||
*/
|
||||
function block_theme_initialize($theme) {
|
||||
// Initialize theme's blocks if none already registered.
|
||||
$has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', array(':theme' => $theme), 0, 1)->fetchField();
|
||||
$has_blocks = (bool) db_query_range('SELECT 1 FROM {block} WHERE theme = :theme', 0, 1, array(':theme' => $theme))->fetchField();
|
||||
if (!$has_blocks) {
|
||||
$default_theme = variable_get('theme_default', 'garland');
|
||||
$regions = system_region_list($theme);
|
||||
|
@ -821,7 +821,7 @@ function block_form_system_performance_settings_alter(&$form, &$form_state) {
|
|||
);
|
||||
|
||||
// Check if the "Who's online" block is enabled.
|
||||
$online_block_enabled = db_query_range("SELECT 1 FROM {block} b WHERE module = 'user' AND delta = 'online' AND status = 1", array(), 0, 1)->fetchField();
|
||||
$online_block_enabled = db_query_range("SELECT 1 FROM {block} b WHERE module = 'user' AND delta = 'online' AND status = 1", 0, 1)->fetchField();
|
||||
|
||||
// If the "Who's online" block is enabled, append some descriptive text to
|
||||
// the end of the form description.
|
||||
|
|
|
@ -45,21 +45,6 @@ function comment_enable() {
|
|||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changed node_comment_statistics to use node->changed to avoid future timestamps.
|
||||
*/
|
||||
function comment_update_1() {
|
||||
// Change any future last comment timestamps to current time.
|
||||
db_query('UPDATE {node_comment_statistics} SET last_comment_timestamp = %d WHERE last_comment_timestamp > %d', REQUEST_TIME, REQUEST_TIME);
|
||||
|
||||
// Unstuck node indexing timestamp if needed.
|
||||
if (($last = variable_get('node_cron_last', FALSE)) !== FALSE) {
|
||||
variable_set('node_cron_last', min(REQUEST_TIME, $last));
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @defgroup updates-6.x-to-7.x Comment updates from 6.x to 7.x
|
||||
* @{
|
||||
|
|
|
@ -435,7 +435,7 @@ function comment_new_page_count($num_comments, $new_replies, $node) {
|
|||
WHERE nid = :nid
|
||||
AND status = 0
|
||||
ORDER BY timestamp DESC) AS thread
|
||||
ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))', array(':nid' => $node->nid), 0, $new_replies)->fetchField();
|
||||
ORDER BY SUBSTRING(thread, 1, (LENGTH(thread) - 1))', 0, $new_replies, array(':nid' => $node->nid))->fetchField();
|
||||
$thread = substr($result, 0, -1);
|
||||
$count = db_query('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND status = 0 AND SUBSTRING(thread, 1, (LENGTH(thread) - 1)) < :thread', array(
|
||||
':nid' => $node->nid,
|
||||
|
@ -2240,10 +2240,10 @@ function _comment_update_node_statistics($nid) {
|
|||
|
||||
if ($count > 0) {
|
||||
// Comments exist.
|
||||
$last_reply = db_query_range('SELECT cid, name, timestamp, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', array(
|
||||
$last_reply = db_query_range('SELECT cid, name, timestamp, uid FROM {comment} WHERE nid = :nid AND status = :status ORDER BY cid DESC', 0, 1, array(
|
||||
':nid' => $nid,
|
||||
':status' => COMMENT_PUBLISHED,
|
||||
), 0, 1)->fetchObject();
|
||||
))->fetchObject();
|
||||
db_update('node_comment_statistics')
|
||||
->fields( array(
|
||||
'comment_count' => $count,
|
||||
|
|
|
@ -1036,7 +1036,7 @@ class FieldInfoTestCase extends FieldTestCase {
|
|||
// Simulate a stored field definition missing a field setting (e.g. a
|
||||
// third-party module adding a new field setting has been enabled, and
|
||||
// existing fields do not know the setting yet).
|
||||
$data = db_result(db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name'])));
|
||||
$data = db_query('SELECT data FROM {field_config} WHERE field_name = :field_name', array(':field_name' => $field_definition['field_name']))->fetchField();
|
||||
$data = unserialize($data);
|
||||
$data['settings'] = array();
|
||||
db_update('field_config')
|
||||
|
@ -1072,7 +1072,7 @@ class FieldInfoTestCase extends FieldTestCase {
|
|||
// Simulate a stored instance definition missing various settings (e.g. a
|
||||
// third-party module adding instance, widget or display settings has been
|
||||
// enabled, but existing instances do not know the new settings).
|
||||
$data = db_result(db_query('SELECT data FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $instance_definition['field_name'], ':bundle' => $instance_definition['bundle'])));
|
||||
$data = db_query('SELECT data FROM {field_config_instance} WHERE field_name = :field_name AND bundle = :bundle', array(':field_name' => $instance_definition['field_name'], ':bundle' => $instance_definition['bundle']))->fetchField();
|
||||
$data = unserialize($data);
|
||||
$data['settings'] = array();
|
||||
$data['widget']['settings'] = 'unavailable_widget';
|
||||
|
|
|
@ -252,10 +252,10 @@ function forum_node_validate($node, $form) {
|
|||
$vocabulary = $vid;
|
||||
$containers = variable_get('forum_containers', array());
|
||||
foreach ($node->taxonomy as $term) {
|
||||
$used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid', array(
|
||||
$used = db_query_range('SELECT 1 FROM {taxonomy_term_data} WHERE tid = :tid AND vid = :vid', 0, 1, array(
|
||||
':tid' => $term,
|
||||
':vid' => $vocabulary,
|
||||
), 0, 1)->fetchField();
|
||||
))->fetchField();
|
||||
if ($used && in_array($term, $containers)) {
|
||||
$term = taxonomy_term_load($term);
|
||||
form_set_error('taxonomy', t('The item %forum is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
|
||||
|
@ -287,7 +287,7 @@ function forum_node_presave($node) {
|
|||
$node->tid = $term_id;
|
||||
}
|
||||
}
|
||||
$old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", array(':nid' => $node->nid), 0, 1)->fetchField();
|
||||
$old_tid = db_query_range("SELECT f.tid FROM {forum} f INNER JOIN {node} n ON f.vid = n.vid WHERE n.nid = :nid ORDER BY f.vid DESC", 0, 1, array(':nid' => $node->nid))->fetchField();
|
||||
if ($old_tid && isset($node->tid) && ($node->tid != $old_tid) && !empty($node->shadow)) {
|
||||
// A shadow copy needs to be created. Retain new term and add old term.
|
||||
$node->taxonomy[] = $old_tid;
|
||||
|
|
|
@ -570,7 +570,7 @@ function menu_edit_menu_validate($form, &$form_state) {
|
|||
// We will add 'menu-' to the menu name to help avoid name-space conflicts.
|
||||
$item['menu_name'] = 'menu-' . $item['menu_name'];
|
||||
$custom_exists = db_query('SELECT menu_name FROM {menu_custom} WHERE menu_name = :menu', array(':menu' => $item['menu_name']))->fetchField();
|
||||
$link_exists = db_query_range("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu", array(':menu' => $item['menu_name']), 0, 1)->fetchField();
|
||||
$link_exists = db_query_range("SELECT menu_name FROM {menu_links} WHERE menu_name = :menu", 0, 1, array(':menu' => $item['menu_name']))->fetchField();
|
||||
if ($custom_exists || $link_exists) {
|
||||
form_set_error('menu_name', t('The menu already exists.'));
|
||||
}
|
||||
|
|
|
@ -365,17 +365,15 @@ function menu_node_prepare($node) {
|
|||
$item = array();
|
||||
if (isset($node->nid)) {
|
||||
// Give priority to the default menu
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", array(
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND menu_name = :menu_name AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
|
||||
':path' => 'node/' . $node->nid,
|
||||
':menu_name' => $menu_name,
|
||||
), 0, 1)
|
||||
->fetchField();
|
||||
))->fetchField();
|
||||
// Check all menus if a link does not exist in the default menu.
|
||||
if (!$mlid) {
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", array(
|
||||
$mlid = db_query_range("SELECT mlid FROM {menu_links} WHERE link_path = :path AND module = 'menu' ORDER BY mlid ASC", 0, 1, array(
|
||||
':path' => 'node/' . $node->nid,
|
||||
), 0, 1)
|
||||
->fetchField();
|
||||
))->fetchField();
|
||||
}
|
||||
if ($mlid) {
|
||||
$item = menu_link_load($mlid);
|
||||
|
|
|
@ -470,7 +470,7 @@ function node_types_rebuild() {
|
|||
function node_type_save($info) {
|
||||
$is_existing = FALSE;
|
||||
$existing_type = !empty($info->old_type) ? $info->old_type : $info->type;
|
||||
$is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', array(':type' => $existing_type), 0, 1)->fetchField();
|
||||
$is_existing = (bool) db_query_range('SELECT 1 FROM {node_type} WHERE type = :type', 0, 1, array(':type' => $existing_type))->fetchField();
|
||||
$type = node_type_set_defaults($info);
|
||||
|
||||
$fields = array(
|
||||
|
@ -2356,61 +2356,6 @@ function node_permissions_get_configured_types() {
|
|||
return $configured_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an SQL join clause for use in fetching a node listing.
|
||||
*
|
||||
* @param $node_alias
|
||||
* If the node table has been given an SQL alias other than the default
|
||||
* "n", that must be passed here.
|
||||
* @param $node_access_alias
|
||||
* If the node_access table has been given an SQL alias other than the default
|
||||
* "na", that must be passed here.
|
||||
* @return
|
||||
* An SQL join clause.
|
||||
*/
|
||||
function _node_access_join_sql($node_alias = 'n', $node_access_alias = 'na') {
|
||||
if (user_access('bypass node access')) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return 'INNER JOIN {node_access} ' . $node_access_alias . ' ON ' . $node_access_alias . '.nid = ' . $node_alias . '.nid';
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate an SQL where clause for use in fetching a node listing.
|
||||
*
|
||||
* @param $op
|
||||
* The operation that must be allowed to return a node.
|
||||
* @param $node_access_alias
|
||||
* If the node_access table has been given an SQL alias other than the default
|
||||
* "na", that must be passed here.
|
||||
* @param $account
|
||||
* The user object for the user performing the operation. If omitted, the
|
||||
* current user is used.
|
||||
* @return
|
||||
* An SQL where clause.
|
||||
*/
|
||||
function _node_access_where_sql($op = 'view', $node_access_alias = 'na', $account = NULL) {
|
||||
if (user_access('bypass node access')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$grants = array();
|
||||
foreach (node_access_grants($op, $account) as $realm => $gids) {
|
||||
foreach ($gids as $gid) {
|
||||
$grants[] = "($node_access_alias.gid = $gid AND $node_access_alias.realm = '$realm')";
|
||||
}
|
||||
}
|
||||
|
||||
$grants_sql = '';
|
||||
if (count($grants)) {
|
||||
$grants_sql = 'AND (' . implode(' OR ', $grants) . ')';
|
||||
}
|
||||
|
||||
$sql = "$node_access_alias.grant_$op >= 1 $grants_sql";
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch an array of permission IDs granted to the given user ID.
|
||||
*
|
||||
|
@ -2484,17 +2429,6 @@ function node_access_view_all_nodes() {
|
|||
return $access;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_db_rewrite_sql().
|
||||
*/
|
||||
function node_db_rewrite_sql($query, $primary_table, $primary_field) {
|
||||
if ($primary_field == 'nid' && !node_access_view_all_nodes()) {
|
||||
$return['join'] = _node_access_join_sql($primary_table);
|
||||
$return['where'] = _node_access_where_sql();
|
||||
$return['distinct'] = 1;
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_query_TAG_alter().
|
||||
|
@ -2739,7 +2673,7 @@ function _node_access_rebuild_batch_operation(&$context) {
|
|||
|
||||
// Process the next 20 nodes.
|
||||
$limit = 20;
|
||||
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", array(':nid' => $context['sandbox']['current_node']), 0, $limit)->fetchCol();
|
||||
$nids = db_query_range("SELECT nid FROM {node} WHERE nid > :nid ORDER BY nid ASC", 0, $limit, array(':nid' => $context['sandbox']['current_node']))->fetchCol();
|
||||
$nodes = node_load_multiple($nids, array(), TRUE);
|
||||
foreach ($nodes as $node) {
|
||||
// To preserve database integrity, only acquire grants if the node
|
||||
|
@ -3055,7 +2989,7 @@ function node_assign_owner_action_form($context) {
|
|||
}
|
||||
|
||||
function node_assign_owner_action_validate($form, $form_state) {
|
||||
$exists = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', array(':name' => $form_state['values']['owner_name']), 0, 1)->fetchField();
|
||||
$exists = (bool) db_query_range('SELECT 1 FROM {users} WHERE name = :name', 0, 1, array(':name' => $form_state['values']['owner_name']))->fetchField();
|
||||
if (!$exists) {
|
||||
form_set_error('owner_name', t('Please enter a valid username.'));
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ function path_admin_overview($keys = NULL) {
|
|||
// Add the filter form above the overview table.
|
||||
$build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys);
|
||||
// Enable language column if locale is enabled or if we have any alias with language
|
||||
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', array(':language' => ''), 0, 1)->fetchField();
|
||||
$alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE language <> :language', 0, 1, array(':language' => ''))->fetchField();
|
||||
$multilanguage = (module_exists('locale') || $alias_exists);
|
||||
|
||||
$header = array(
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
* Implement hook_install().
|
||||
*/
|
||||
function php_install() {
|
||||
$format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', array(':name' => 'PHP code'), 0, 1)->fetchField();
|
||||
$format_exists = (bool) db_query_range('SELECT 1 FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'PHP code'))->fetchField();
|
||||
// Add a PHP code text format, if it does not exist. Do this only for the
|
||||
// first install (or if the format has been manually deleted) as there is no
|
||||
// reliable method to identify the format in an uninstall hook or in
|
||||
|
|
|
@ -420,7 +420,7 @@ function profile_field_delete_submit($form, &$form_state) {
|
|||
*/
|
||||
function profile_admin_settings_autocomplete($string) {
|
||||
$matches = array();
|
||||
$result = db_query_range("SELECT category FROM {profile_field} WHERE LOWER(category) LIKE LOWER(:category)", array(':category' => $string . '%'), 0, 10);
|
||||
$result = db_query_range("SELECT category FROM {profile_field} WHERE LOWER(category) LIKE LOWER(:category)", 0, 10, array(':category' => $string . '%'));
|
||||
foreach ($result as $data) {
|
||||
$matches[$data->category] = check_plain($data->category);
|
||||
}
|
||||
|
|
|
@ -510,10 +510,10 @@ function profile_category_access($account, $category) {
|
|||
return TRUE;
|
||||
}
|
||||
else {
|
||||
$category_visible = (bool) db_query_range('SELECT 1 FROM {profile_field} WHERE category = :category AND visibility <> :visibility', array(
|
||||
$category_visible = (bool) db_query_range('SELECT 1 FROM {profile_field} WHERE category = :category AND visibility <> :visibility', 0, 1, array(
|
||||
':category' => $category,
|
||||
':visibility' => PROFILE_HIDDEN
|
||||
), 0, 1)->fetchField();
|
||||
))->fetchField();
|
||||
return user_edit_access($account) && $category_visible;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,12 +123,12 @@ function profile_browse() {
|
|||
*/
|
||||
function profile_autocomplete($field, $string) {
|
||||
$matches = array();
|
||||
$autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", array(':fid' => $field), 0, 1)->fetchField();
|
||||
$autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", 0, 1, array(':fid' => $field))->fetchField();
|
||||
if ($autocomplete_field) {
|
||||
$values = db_query_range("SELECT value FROM {profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", array(
|
||||
$values = db_query_range("SELECT value FROM {profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", 0, 10, array(
|
||||
':fid' => $field,
|
||||
':value' => $string . '%',
|
||||
), 0, 10)->fetchCol();
|
||||
))->fetchCol();
|
||||
foreach ($values as $value) {
|
||||
$matches[$value] = check_plain($value);
|
||||
}
|
||||
|
|
|
@ -252,8 +252,8 @@ function _simpletest_batch_finished($success, $results, $operations, $elapsed) {
|
|||
* that ran.
|
||||
*/
|
||||
function simpletest_last_test_get($test_id) {
|
||||
$last_prefix = db_result(db_query_range('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', array(':test_id' => $test_id), 0, 1));
|
||||
$last_test_class = db_result(db_query_range('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id DESC', array(':test_id' => $test_id), 0, 1));
|
||||
$last_prefix = db_query_range('SELECT last_prefix FROM {simpletest_test_id} WHERE test_id = :test_id', 0, 1, array(':test_id' => $test_id))->fetchField();
|
||||
$last_test_class = db_query_range('SELECT test_class FROM {simpletest} WHERE test_id = :test_id ORDER BY message_id DESC', 0, 1, array(':test_id' => $test_id))->fetchField();
|
||||
return array($last_prefix, $last_test_class);
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ class ActionLoopTestCase extends DrupalWebTestCase {
|
|||
|
||||
$result = db_query("SELECT * FROM {watchdog} WHERE type = 'actions_loop_test' OR type = 'actions' ORDER BY timestamp");
|
||||
$loop_started = FALSE;
|
||||
while ($row = db_fetch_object($result)) {
|
||||
foreach ($result as $row) {
|
||||
|
||||
$expected_message = array_shift($expected);
|
||||
$this->assertEqual($row->message, $expected_message, t('Expected message %expected, got %message.', array('%expected' => $expected_message, '%message' => $row->message)));
|
||||
|
|
|
@ -2448,7 +2448,7 @@ class DatabaseRangeQueryTestCase extends DrupalWebTestCase {
|
|||
*/
|
||||
function testRangeQuery() {
|
||||
// Test if return correct number of rows.
|
||||
$range_rows = db_query_range("SELECT name FROM {system} ORDER BY name", array(), 2, 3)->fetchAll();
|
||||
$range_rows = db_query_range("SELECT name FROM {system} ORDER BY name", 2, 3)->fetchAll();
|
||||
$this->assertEqual(count($range_rows), 3, t('Range query work and return correct number of rows.'));
|
||||
|
||||
// Test if return target data.
|
||||
|
|
|
@ -137,53 +137,6 @@ function hook_cron() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewrite database queries, usually for access control.
|
||||
*
|
||||
* Add JOIN and WHERE statements to queries and decide whether the primary_field
|
||||
* shall be made DISTINCT. For node objects, primary field is always called nid.
|
||||
* For taxonomy terms, it is tid and for vocabularies it is vid. For comments,
|
||||
* it is cid. Primary table is the table where the primary object (node, file,
|
||||
* taxonomy_term_node etc.) is.
|
||||
*
|
||||
* You shall return an associative array. Possible keys are 'join', 'where' and
|
||||
* 'distinct'. The value of 'distinct' shall be 1 if you want that the
|
||||
* primary_field made DISTINCT.
|
||||
*
|
||||
* @param $query
|
||||
* Query to be rewritten.
|
||||
* @param $primary_table
|
||||
* Name or alias of the table which has the primary key field for this query.
|
||||
* Typical table names would be: {block}, {comment}, {forum}, {node},
|
||||
* {menu}, {taxonomy_term_data} or {taxonomy_vocabulary}. However, it is more common for
|
||||
* $primary_table to contain the usual table alias: b, c, f, n, m, t or v.
|
||||
* @param $primary_field
|
||||
* Name of the primary field.
|
||||
* @param $args
|
||||
* Array of additional arguments.
|
||||
* @return
|
||||
* An array of join statements, where statements, distinct decision.
|
||||
*/
|
||||
function hook_db_rewrite_sql($query, $primary_table, $primary_field, $args) {
|
||||
switch ($primary_field) {
|
||||
case 'nid':
|
||||
// this query deals with node objects
|
||||
$return = array();
|
||||
if ($primary_table != 'n') {
|
||||
$return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid";
|
||||
}
|
||||
$return['where'] = 'created >' . mktime(0, 0, 0, 1, 1, 2005);
|
||||
return $return;
|
||||
break;
|
||||
case 'tid':
|
||||
// this query deals with taxonomy objects
|
||||
break;
|
||||
case 'vid':
|
||||
// this query deals with vocabulary objects
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows modules to declare their own Forms API element types and specify their
|
||||
* default values.
|
||||
|
@ -1432,7 +1385,7 @@ function hook_file_move($file, $source) {
|
|||
*/
|
||||
function hook_file_references($file) {
|
||||
// If upload.module is still using a file, do not let other modules delete it.
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', array(':fid' => $file->fid), 0, 1)->fetchField();
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', 0, 1, array(':fid' => $file->fid))->fetchField();
|
||||
if ($file_used) {
|
||||
// Return the name of the module and how many references it has to the file.
|
||||
return array('upload' => $count);
|
||||
|
|
|
@ -350,17 +350,38 @@ function system_install() {
|
|||
// uid 2 which is not what we want. So we insert the first user here, the
|
||||
// anonymous user. uid is 1 here for now, but very soon it will be changed
|
||||
// to 0.
|
||||
db_query("INSERT INTO {users} (name, mail) VALUES('%s', '%s')", '', '');
|
||||
db_insert('users')
|
||||
->fields(array(
|
||||
'name' => '',
|
||||
'mail' => '',
|
||||
))
|
||||
->execute();
|
||||
// We need some placeholders here as name and mail are uniques and data is
|
||||
// presumed to be a serialized array. Install will change uid 1 immediately
|
||||
// anyways. So we insert the superuser here, the uid is 2 here for now, but
|
||||
// very soon it will be changed to 1.
|
||||
db_query("INSERT INTO {users} (name, mail, created, status, data) VALUES('%s', '%s', %d, %d, '%s')", 'placeholder-for-uid-1', 'placeholder-for-uid-1', REQUEST_TIME, 1, serialize(array()));
|
||||
|
||||
db_insert('users')
|
||||
->fields(array(
|
||||
'name' => 'placeholder-for-uid-1',
|
||||
'mail' => 'placeholder-for-uid-1',
|
||||
'created' => REQUEST_TIME,
|
||||
'status' => 1,
|
||||
'data' => serialize(array()),
|
||||
))
|
||||
->execute();
|
||||
// This sets the above two users uid 0 (anonymous). We avoid an explicit 0
|
||||
// otherwise MySQL might insert the next auto_increment value.
|
||||
db_query("UPDATE {users} SET uid = uid - uid WHERE name = '%s'", '');
|
||||
db_update('users')
|
||||
->expression('uid', 'uid - uid')
|
||||
->condition('name', '')
|
||||
->execute();
|
||||
|
||||
// This sets uid 1 (superuser). We skip uid 2 but that's not a big problem.
|
||||
db_query("UPDATE {users} SET uid = 1 WHERE name = '%s'", 'placeholder-for-uid-1');
|
||||
db_update('users')
|
||||
->fields(array('uid' => 1))
|
||||
->condition('name', 'placeholder-for-uid-1')
|
||||
->execute();
|
||||
|
||||
// Built-in roles.
|
||||
$rid_anonymous = db_insert('role')
|
||||
|
|
|
@ -204,7 +204,7 @@ class SystemQueue implements DrupalQueueInterface {
|
|||
// meantime. Therefore loop until an item is successfully claimed or we are
|
||||
// reasonably sure there are no unclaimed items left.
|
||||
while (TRUE) {
|
||||
$item = db_query_range('SELECT data, item_id FROM {queue} q WHERE consumer_id = 0 AND name = :name ORDER BY created ASC', array(':name' => $this->name), 0, 1)->fetchObject();
|
||||
$item = db_query_range('SELECT data, item_id FROM {queue} q WHERE consumer_id = 0 AND name = :name ORDER BY created ASC', 0, 1, array(':name' => $this->name))->fetchObject();
|
||||
if ($item) {
|
||||
// Try to mark the item as ours. We cannot rely on REQUEST_TIME
|
||||
// because items might be claimed by a single consumer which runs
|
||||
|
|
|
@ -124,7 +124,7 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
|
|||
|
||||
case 'node-count':
|
||||
$sql = "SELECT COUNT (1) FROM {taxonomy_term_node} tn WHERE tn.tid = :tid";
|
||||
$count = db_result(db_query($sql, array(':tid' => $term->tid)));
|
||||
$count = db_query($sql, array(':tid' => $term->tid))->fetchField();
|
||||
$replacements[$original] = $count;
|
||||
break;
|
||||
|
||||
|
@ -172,13 +172,13 @@ function taxonomy_tokens($type, $tokens, array $data = array(), array $options =
|
|||
|
||||
case 'term-count':
|
||||
$sql = "SELECT COUNT (1) FROM {taxonomy_term_data} td WHERE td.vid = :vid";
|
||||
$count = db_result(db_query($sql, array(':vid' => $vocabulary->vid)));
|
||||
$count = db_query($sql, array(':vid' => $vocabulary->vid))->fetchField();
|
||||
$replacements[$original] = $count;
|
||||
break;
|
||||
|
||||
case 'node-count':
|
||||
$sql = "SELECT COUNT (1) FROM {taxonomy_term_node} tn LEFT JOIN {taxonomy_term_data} td ON tn.tid = td.tid WHERE td.vid = :vid";
|
||||
$count = db_result(db_query($sql, array(':vid' => $vocabulary->vid)));
|
||||
$count = db_query($sql, array(':vid' => $vocabulary->vid))->fetchField();
|
||||
$replacements[$original] = $count;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ function tracker_cron() {
|
|||
$batch_size = variable_get('tracker_batch_size', 1000);
|
||||
if ($max_nid > 0) {
|
||||
$last_nid = FALSE;
|
||||
$result = db_query_range('SELECT nid, uid, status FROM {node} WHERE nid <= :max_nid ORDER BY nid DESC', array(':max_nid' => $max_nid), 0, $batch_size);
|
||||
$result = db_query_range('SELECT nid, uid, status FROM {node} WHERE nid <= :max_nid ORDER BY nid DESC', 0, $batch_size, array(':max_nid' => $max_nid));
|
||||
|
||||
$count = 0;
|
||||
|
||||
|
@ -266,10 +266,10 @@ function _tracker_add($nid, $uid, $changed) {
|
|||
*/
|
||||
function _tracker_calculate_changed($nid) {
|
||||
$changed = db_query('SELECT changed FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
|
||||
$latest_comment = db_query_range('SELECT cid, timestamp FROM {comment} WHERE nid = :nid AND status = :status ORDER BY timestamp DESC', array(
|
||||
$latest_comment = db_query_range('SELECT cid, timestamp FROM {comment} WHERE nid = :nid AND status = :status ORDER BY timestamp DESC', 0, 1, array(
|
||||
':nid' => $nid,
|
||||
':status' => COMMENT_PUBLISHED,
|
||||
), 0, 1)->fetchObject();
|
||||
))->fetchObject();
|
||||
if ($latest_comment && $latest_comment->timestamp > $changed) {
|
||||
$changed = $latest_comment->timestamp;
|
||||
}
|
||||
|
@ -301,10 +301,10 @@ function _tracker_remove($nid, $uid = NULL, $changed = NULL) {
|
|||
// Comments are a second reason to keep the user's subscription.
|
||||
if (!$keep_subscription) {
|
||||
// Check if the user has commented at least once on the given nid
|
||||
$keep_subscription = db_query_range('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND uid = :uid AND status = 0', array(
|
||||
$keep_subscription = db_query_range('SELECT COUNT(*) FROM {comment} WHERE nid = :nid AND uid = :uid AND status = 0', 0, 1, array(
|
||||
':nid' => $nid,
|
||||
':uid' => $uid,
|
||||
), 0, 1)->fetchField();
|
||||
))->fetchField();
|
||||
}
|
||||
|
||||
// If we haven't found a reason to keep the user's subscription, delete it.
|
||||
|
|
|
@ -281,7 +281,7 @@ function upload_file_load($files) {
|
|||
*/
|
||||
function upload_file_references($file) {
|
||||
// If upload.module is still using a file, do not let other modules delete it.
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', array(':fid' => $file->fid), 0, 1)->fetchField();
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {upload} WHERE fid = :fid', 0, 1, array(':fid' => $file->fid))->fetchField();
|
||||
if ($file_used) {
|
||||
// Return the name of the module and how many references it has to the file.
|
||||
return array('upload' => $count);
|
||||
|
|
|
@ -270,7 +270,7 @@ function user_update_7000(&$sandbox) {
|
|||
$has_rows = FALSE;
|
||||
// Update this many per page load.
|
||||
$count = 1000;
|
||||
$result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", array(), $sandbox['user_from'], $count);
|
||||
$result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 0 ORDER BY uid", $sandbox['user_from'], $count);
|
||||
foreach ($result as $account) {
|
||||
$has_rows = TRUE;
|
||||
$new_hash = user_hash_password($account->pass, $hash_count_log2);
|
||||
|
@ -328,7 +328,7 @@ function user_update_7002(&$sandbox) {
|
|||
$contributed_date_module = db_column_exists('users', 'timezone_name');
|
||||
$contributed_event_module = db_column_exists('users', 'timezone_id');
|
||||
|
||||
$results = db_query_range("SELECT uid FROM {users} ORDER BY uid", array(), $sandbox['user_from'], $count);
|
||||
$results = db_query_range("SELECT uid FROM {users} ORDER BY uid", $sandbox['user_from'], $count);
|
||||
foreach ($results as $account) {
|
||||
$timezone = NULL;
|
||||
// If the contributed Date module has created a users.timezone_name
|
||||
|
@ -434,7 +434,7 @@ function user_update_7004(&$sandbox) {
|
|||
// As a batch operation move the photos into the {file} table and update the
|
||||
// {users} records.
|
||||
$limit = 500;
|
||||
$result = db_query_range("SELECT uid, picture FROM {user} WHERE picture <> '' AND uid > :uid ORDER BY uid", array(':uid' => $sandbox['last_user_processed']), 0, $limit);
|
||||
$result = db_query_range("SELECT uid, picture FROM {user} WHERE picture <> '' AND uid > :uid ORDER BY uid", 0, $limit, array(':uid' => $sandbox['last_user_processed']));
|
||||
foreach ($result as $user) {
|
||||
// Don't bother adding files that don't exist.
|
||||
if (!file_exists($user->picture)) {
|
||||
|
|
|
@ -761,7 +761,7 @@ function user_file_download($filepath) {
|
|||
*/
|
||||
function user_file_references($file) {
|
||||
// Determine if the file is used by this module.
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {users} WHERE picture = :fid', array(':fid' => $file->fid), 0, 1)->fetchField();
|
||||
$file_used = (bool) db_query_range('SELECT 1 FROM {users} WHERE picture = :fid', 0, 1, array(':fid' => $file->fid))->fetchField();
|
||||
if ($file_used) {
|
||||
// Return the name of the module and how many references it has to the file.
|
||||
return array('user' => $count);
|
||||
|
@ -880,7 +880,7 @@ function user_user_validate(&$edit, $account, $category) {
|
|||
if ($error = user_validate_name($edit['name'])) {
|
||||
form_set_error('name', $error);
|
||||
}
|
||||
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:name)", array(':uid' => $uid, ':name' => $edit['name']), 0, 1)->fetchField()) {
|
||||
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:name)", 0, 1, array(':uid' => $uid, ':name' => $edit['name']))->fetchField()) {
|
||||
form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
|
||||
}
|
||||
}
|
||||
|
@ -889,7 +889,7 @@ function user_user_validate(&$edit, $account, $category) {
|
|||
if ($error = user_validate_mail($edit['mail'])) {
|
||||
form_set_error('mail', $error);
|
||||
}
|
||||
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(mail) = LOWER(:mail)", array(':uid' => $uid, ':mail' => $edit['mail']), 0, 1)->fetchField()) {
|
||||
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(mail) = LOWER(:mail)", 0, 1, array(':uid' => $uid, ':mail' => $edit['mail']))->fetchField()) {
|
||||
// Format error message dependent on whether the user is logged in or not.
|
||||
if ($GLOBALS['user']->uid) {
|
||||
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $edit['mail'])));
|
||||
|
@ -1056,7 +1056,7 @@ function user_block_view($delta = '') {
|
|||
case 'new':
|
||||
if (user_access('access content')) {
|
||||
// Retrieve a list of new users who have subsequently accessed the site successfully.
|
||||
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', array(), 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
|
||||
$items = db_query_range('SELECT uid, name FROM {users} WHERE status <> 0 AND access <> 0 ORDER BY created DESC', 0, variable_get('user_block_whois_new_count', 5))->fetchAll();
|
||||
$output = theme('user_list', $items);
|
||||
|
||||
$block['subject'] = t('Who\'s new');
|
||||
|
@ -1092,7 +1092,7 @@ function user_block_view($delta = '') {
|
|||
// Display a list of currently online users.
|
||||
$max_users = variable_get('user_block_max_list_count', 10);
|
||||
if ($authenticated_count && $max_users) {
|
||||
$items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', array(':interval' => $interval), 0, $max_users)->fetchAll();
|
||||
$items = db_query_range('SELECT u.uid, u.name, MAX(s.timestamp) AS max_timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= :interval AND s.uid > 0 GROUP BY u.uid, u.name ORDER BY max_timestamp DESC', 0, $max_users, array(':interval' => $interval))->fetchAll();
|
||||
$output .= theme('user_list', $items, t('Online users'));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
function user_autocomplete($string = '') {
|
||||
$matches = array();
|
||||
if ($string) {
|
||||
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", array(':name' => $string . '%'), 0, 10);
|
||||
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", 0, 10, array(':name' => $string . '%'));
|
||||
foreach ($result as $user) {
|
||||
$matches[$user->name] = check_plain($user->name);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue