本文整理汇总了PHP中db_add_field函数的典型用法代码示例。如果您正苦于以下问题:PHP db_add_field函数的具体用法?PHP db_add_field怎么用?PHP db_add_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了db_add_field函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hook_update_N
/**
* Additional columns and views need to be added to existing fields.
* Below is an example using the addtional column and view defined above.
* my_new_view_additional_data() is schema defined in
* hook_recline_field_columns.
*/
function hook_update_N(&$sandbox)
{
$ret = array();
$fields = field_info_fields();
foreach ($fields as $field_name => $field) {
if ($field['type'] == 'recline_field' && $field['storage']['type'] == 'field_sql_storage') {
foreach ($field['storage']['details']['sql'] as $type => $table_info) {
foreach ($table_info as $table_name => $columns) {
$column_name = _field_sql_storage_columnname($field_name, 'my_new_view_additional_data');
// Adding my_new_view_additional_data.
if (!db_field_exists($table_name, $column_name)) {
// Calling schema defined in hook_recline_field_column().
$schema = my_new_view_additional_data();
db_add_field($table_name, $column_name, $schema);
}
// Adding my_new_view.
$column_name = _field_sql_storage_columnname($field_name, 'my_new_view');
$schema = recline_field_schema();
if (!db_field_exists($table_name, $column_name)) {
db_add_field($table_name, $column_name, $schema['columns']['my_new_view']);
}
field_cache_clear();
}
}
}
}
return $ret;
}
示例2: assertFieldAdditionRemoval
/**
* Asserts that a given field can be added and removed from a table.
*
* The addition test covers both defining a field of a given specification
* when initially creating at table and extending an existing table.
*
* @param $field_spec
* The schema specification of the field.
*/
protected function assertFieldAdditionRemoval($field_spec)
{
// Try creating the field on a new table.
$table_name = 'test_table_' . $this->counter++;
$table_spec = array('fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE), 'test_field' => $field_spec), 'primary key' => array('serial_column'));
db_create_table($table_name, $table_spec);
$this->pass(format_string('Table %table created.', array('%table' => $table_name)));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
// Clean-up.
db_drop_table($table_name);
// Try adding a field to an existing table.
$table_name = 'test_table_' . $this->counter++;
$table_spec = array('fields' => array('serial_column' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE)), 'primary key' => array('serial_column'));
db_create_table($table_name, $table_spec);
$this->pass(format_string('Table %table created.', array('%table' => $table_name)));
// Insert some rows to the table to test the handling of initial values.
for ($i = 0; $i < 3; $i++) {
db_insert($table_name)->useDefaults(array('serial_column'))->execute();
}
db_add_field($table_name, 'test_field', $field_spec);
$this->pass(format_string('Column %column created.', array('%column' => 'test_field')));
// Check the characteristics of the field.
$this->assertFieldCharacteristics($table_name, 'test_field', $field_spec);
// Clean-up.
db_drop_field($table_name, 'test_field');
// Add back the field and then try to delete a field which is also a primary
// key.
db_add_field($table_name, 'test_field', $field_spec);
db_drop_field($table_name, 'serial_column');
db_drop_table($table_name);
}
示例3: update_fix_d7_requirements
/**
* Perform Drupal 6.x to 7.x updates that are required for update.php
* to function properly.
*
* This function runs when update.php is run the first time for 7.x,
* even before updates are selected or performed. It is important
* that if updates are not ultimately performed that no changes are
* made which make it impossible to continue using the prior version.
*/
function update_fix_d7_requirements()
{
$ret = array();
// Rewrite the settings.php file if necessary.
// @see update_prepare_d7_bootstrap().
global $update_rewrite_settings, $db_url;
if (!empty($update_rewrite_settings)) {
$databases = update_parse_db_url($db_url);
file_put_contents(conf_path() . '/settings.php', "\n" . '$databases = ' . var_export($databases, TRUE) . ';', FILE_APPEND);
}
if (drupal_get_installed_schema_version('system') < 7000 && !variable_get('update_d7_requirements', FALSE)) {
// 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']);
variable_set('update_d7_requirements', TRUE);
// 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.'));
}
}
return $ret;
}
示例4: update_fix_d6_requirements
/**
* Perform Drupal 5.x to 6.x updates that are required for update.php
* to function properly.
*
* This function runs when update.php is run the first time for 6.x,
* even before updates are selected or performed. It is important
* that if updates are not ultimately performed that no changes are
* made which make it impossible to continue using the prior version.
* Just adding columns is safe. However, renaming the
* system.description column to owner is not. Therefore, we add the
* system.owner column and leave it to system_update_6008() to copy
* the data from description and remove description. The same for
* renaming locales_target.locale to locales_target.language, which
* will be finished by locale_update_6002().
*/
function update_fix_d6_requirements()
{
$ret = array();
if (drupal_get_installed_schema_version('system') < 6000 && !variable_get('update_d6_requirements', FALSE)) {
$spec = array('type' => 'int', 'size' => 'small', 'default' => 0, 'not null' => TRUE);
db_add_field($ret, 'cache', 'serialized', $spec);
db_add_field($ret, 'cache_filter', 'serialized', $spec);
db_add_field($ret, 'cache_page', 'serialized', $spec);
db_add_field($ret, 'cache_menu', 'serialized', $spec);
db_add_field($ret, 'system', 'info', array('type' => 'text'));
db_add_field($ret, 'system', 'owner', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
if (db_table_exists('locales_target')) {
db_add_field($ret, 'locales_target', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => ''));
}
if (db_table_exists('locales_source')) {
db_add_field($ret, 'locales_source', 'textgroup', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => 'default'));
db_add_field($ret, 'locales_source', 'version', array('type' => 'varchar', 'length' => 20, 'not null' => TRUE, 'default' => 'none'));
}
variable_set('update_d6_requirements', TRUE);
// Create the cache_block table. See system_update_6027() for more details.
$schema['cache_block'] = array('fields' => array('cid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), 'data' => array('type' => 'blob', 'not null' => FALSE, 'size' => 'big'), 'expire' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'created' => array('type' => 'int', 'not null' => TRUE, 'default' => 0), 'headers' => array('type' => 'text', 'not null' => FALSE), 'serialized' => array('type' => 'int', 'size' => 'small', 'not null' => TRUE, 'default' => 0)), 'indexes' => array('expire' => array('expire')), 'primary key' => array('cid'));
db_create_table($ret, 'cache_block', $schema['cache_block']);
// Create the semaphore table now -- the menu system after 6.15 depends on
// this table, and menu code runs in updates prior to the table being
// created in its original update function, system_update_6054().
$schema['semaphore'] = array('fields' => array('name' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), 'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''), 'expire' => array('type' => 'float', 'size' => 'big', 'not null' => TRUE)), 'indexes' => array('expire' => array('expire')), 'primary key' => array('name'));
db_create_table($ret, 'semaphore', $schema['semaphore']);
}
return $ret;
}
示例5: hook_update_N
/**
* Perform a single update.
*
* For each change that requires one or more actions to be performed when
* updating a site, add a new hook_update_N(), which will be called by
* update.php. The documentation block preceding this function is stripped of
* newlines and used as the description for the update on the pending updates
* task list. Schema updates should adhere to the
* @link http://drupal.org/node/150215 Schema API. @endlink
*
* Implementations of hook_update_N() are named (module name)_update_(number).
* The numbers are composed of three parts:
* - 1 digit for Drupal core compatibility.
* - 1 digit for your module's major release version (e.g., is this the 8.x-1.*
* (1) or 8.x-2.* (2) series of your module).
* - 2 digits for sequential counting, starting with 01.
*
* Examples:
* - mymodule_update_8100(): This is the first update to get the database ready
* to run mymodule 8.x-1.*.
* - mymodule_update_8200(): This is the first update to get the database ready
* to run mymodule 8.x-2.*.
*
* As of Drupal 8.0, the database upgrade system no longer supports updating a
* database from an earlier major version of Drupal: update.php can be used to
* upgrade from 7.x-1.x to 7.x-2.x, or 8.x-1.x to 8.x-2.x, but not from 7.x to
* 8.x. Therefore, only update hooks numbered 8001 or later will run for
* Drupal 8. 8000 is reserved for the minimum core schema version and defining
* mymodule_update_8000() will result in an exception. Use the
* @link https://drupal.org/node/2127611 Migration API @endlink instead to
* migrate data from an earlier major version of Drupal.
*
* For further information about releases and release numbers see:
* @link http://drupal.org/node/711070 Maintaining a drupal.org project with Git @endlink
*
* Never renumber update functions.
*
* 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.
*
* Not all module functions are available from within a hook_update_N() function.
* In order to call a function from your mymodule.module or an include file,
* you need to explicitly load that file first.
*
* During database updates the schema of any module could be out of date. For
* this reason, caution is needed when using any API function within an update
* function - particularly CRUD functions, functions that depend on the schema
* (for example by using drupal_write_record()), and any functions that invoke
* hooks.
*
* The $sandbox parameter should be used when a multipass update is needed, in
* circumstances where running the whole update at once could cause PHP to
* timeout. Each pass is run in a way that avoids PHP timeouts, provided each
* pass remains under the timeout limit. To signify that an update requires
* at least one more pass, set $sandbox['#finished'] to a number less than 1
* (you need to do this each pass). The value of $sandbox['#finished'] will be
* unset between passes but all other data in $sandbox will be preserved. The
* system will stop iterating this update when $sandbox['#finished'] is left
* unset or set to a number higher than 1. It is recommended that
* $sandbox['#finished'] is initially set to 0, and then updated each pass to a
* number between 0 and 1 that represents the overall % completed for this
* update, finishing with 1.
*
* See the @link batch Batch operations topic @endlink for more information on
* how to use the Batch API.
*
* @param array $sandbox
* Stores information for multipass updates. See above for more information.
*
* @throws \Drupal\Core\Utility\UpdateException|PDOException
* In case of error, update hooks should throw an instance of
* Drupal\Core\Utility\UpdateException with a meaningful message for the user.
* If a database query fails for whatever reason, it will throw a
* PDOException.
*
* @return string|null
* Optionally, update hooks may return a translated string that will be
* displayed to the user after the update has completed. If no message is
* returned, no message will be presented to the user.
*
* @see batch
* @see schemaapi
* @see hook_update_last_removed()
* @see update_get_update_list()
*/
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.
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.
// 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...
//.........这里部分代码省略.........
示例6: hook_update_N
/**
* 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;
}
示例7: hook_update_N
/**
* 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.
*
* @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.
*/
function hook_update_N()
{
$ret = array();
db_add_field($ret, 'mytable1', 'newcol', array('type' => 'int', 'not null' => TRUE));
return $ret;
}
示例8: changeSchema
public static function changeSchema(array &$field, array $column_renames = array())
{
// Update the field schema
$old_schema = array_intersect_key($field, array('columns' => '', 'indexes' => '', 'foreign keys' => ''));
module_load_install($field['module']);
$new_schema = (array) module_invoke($field['module'], 'field_schema', $field);
$new_schema += array('columns' => array(), 'indexes' => array(), 'foreign keys' => array());
$field['data']['columns'] = $new_schema['columns'];
$field['data']['indexes'] = $new_schema['indexes'];
$field['data']['foreign keys'] = $new_schema['foreign keys'];
$data_table = _field_sql_storage_tablename($field);
$revision_table = _field_sql_storage_revision_tablename($field);
// Validate that all the columns described in the existing schema actually exist.
foreach (array_keys($old_schema['columns']) as $old_column) {
$old_column_name = _field_sql_storage_columnname($field['field_name'], $old_column);
if (!db_field_exists($data_table, $old_column_name)) {
throw new Exception();
}
if (!db_field_exists($revision_table, $old_column_name)) {
throw new Exception();
}
// Attempt to re-use any columns that have the same name.
// This can be skipped by setting $column_renames['column-name'] = FALSE;
if (!empty($new_schema['columns'][$old_column]) && !isset($column_renames[$old_column])) {
$column_renames[$old_column] = $old_column;
}
}
// Validate that any columns to be renamed actually exist.
foreach ($column_renames as $old_column => $new_column) {
if (!isset($old_schema['columns'][$old_column])) {
throw new Exception("Cannot rename field {$field['field_name']} column {$old_column} because it does not exist in the old schema.");
}
if (!isset($new_schema['columns'][$new_column])) {
throw new Exception("Cannot rename field {$field['field_name']} column {$old_column} to {$new_column} because it does not exist in the new schema.");
}
}
// Remove all existing indexes.
foreach ($old_schema['indexes'] as $index => $index_fields) {
$index_name = _field_sql_storage_indexname($field['field_name'], $index);
if (db_index_exists($data_table, $index_name)) {
watchdog('helper', "Dropped index {$data_table}.{$index_name}");
db_drop_index($data_table, $index_name);
}
if (db_index_exists($revision_table, $index_name)) {
watchdog('helper', "Dropped index {$revision_table}.{$index_name}");
db_drop_index($revision_table, $index_name);
}
}
// Rename any columns.
foreach ($column_renames as $old_column => $new_column) {
$old_column_name = _field_sql_storage_columnname($field['field_name'], $old_column);
if ($new_column === FALSE) {
db_drop_field($data_table, $old_column_name);
watchdog('helper', "Dropped column {$data_table}.{$old_column_name}");
db_drop_field($revision_table, $old_column_name);
watchdog('helper', "Dropped column {$revision_table}.{$old_column_name}");
unset($old_schema['columns'][$old_column]);
} else {
$new_column_name = _field_sql_storage_columnname($field['field_name'], $new_column);
db_change_field($data_table, $old_column_name, $new_column_name, $new_schema['columns'][$new_column]);
watchdog('helper', "Changed column {$data_table}.{$old_column_name}<br/><pre>" . print_r($new_schema['columns'][$new_column], TRUE) . '</pre>');
db_change_field($revision_table, $old_column_name, $new_column_name, $new_schema['columns'][$new_column]);
watchdog('helper', "Changed column {$revision_table}.{$old_column_name}<br/><pre>" . print_r($new_schema['columns'][$new_column], TRUE) . '</pre>');
// Remove these fields so they aren't removed or added in the code below.
unset($new_schema['columns'][$new_column]);
unset($old_schema['columns'][$old_column]);
}
}
// Remove any old columns.
$old_columns = array_diff_key($old_schema['columns'], $new_schema['columns']);
foreach (array_keys($old_columns) as $old_column) {
$old_column_name = _field_sql_storage_columnname($field['field_name'], $old_column);
db_drop_field($data_table, $old_column_name);
watchdog('helper', "Dropped column {$data_table}.{$old_column_name}");
db_drop_field($revision_table, $old_column_name);
watchdog('helper', "Dropped column {$revision_table}.{$old_column_name}");
}
// Add any new columns.
$new_columns = array_diff_key($new_schema['columns'], $old_schema['columns']);
foreach (array_keys($new_columns) as $new_column) {
$new_column_name = _field_sql_storage_columnname($field['field_name'], $new_column);
db_add_field($data_table, $new_column_name, $new_schema['columns'][$new_column]);
watchdog('helper', "Added column {$data_table}.{$new_column_name}");
db_add_field($revision_table, $new_column_name, $new_schema['columns'][$new_column]);
watchdog('helper', "Added column {$revision_table}.{$new_column_name}");
}
// Re-add indexes.
foreach ($new_schema['indexes'] as $index => $index_fields) {
foreach ($index_fields as &$index_field) {
if (is_array($index_field)) {
$index_field[0] = _field_sql_storage_columnname($field['field_name'], $index_field[0]);
} else {
$index_field = _field_sql_storage_columnname($field['field_name'], $index_field);
}
}
$index_name = _field_sql_storage_indexname($field['field_name'], $index);
db_add_index($data_table, $index_name, $index_fields);
watchdog('helper', "Added index {$data_table}.{$index_name}<br/><pre>" . print_r($index_fields, TRUE) . '</pre>');
db_add_index($revision_table, $index_name, $index_fields);
watchdog('helper', "Added index {$revision_table}.{$index_name}<br/><pre>" . print_r($index_fields, TRUE) . '</pre>');
//.........这里部分代码省略.........
示例9: db_add_field
Settings::Set("wb_secform_timeout", '7200', false);
Settings::Set("wb_secform_tokenname", 'formtoken', false);
Settings::Set("wb_secform_usefp", false, false);
Settings::Set('fingerprint_with_ip_octets', '0', false);
echo "<br />Removing Secureform selector, no longer needed.<br />";
Settings::Del('secure_form_module');
// No longer needed as Singletab is removed
/**********************************************************
* Adding DB Fields
*/
// Add field "redirect_type" to table "mod_menu_link"
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
db_add_field('redirect_type', 'mod_menu_link', "INT NOT NULL DEFAULT '302' AFTER `target_page_id`");
// Add field "namesection" to table "sections"
echo "<br />Adding field namesection to sections table<br />";
db_add_field('namesection', 'sections', "VARCHAR( 255 ) NULL");
/**********************************************************
* - making sure group_id is set correct there was a big bug in original WB
* WBCE 1.0.0
*/
$table = TABLE_PREFIX . "users";
// set group_id to first group of groups_id
$sql = "UPDATE {$table} SET `group_id` = CAST(groups_id AS SIGNED)";
$query = $database->query($sql);
echo $database->is_error() ? __LINE__ . ': ' . $database->get_error() . '<br />' : '';
// if admin, set group_id to 1
$sql = "UPDATE {$table} SET `group_id` = 1 WHERE FIND_IN_SET('1', groups_id) > '0'";
echo $database->is_error() ? __LINE__ . ': ' . $database->get_error() . '<br />' : '';
$query = $database->query($sql);
/**********************************************************
* - Update search no results database filed to create
示例10: db_update_key_value
*/
echo "<br />Set wysiwyg_editor to ckeditor<br />";
db_update_key_value('settings', 'wysiwyg_editor', 'ckeditor');
/**********************************************************
* - Adding fingerprint_with_ip_octets to settings table
*/
echo "<br />Adding fingerprint_with_ip_octets to settings table<br />";
$cfg = array('sec_token_fingerprint' => defined('SEC_TOKEN_FINGERPRINT') ? SEC_TOKEN_FINGERPRINT : 'true', 'sec_token_netmask4' => defined('SEC_TOKEN_NETMASK4') ? SEC_TOKEN_NETMASK4 : '24', 'sec_token_netmask6' => defined('SEC_TOKEN_NETMASK6') ? SEC_TOKEN_NETMASK6 : '64', 'sec_token_life_time' => defined('SEC_TOKEN_LIFE_TIME') ? SEC_TOKEN_LIFE_TIME : '180', 'wbmailer_smtp_port' => defined('WBMAILER_SMTP_PORT') ? WBMAILER_SMTP_PORT : '25', 'wbmailer_smtp_secure' => defined('WBMAILER_SMTP_SECURE') ? WBMAILER_SMTP_SECURE : 'TLS');
foreach ($cfg as $key => $value) {
db_add_key_value($key, $value);
}
/**********************************************************
* - Add field "redirect_type" to table "mod_menu_link"
*/
echo "<br />Adding field redirect_type to mod_menu_link table<br />";
db_add_field('mod_menu_link', 'redirect_type', "INT NOT NULL DEFAULT '301' AFTER `target_page_id`");
/**********************************************************
* - Update search no results database filed to create
* valid XHTML if search is empty
*/
if (version_compare(WB_VERSION, '2.8', '<')) {
echo "<br />Updating database field `no_results` of search table: ";
$search_no_results = addslashes('<tr><td><p>[TEXT_NO_RESULTS]</p></td></tr>');
$sql = 'UPDATE `' . TABLE_PREFIX . 'search` ';
$sql .= 'SET `value`=\'' . $search_no_results . '\' ';
$sql .= 'WHERE `name`=\'no_results\'';
echo $database->query($sql) ? ' $OK<br />' : ' $FAIL<br />';
}
/* *****************************************************************************
* - check for deprecated / never needed files
*/
示例11: db_add_field
echo "<br />Adding field image to pages table<br />";
db_add_field('image', 'pages', "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''");
echo "<br />Adding field thumb to pages table<br />";
db_add_field('thumb', 'pages', "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''");
echo "<br />Adding field image2 to pages table<br />";
db_add_field('image2', 'pages', "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''");
echo "<br />Adding field image3 to pages table<br />";
db_add_field('image3', 'pages', "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''");
echo "<br />Adding field image4 to pages table<br />";
db_add_field('image4', 'pages', "varchar(255) collate utf8_unicode_ci NOT NULL DEFAULT ''");
echo "<br />Adding field publish to pages table<br />";
db_add_field('publish', 'pages', "int(11) NOT NULL DEFAULT '0'");
echo "<br />Adding unpublish icon to pages table<br />";
db_add_field('unpublish', 'pages', "int(11) NOT NULL DEFAULT '0'");
echo "<br />Adding direct_link icon to pages table<br />";
db_add_field('dlink', 'pages', "text collate utf8_unicode_ci NOT NULL DEFAULT '' AFTER link");
/**********************************************************
* - making sure group_id is set correct there was a big bug in original WB
* WBCE 1.0.0
*/
$table = TABLE_PREFIX . "users";
// set group_id to first group of groups_id
$sql = "UPDATE {$table} SET `group_id` = CAST(groups_id AS SIGNED)";
$query = $database->query($sql);
echo $database->is_error() ? __LINE__ . ': ' . $database->get_error() . '<br />' : '';
// if admin, set group_id to 1
$sql = "UPDATE {$table} SET `group_id` = 1 WHERE FIND_IN_SET('1', groups_id) > '0'";
echo $database->is_error() ? __LINE__ . ': ' . $database->get_error() . '<br />' : '';
$query = $database->query($sql);
/**********************************************************
* - Update search no results database filed to create
示例12: hook_update_N
/**
* 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;
}