コード例 #1
0
ファイル: system.api.php プロジェクト: nicklewisatx/drupal
/**
 * Perform a single update. For each patch which requires a database change add
 * a new hook_update_N() which will be called by update.php.
 *
 * The database updates are numbered sequentially according to the version of Drupal you are compatible with.
 *
 * Schema updates should adhere to the Schema API:
 * @link http://drupal.org/node/150215 http://drupal.org/node/150215 @endlink
 *
 * Database updates consist of 3 parts:
 * - 1 digit for Drupal core compatibility
 * - 1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
 * - 2 digits for sequential counting starting with 00
 *
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal
 * core API.
 *
 * Examples:
 * - mymodule_update_5200()
 *   - This is the first update to get the database ready to run mymodule 5.x-2.*.
 * - mymodule_update_6000()
 *   - This is the required update for mymodule to run with Drupal core API 6.x.
 * - mymodule_update_6100()
 *   - This is the first update to get the database ready to run mymodule 6.x-1.*.
 * - mymodule_update_6200()
 *   - This is the first update to get the database ready to run mymodule 6.x-2.*.
 *     Users can directly update from 5.x-2.* to 6.x-2.* and they get all 60XX
 *     and 62XX updates, but not 61XX updates, because those reside in the
 *     6.x-1.x branch only.
 *
 * A good rule of thumb is to remove updates older than two major releases of
 * Drupal. See hook_update_last_removed() to notify Drupal about the removals.
 *
 * Never renumber update functions.
 *
 * Further information about releases and release numbers:
 * - @link http://drupal.org/handbook/version-info http://drupal.org/handbook/version-info @endlink
 * - @link http://drupal.org/node/93999 http://drupal.org/node/93999 @endlink (Overview of contributions branches and tags)
 * - @link http://drupal.org/handbook/cvs/releases http://drupal.org/handbook/cvs/releases @endlink
 *
 * Implementations of this hook should be placed in a mymodule.install file in
 * the same directory as mymodule.module. Drupal core's updates are implemented
 * using the system module as a name and stored in database/updates.inc.
 *
 * 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
 * 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.
 */
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;
    // 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!)
    if (!isset($sandbox['progress'])) {
        $sandbox['progress'] = 0;
        $sandbox['current_uid'] = 0;
        // We'll -1 to disregard the uid 0...
        $sandbox['max'] = db_query('SELECT COUNT(DISTINCT uid) FROM {users}')->fetchField() - 1;
    }
    db_select('users', 'u')->fields('u', array('uid', 'name'))->condition('uid', $sandbox['current_uid'], '>')->range(0, 3)->orderBy('uid', 'ASC')->execute();
    foreach ($users as $user) {
        $user->name .= '!';
        $ret[] = update_sql("UPDATE {users} SET name = '{$user->name}' WHERE uid = {$user->uid}");
        $sandbox['progress']++;
        $sandbox['current_uid'] = $user->uid;
    }
    $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
    return $ret;
}
コード例 #2
0
ファイル: update.php プロジェクト: veggieryan/drupal
/**
 * Disable anything in the {system} table that is not compatible with the
 * current version of Drupal core.
 */
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;
        }
    }
    if (!empty($incompatible)) {
        $ret[] = update_sql("UPDATE {system} SET status = 0 WHERE name IN ('" . implode("','", $incompatible) . "')");
    }
    return $ret;
}
コード例 #3
0
function drupal_update_131()
{
    $ret = array();
    $ret[] = update_sql("ALTER TABLE {locales_source} CHANGE location location varchar(255) NOT NULL default ''");
    return $ret;
}
コード例 #4
0
ファイル: update.php プロジェクト: shjalayeri/Blood-Money
function update_70()
{
    update_sql("ALTER TABLE {variable} CHANGE name name varchar(48) NOT NULL");
}
コード例 #5
0
function fanli($username, $fxje, $tgje, $order_code, $merchant_id)
{
    if (JIFENOPEN == 1 && JIFENBL > 0) {
        $jifen = round($fxje * JIFENBL);
        if ($jifen > 0) {
            $msg_tabao_jifen = $jifen . "积分!";
        }
    } else {
        $jifen = 0;
    }
    $field_arr = array('money' => $fxje, 'jifen' => $jifen, 'dengji' => 1);
    update_sql('user', $field_arr, "ddusername='******'", 1);
    //增加会员金额,积分和等级
    //用户消息
    $title = '您获得了新的商城交易返现!';
    $trade_id = $order_code;
    $msg_tabao = "您获得了新的交易返现," . $merchant_id . "商城订单号" . $order_code . "返现金额" . $fxje . '!' . $msg_tabao_jifen;
    $filed_arr = array('title' => $title, 'content' => $msg_tabao, 'addtime' => date('Y-m-d H:i:s'), 'see' => 0, 'ddusername' => $ddusername, 'senduser' => '网站客服');
    insert_one_sql("msg", $filed_arr);
    //用户明细
    $shijian = "商城交易返现";
    $memo = $merchant_id . "交易号{$order_code}";
    $filed_arr = array('ddusername' => $ddusername, 'shijian' => $shijian, 'addtime' => date('Y-m-d H:i:s'), 'je' => $fxje, 'jifen' => $jifen, 'memo' => $memo);
    insert_one_sql("mingxi", $filed_arr);
    //求推荐人
    $tjrid = sel_sql("user", "tjr", "ddusername='******'");
    if ($tjrid > 0) {
        $tjrname = sel_sql("user", "ddusername", "Id='{$tjrid}'");
        //增加推荐人佣金
        $field_arr = array('money' => $tgje);
        update_sql("user", $field_arr, "Id='{$tjrid}'", 1);
        //用户消息
        $title = '您获得了新的推广佣金!';
        $msg_taobaotuiguang = "您获得了新的推广佣金" . $tgje;
        $filed_arr = array('title' => $title, 'content' => $msg_taobaotuiguang, 'addtime' => date('Y-m-d H:i:s'), 'see' => 0, 'ddusername' => $tjrname, 'senduser' => '网站客服');
        insert_one_sql("msg", $filed_arr);
        //用户明细
        $shijian = "推广佣金";
        $memo = "交易人{$ddusername}";
        $filed_arr = array('ddusername' => $tjrname, 'shijian' => $shijian, 'addtime' => date('Y-m-d H:i:s'), 'je' => $tgje, 'memo' => $memo);
        insert_one_sql("mingxi", $filed_arr);
    }
}
コード例 #6
0
 protected function computeSimilarityDatabase()
 {
     watchdog("recommender", "Computing similarity in database. Might take a long time. Please be patient.");
     if ($this->fieldWeight === NULL) {
         $count = "COUNT(*)";
         // if no $fieldWeight is specified, just count the occurrences.
     } else {
         // otherwise, use the weight.
         $count = "SUM((n1.{$this->fieldWeight}+n2.{$this->fieldWeight})/2)";
     }
     $sql = "INSERT INTO {recommender_similarity}(app_id, mouse1_id, mouse2_id, similarity, created)\n                SELECT {$this->appId}, n1.{$this->fieldMouse}, n2.{$this->fieldMouse}, {$count}, {$this->created}\n                FROM {{$this->tableName}} n1 INNER JOIN {{$this->tableName}} n2 ON n1.{$this->fieldCheese}=n2.{$this->fieldCheese}\n                GROUP BY n1.{$this->fieldMouse}, n2.{$this->fieldMouse}";
     update_sql($sql);
     $this->purgeOutdatedRecords('similarity');
 }
