本文整理汇总了PHP中drupal_get_installed_schema_version函数的典型用法代码示例。如果您正苦于以下问题:PHP drupal_get_installed_schema_version函数的具体用法?PHP drupal_get_installed_schema_version怎么用?PHP drupal_get_installed_schema_version使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了drupal_get_installed_schema_version函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$status = $input->getOption('status');
$type = $input->getOption('type');
if (strtolower($status) == 'enabled') {
$status = 1;
} elseif (strtolower($status) == 'disabled') {
$status = 0;
} else {
$status = -1;
}
if (strtolower($type) == 'core') {
$type = 'core';
} elseif (strtolower($type) == 'no-core') {
$type = '';
} else {
$type = null;
}
$tableHeader = [$this->trans('commands.module.debug.messages.id'), $this->trans('commands.module.debug.messages.name'), $this->trans('commands.module.debug.messages.status'), $this->trans('commands.module.debug.messages.package'), $this->trans('commands.module.debug.messages.schema-version'), $this->trans('commands.module.debug.messages.origin')];
$tableRows = [];
$modules = system_rebuild_module_data();
foreach ($modules as $module_id => $module) {
if ($status >= 0 && $status != $module->status) {
continue;
}
if ($type !== null && $type !== $module->origin) {
continue;
}
$module_status = $module->status ? $this->trans('commands.module.debug.messages.enabled') : $this->trans('commands.module.debug.messages.disabled');
$schema_version = drupal_get_installed_schema_version($module_id) != -1 ? drupal_get_installed_schema_version($module_id) : '';
$tableRows[] = [$module_id, $module->info['name'], $module_status, $module->info['package'], $schema_version, $module->origin];
}
$io->table($tableHeader, $tableRows, 'compact');
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Get a list of all available modules.
$modules = system_rebuild_module_data();
$uninstallable = array_filter($modules, function ($module) use($modules) {
return empty($modules[$module->getName()]->info['required']) && drupal_get_installed_schema_version($module->getName()) > SCHEMA_UNINSTALLED && $module->getName() !== 'devel';
});
$form['filters'] = array('#type' => 'container', '#attributes' => array('class' => array('table-filter', 'js-show')));
$form['filters']['text'] = array('#type' => 'search', '#title' => $this->t('Search'), '#size' => 30, '#placeholder' => $this->t('Enter module name'), '#attributes' => array('class' => array('table-filter-text'), 'data-table' => '#devel-reinstall-form', 'autocomplete' => 'off', 'title' => $this->t('Enter a part of the module name or description to filter by.')));
// Only build the rest of the form if there are any modules available to
// uninstall;
if (empty($uninstallable)) {
return $form;
}
$header = array('name' => $this->t('Name'), 'description' => $this->t('Description'));
$rows = array();
foreach ($uninstallable as $module) {
$name = $module->info['name'] ?: $module->getName();
$rows[$module->getName()] = array('name' => array('data' => array('#type' => 'inline_template', '#template' => '<label class="module-name table-filter-text-source">{{ module_name }}</label>', '#context' => array('module_name' => $name))), 'description' => array('data' => $module->info['description'], 'class' => array('description')));
}
$form['reinstall'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $rows, '#js_select' => FALSE, '#empty' => $this->t('No modules are available to uninstall.'));
$form['#attached']['library'][] = 'system/drupal.system.modules';
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Reinstall'));
return $form;
}
示例3: testRequiredModuleSchemaVersions
/**
* Tests recorded schema versions of early installed modules in the installer.
*/
public function testRequiredModuleSchemaVersions()
{
$version = drupal_get_installed_schema_version('system', TRUE);
$this->assertTrue($version > 0, 'System module version is > 0.');
$version = drupal_get_installed_schema_version('user', TRUE);
$this->assertTrue($version > 0, 'User module version is > 0.');
}
示例4: update_script_selection_form
function update_script_selection_form()
{
$form = array();
$form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#title' => 'Select versions', '#collapsible' => TRUE, '#collapsed' => TRUE);
// Ensure system.module's updates appear first
$form['start']['system'] = array();
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
foreach ($modules as $module => $schema_version) {
$updates = drupal_get_schema_versions($module);
// Skip incompatible module updates completely, otherwise test schema versions.
if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
// module_invoke returns NULL for nonexisting hooks, so if no updates
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
$form['start'][$module] = array('#value' => '<em>' . $module . '</em> module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.', '#prefix' => '<div class="warning">', '#suffix' => '</div>');
$form['start']['#collapsed'] = FALSE;
continue;
}
$updates = drupal_map_assoc($updates);
$updates[] = 'No updates available';
$default = $schema_version;
foreach (array_keys($updates) as $update) {
if ($update > $schema_version) {
$default = $update;
break;
}
}
$form['start'][$module] = array('#type' => 'select', '#title' => $module . ' module', '#default_value' => $default, '#options' => $updates);
}
}
$form['has_js'] = array('#type' => 'hidden', '#default_value' => FALSE);
$form['submit'] = array('#type' => 'submit', '#value' => 'Update');
return $form;
}
示例5: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
$this->get('site')->loadLegacyFile('/core/modules/system/system.module');
$status = strtolower($input->getOption('status'));
$type = strtolower($input->getOption('type'));
$modules = strtolower($input->getArgument('module'));
if ($modules) {
$config = $this->getApplication()->getConfig();
$repo = $config->get('application.composer.repositories.default');
foreach ($modules as $module) {
$url = sprintf('%s/packages/drupal/%s.json', $config->get('application.composer.packages.default'), $module);
try {
$data = $this->getApplication()->getHttpClientHelper()->getUrlAsJson($repo . $url);
} catch (\Exception $e) {
$io->error(sprintf($this->trans('commands.module.debug.messages.no-results'), $module));
return 1;
}
$tableHeader = ['<info>' . $data->package->name . '</info>'];
$tableRows = [];
$tableRows[] = [$data->package->description];
$tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-downloads') . '</comment>', $data->package->downloads->total];
$tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-monthly') . '</comment>', $data->package->downloads->monthly];
$tableRows[] = ['<comment>' . $this->trans('commands.module.debug.messages.total-daily') . '</comment>', $data->package->downloads->daily];
$io->table($tableHeader, $tableRows, 'compact');
}
return 0;
}
if ($status == 'installed') {
$status = 1;
} elseif ($status == 'uninstalled') {
$status = 0;
} else {
$status = -1;
}
if ($type == 'core') {
$type = 'core';
} elseif ($type == 'no-core') {
$type = '';
} else {
$type = null;
}
$tableHeader = [$this->trans('commands.module.debug.messages.id'), $this->trans('commands.module.debug.messages.name'), $this->trans('commands.module.debug.messages.package'), $this->trans('commands.module.debug.messages.version'), $this->trans('commands.module.debug.messages.schema-version'), $this->trans('commands.module.debug.messages.status'), $this->trans('commands.module.debug.messages.origin')];
$tableRows = [];
$modules = system_rebuild_module_data();
foreach ($modules as $module_id => $module) {
if ($status >= 0 && $status != $module->status) {
continue;
}
if ($type !== null && $type !== $module->origin) {
continue;
}
$module_status = $module->status ? $this->trans('commands.module.debug.messages.installed') : $this->trans('commands.module.debug.messages.uninstalled');
$module_origin = $module->origin ? $module->origin : 'no core';
$schema_version = drupal_get_installed_schema_version($module_id) != -1 ? drupal_get_installed_schema_version($module_id) : '';
$tableRows[] = [$module_id, $module->info['name'], $module->info['package'], $module->info['version'], $schema_version, $module_status, $module_origin];
}
$io->table($tableHeader, $tableRows, 'compact');
}
示例6: testRequiredModuleSchemaVersions
/**
* Tests recorded schema versions of early installed modules in the installer.
*/
public function testRequiredModuleSchemaVersions()
{
$version = drupal_get_installed_schema_version('system', TRUE);
$this->assertTrue($version > 0, 'System module version is > 0.');
$version = drupal_get_installed_schema_version('user', TRUE);
$this->assertTrue($version > 0, 'User module version is > 0.');
$post_update_key_value = \Drupal::keyValue('post_update');
$existing_updates = $post_update_key_value->get('existing_updates', []);
$this->assertTrue(in_array('module_test_post_update_test', $existing_updates));
}
示例7: testUpdateHookN
/**
* Test that updates are properly run.
*/
public function testUpdateHookN()
{
// Increment the schema version.
\Drupal::state()->set('update_test_schema_version', 8001);
$this->runUpdates();
// Ensure schema has changed.
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
// Ensure the index was added for column a.
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
示例8: update_script_selection_form
function update_script_selection_form()
{
$form = array();
$count = 0;
$form['start'] = array('#tree' => TRUE, '#type' => 'fieldset', '#collapsed' => TRUE, '#collapsible' => TRUE);
// Ensure system.module's updates appear first
$form['start']['system'] = array();
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
foreach ($modules as $module => $schema_version) {
$pending = array();
$updates = drupal_get_schema_versions($module);
// Skip incompatible module updates completely, otherwise test schema versions.
if (!update_check_incompatibility($module) && $updates !== FALSE && $schema_version >= 0) {
// module_invoke returns NULL for nonexisting hooks, so if no updates
// are removed, it will == 0.
$last_removed = module_invoke($module, 'update_last_removed');
if ($schema_version < $last_removed) {
$form['start'][$module] = array('#title' => $module, '#item' => '<em>' . $module . '</em> module can not be updated. Its schema version is ' . $schema_version . '. Updates up to and including ' . $last_removed . ' have been removed in this release. In order to update <em>' . $module . '</em> module, you will first <a href="http://drupal.org/upgrade">need to upgrade</a> to the last version in which these updates were available.', '#prefix' => '<div class="warning">', '#suffix' => '</div>');
continue;
}
$updates = drupal_map_assoc($updates);
foreach (array_keys($updates) as $update) {
if ($update > $schema_version) {
// The description for an update comes from its Doxygen.
$func = new ReflectionFunction($module . '_update_' . $update);
$description = str_replace(array("\n", '*', '/'), '', $func->getDocComment());
$pending[] = "{$update} - {$description}";
if (!isset($default)) {
$default = $update;
}
}
}
if (!empty($pending)) {
if (!isset($default)) {
$default = $schema_version;
}
$form['start'][$module] = array('#type' => 'hidden', '#value' => $default);
$form['start'][$module . '_updates'] = array('#markup' => theme('item_list', $pending, $module . ' module'));
}
}
unset($default);
$count = $count + count($pending);
}
if (empty($count)) {
drupal_set_message(t('No pending updates.'));
unset($form);
$form['links'] = array('#markup' => theme('item_list', update_helpful_links()));
} else {
$form['help'] = array('#markup' => '<p>The version of Drupal you are updating from has been automatically detected.</p>', '#weight' => -5);
$form['start']['#title'] = strtr('!num pending updates', array('!num' => $count));
$form['has_js'] = array('#type' => 'hidden', '#default_value' => FALSE);
$form['submit'] = array('#type' => 'submit', '#value' => 'Apply pending updates');
}
return $form;
}
示例9: testWith7x
function testWith7x()
{
// Ensure that the minimum schema version is 8000, despite 7200 update
// hooks and a 7XXX hook_update_last_removed().
$this->assertEqual(drupal_get_installed_schema_version('update_test_with_7x'), 8000);
// Try to manually set the schema version to 7110 and ensure that no
// updates are allowed.
drupal_set_installed_schema_version('update_test_with_7x', 7110);
// Click through update.php with 'administer software updates' permission.
$this->drupalLogin($this->update_user);
$this->drupalPostForm($this->update_url, array(), t('Continue'), array('external' => TRUE));
$this->assertText(t('Some of the pending updates cannot be applied because their dependencies were not met.'));
}
示例10: block_post_update_disable_blocks_with_missing_contexts
/**
* Disable all blocks with missing context IDs in block_update_8001().
*/
function block_post_update_disable_blocks_with_missing_contexts()
{
// Don't execute the function if block_update_8002() got executed already,
// which used to do the same. Note: Its okay to check here, because
// update_do_one() does not update the installed schema version until the
// batch is finished.
$module_schema = drupal_get_installed_schema_version('block');
// The state entry 'block_update_8002_placeholder' is used in order to
// indicate that the placeholder block_update_8002() function has been
// executed, so this function needs to be executed as well. If the non
// placeholder version of block_update_8002() got executed already, the state
// won't be set and we skip this update.
if ($module_schema >= 8002 && !\Drupal::state()->get('block_update_8002_placeholder', FALSE)) {
return;
}
// Cleanup the state entry as its no longer needed.
\Drupal::state()->delete('block_update_8002');
$block_update_8001 = \Drupal::keyValue('update_backup')->get('block_update_8001', []);
$block_ids = array_keys($block_update_8001);
$block_storage = \Drupal::entityManager()->getStorage('block');
$blocks = $block_storage->loadMultiple($block_ids);
/** @var $blocks \Drupal\block\BlockInterface[] */
foreach ($blocks as $block) {
// This block has had conditions removed due to an inability to resolve
// contexts in block_update_8001() so disable it.
// Disable currently enabled blocks.
if ($block_update_8001[$block->id()]['status']) {
$block->setStatus(FALSE);
$block->save();
}
}
// Provides a list of plugin labels, keyed by plugin ID.
$condition_plugin_id_label_map = array_column(\Drupal::service('plugin.manager.condition')->getDefinitions(), 'label', 'id');
// Override with the UI labels we are aware of. Sadly they are not machine
// accessible, see
// \Drupal\node\Plugin\Condition\NodeType::buildConfigurationForm().
$condition_plugin_id_label_map['node_type'] = t('Content types');
$condition_plugin_id_label_map['request_path'] = t('Pages');
$condition_plugin_id_label_map['user_role'] = t('Roles');
if (count($block_ids) > 0) {
$message = t('Encountered an unknown context mapping key coming probably from a contributed or custom module: One or more mappings could not be updated. Please manually review your visibility settings for the following blocks, which are disabled now:');
$message .= '<ul>';
foreach ($blocks as $disabled_block_id => $disabled_block) {
$message .= '<li>' . t('@label (Visibility: @plugin_ids)', array('@label' => $disabled_block->get('settings')['label'], '@plugin_ids' => implode(', ', array_intersect_key($condition_plugin_id_label_map, array_flip(array_keys($block_update_8001[$disabled_block_id]['missing_context_ids'])))))) . '</li>';
}
$message .= '</ul>';
return $message;
}
}
示例11: testUpdateHookN
/**
* Test that updates are properly run.
*/
public function testUpdateHookN()
{
// Increment the schema version.
\Drupal::state()->set('update_test_schema_version', 8001);
$this->runUpdates();
$select = \Drupal::database()->select('watchdog');
$select->orderBy('wid', 'DESC');
$select->range(0, 5);
$select->fields('watchdog', ['message']);
$container_cannot_be_saved_messages = array_filter(iterator_to_array($select->execute()), function ($row) {
return strpos($row->message, 'Container cannot be saved to cache.') !== FALSE;
});
$this->assertEqual([], $container_cannot_be_saved_messages);
// Ensure schema has changed.
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
// Ensure the index was added for column a.
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
示例12: testUpdateHooks
/**
* Tests that update hooks are properly run.
*/
public function testUpdateHooks()
{
// Verify that the 8000 schema is in place.
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema'), 8000);
$this->assertFalse(db_index_exists('update_test_schema_table', 'test'), 'Version 8000 of the update_test_schema module is installed.');
// Increment the schema version.
\Drupal::state()->set('update_test_schema_version', 8001);
$this->drupalLogin($this->user);
$this->drupalGet($this->updateUrl, ['external' => TRUE]);
$this->clickLink(t('Continue'));
$this->assertRaw('Schema version 8001.');
// Run the update hooks.
$this->clickLink(t('Apply pending updates'));
// Ensure schema has changed.
$this->assertEqual(drupal_get_installed_schema_version('update_test_schema', TRUE), 8001);
// Ensure the index was added for column a.
$this->assertTrue(db_index_exists('update_test_schema_table', 'test'), 'Version 8001 of the update_test_schema module is installed.');
}
示例13: getAllModules
protected function getAllModules($status, $type, $output, $table)
{
$this->getDrupalHelper()->loadLegacyFile('/core/includes/schema.inc');
$table->setHeaders([$this->trans('commands.module.debug.messages.id'), $this->trans('commands.module.debug.messages.name'), $this->trans('commands.module.debug.messages.status'), $this->trans('commands.module.debug.messages.package'), $this->trans('commands.module.debug.messages.schema-version'), $this->trans('commands.module.debug.messages.origin')]);
$table->setlayout($table::LAYOUT_COMPACT);
$modules = system_rebuild_module_data();
foreach ($modules as $module_id => $module) {
if ($status >= 0 && $status != $module->status) {
continue;
}
if ($type !== null && $type !== $module->origin) {
continue;
}
$module_status = $module->status ? $this->trans('commands.module.debug.messages.enabled') : $this->trans('commands.module.debug.messages.disabled');
$schema_version = drupal_get_installed_schema_version($module_id) != -1 ? drupal_get_installed_schema_version($module_id) : '';
$table->addRow([$module_id, $module->info['name'], $module_status, $module->info['package'], $schema_version, $module->origin]);
}
$table->render($output);
}
示例14: testDatabaseLoaded
/**
* Tests that the database was properly loaded.
*/
public function testDatabaseLoaded()
{
$hook_updates = ['user' => '8000', 'node' => '8003', 'system' => '8013'];
foreach ($hook_updates as $module => $schema) {
$this->assertEqual(drupal_get_installed_schema_version($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
}
// Test post_update key value stores contains a list of the update functions
// that have run.
$existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
$expected_updates = ['system_post_update_recalculate_configuration_entity_dependencies', 'field_post_update_save_custom_storage_property', 'field_post_update_entity_reference_handler_setting', 'block_post_update_disable_blocks_with_missing_contexts', 'views_post_update_update_cacheability_metadata'];
foreach ($expected_updates as $expected_update) {
$this->assertEqual($existing_updates[$expected_update], 1, new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
}
// @todo there are no updates to run.
// $this->runUpdates();
$this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
$this->drupalGet('<front>');
$this->assertText('Site-Install');
}
示例15: testDatabaseLoaded
/**
* Tests that the database was properly loaded.
*/
public function testDatabaseLoaded()
{
$extensions = \Drupal::service('config.storage')->read('core.extension');
$this->assertFalse(isset($extensions['theme']['stable']), 'Stable is not installed before updating.');
$hook_updates = ['user' => '8000', 'node' => '8003', 'system' => '8013'];
foreach ($hook_updates as $module => $schema) {
$this->assertEqual(drupal_get_installed_schema_version($module), $schema, new FormattableMarkup('Module @module schema is @schema', ['@module' => $module, '@schema' => $schema]));
}
// Test post_update key value stores contains a list of the update functions
// that have run.
$existing_updates = array_count_values(\Drupal::keyValue('post_update')->get('existing_updates'));
$expected_updates = ['system_post_update_recalculate_configuration_entity_dependencies', 'field_post_update_save_custom_storage_property', 'field_post_update_entity_reference_handler_setting', 'block_post_update_disable_blocks_with_missing_contexts', 'views_post_update_update_cacheability_metadata'];
foreach ($expected_updates as $expected_update) {
$this->assertEqual($existing_updates[$expected_update], 1, new FormattableMarkup("@expected_update exists in 'existing_updates' key and only appears once.", ['@expected_update' => $expected_update]));
}
$this->runUpdates();
$this->assertEqual(\Drupal::config('system.site')->get('name'), 'Site-Install');
$this->drupalGet('<front>');
$this->assertText('Site-Install');
$extensions = \Drupal::service('config.storage')->read('core.extension');
$this->assertTrue(isset($extensions['theme']['stable']), 'Stable is installed after updating.');
$blocks = \Drupal::entityManager()->getStorage('block')->loadByProperties(['theme' => 'stable']);
$this->assertTrue(empty($blocks), 'No blocks have been placed for Stable.');
}