コード例 #7
0
/**
 * Create tables for the split cache.
 *
 * This is part of the Drupal 4.7.x to 5.x migration.
 */
function update_create_cache_tables()
{
    // If cache_filter exists, update is not necessary
    if (db_table_exists('cache_filter')) {
        return;
    }
    $ret = array();
    switch ($GLOBALS['db_type']) {
        case 'mysql':
        case 'mysqli':
            $ret[] = update_sql("CREATE TABLE {cache_filter} (\n        cid varchar(255) NOT NULL default '',\n        data longblob,\n        expire int NOT NULL default '0',\n        created int NOT NULL default '0',\n        headers text,\n        PRIMARY KEY (cid),\n        INDEX expire (expire)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
            $ret[] = update_sql("CREATE TABLE {cache_menu} (\n        cid varchar(255) NOT NULL default '',\n        data longblob,\n        expire int NOT NULL default '0',\n        created int NOT NULL default '0',\n        headers text,\n        PRIMARY KEY (cid),\n        INDEX expire (expire)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
            $ret[] = update_sql("CREATE TABLE {cache_page} (\n        cid varchar(255) BINARY NOT NULL default '',\n        data longblob,\n        expire int NOT NULL default '0',\n         created int NOT NULL default '0',\n        headers text,\n        PRIMARY KEY (cid),\n        INDEX expire (expire)\n      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
            break;
        case 'pgsql':
            $ret[] = update_sql("CREATE TABLE {cache_filter} (\n        cid varchar(255) NOT NULL default '',\n        data bytea,\n        expire int NOT NULL default '0',\n        created int NOT NULL default '0',\n        headers text,\n        PRIMARY KEY (cid)\n     )");
            $ret[] = update_sql("CREATE TABLE {cache_menu} (\n       cid varchar(255) NOT NULL default '',\n       data bytea,\n       expire int NOT NULL default '0',\n       created int NOT NULL default '0',\n       headers text,\n       PRIMARY KEY (cid)\n     )");
            $ret[] = update_sql("CREATE TABLE {cache_page} (\n       cid varchar(255) NOT NULL default '',\n       data bytea,\n       expire int NOT NULL default '0',\n       created int NOT NULL default '0',\n       headers text,\n       PRIMARY KEY (cid)\n     )");
            $ret[] = update_sql("CREATE INDEX {cache_filter}_expire_idx ON {cache_filter} (expire)");
            $ret[] = update_sql("CREATE INDEX {cache_menu}_expire_idx ON {cache_menu} (expire)");
            $ret[] = update_sql("CREATE INDEX {cache_page}_expire_idx ON {cache_page} (expire)");
            break;
    }
    return $ret;
}
コード例 #8
0
ファイル: update.php プロジェクト: skellystarman/drupaldev
/**
 * Convert a single MySQL table to UTF-8.
 *
 * We change all text columns to their corresponding binary type,
 * then back to text, but with a UTF-8 character set.
 * See: http://dev.mysql.com/doc/refman/4.1/en/charset-conversion.html
 */
function update_convert_table_utf8($table)
{
    $ret = array();
    $types = array('char' => 'binary', 'varchar' => 'varbinary', 'tinytext' => 'tinyblob', 'text' => 'blob', 'mediumtext' => 'mediumblob', 'longtext' => 'longblob');
    // Get next table in list
    $convert_to_binary = array();
    $convert_to_utf8 = array();
    // Set table default charset
    $ret[] = update_sql('ALTER TABLE {' . $table . '} DEFAULT CHARACTER SET utf8');
    // Find out which columns need converting and build SQL statements
    $result = db_query('SHOW FULL COLUMNS FROM {' . $table . '}');
    while ($column = db_fetch_array($result)) {
        list($type) = explode('(', $column['Type']);
        if (isset($types[$type])) {
            $names = 'CHANGE `' . $column['Field'] . '` `' . $column['Field'] . '` ';
            $attributes = ' DEFAULT ' . ($column['Default'] == 'NULL' ? 'NULL ' : "'" . db_escape_string($column['Default']) . "' ") . ($column['Null'] == 'YES' ? 'NULL' : 'NOT NULL');
            $convert_to_binary[] = $names . preg_replace('/' . $type . '/i', $types[$type], $column['Type']) . $attributes;
            $convert_to_utf8[] = $names . $column['Type'] . ' CHARACTER SET utf8' . $attributes;
        }
    }
    if (count($convert_to_binary)) {
        // Convert text columns to binary
        $ret[] = update_sql('ALTER TABLE {' . $table . '} ' . implode(', ', $convert_to_binary));
        // Convert binary columns to UTF-8
        $ret[] = update_sql('ALTER TABLE {' . $table . '} ' . implode(', ', $convert_to_utf8));
    }
    return $ret;
}
コード例 #9
0
ファイル: install.php プロジェクト: t-web/drupal-doxygen-base
/**
 * Perform a single update.
 *
 * For each patch which requires a database change add a new hook_update_N()
 * which will be called by update.php. The database updates are numbered
 * sequentially according to the version of Drupal you are compatible with.
 *
 * Schema updates should adhere to the Schema API: http://drupal.org/node/150215
 *
 * Database updates consist of 3 parts:
 * - 1 digit for Drupal core compatibility
 * - 1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
 * - 2 digits for sequential counting starting with 00
 *
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal
 * core API.
 *
 * Examples:
 * - mymodule_update_5200()
 *   - This is the first update to get the database ready to run mymodule 5.x-2.*.
 * - mymodule_update_6000()
 *   - This is the required update for mymodule to run with Drupal core API 6.x.
 * - mymodule_update_6100()
 *   - This is the first update to get the database ready to run mymodule 6.x-1.*.
 * - mymodule_update_6200()
 *   - This is the first update to get the database ready to run mymodule 6.x-2.*.
 *     Users can directly update from 5.x-2.* to 6.x-2.* and they get all 60XX
 *     and 62XX updates, but not 61XX updates, because those reside in the
 *     6.x-1.x branch only.
 *
 * A good rule of thumb is to remove updates older than two major releases of
 * Drupal. See hook_update_last_removed() to notify Drupal about the removals.
 *
 * Never renumber update functions.
 *
 * Further information about releases and release numbers:
 * - http://drupal.org/handbook/version-info
 * - http://drupal.org/node/93999 (Overview of contributions branches and tags)
 * - http://drupal.org/handbook/cvs/releases
 *
 * Implementations of this hook should be placed in a mymodule.install file in
 * the same directory as mymodule.module. Drupal core's updates are implemented
 * using the system module as a name and stored in database/updates.inc.
 *
 * @return An array with the results of the calls to update_sql(). An update
 *   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.
 */
function hook_update_N(&$sandbox)
{
    // For non-multipass updates, the signature can simply be;
    // function hook_update_N() {
    // For most updates, the following is sufficient.
    $ret = array();
    db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE));
    return $ret;
    // 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!)
    if (!isset($sandbox['progress'])) {
        $sandbox['progress'] = 0;
        $sandbox['current_uid'] = 0;
        // We'll -1 to disregard the uid 0...
        $sandbox['max'] = db_result(db_query('SELECT COUNT(DISTINCT uid) FROM {users}')) - 1;
    }
    $users = db_query_range("SELECT uid, name FROM {users} WHERE uid > %d ORDER BY uid ASC", $sandbox['current_uid'], 0, 3);
    while ($user = db_fetch_object($users)) {
        $user->name .= '!';
        $ret[] = update_sql("UPDATE {users} SET name = '{$user->name}' WHERE uid = {$user->uid}");
        $sandbox['progress']++;
        $sandbox['current_uid'] = $user->uid;
    }
    $ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
    return $ret;
}