Skip to content

Commit

Permalink
Make it possible to disable modules from being counted (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriksm authored Mar 21, 2023
1 parent 1a66f53 commit f9cffc4
Show file tree
Hide file tree
Showing 6 changed files with 449 additions and 11 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
name: Run tests
runs-on: 'ubuntu-20.04'
env:
SCHEMA_PATH: /tmp/test-schema.json
SCHEMA_PATH: /tmp
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -88,6 +88,10 @@ jobs:
./vendor/bin/drush si minimal --db-url=sqlite://sites/default/files/.ht.sqlite -y
mkdir -p drush/Commands/contrib
cp -r ../drush-site-schema drush/Commands/contrib/site-schema
./vendor/bin/drush site-schema --format=json > $SCHEMA_PATH
./vendor/bin/drush site-schema --format=json > $SCHEMA_PATH/test-schema.json
# Now do another one, but this time with some modules excluded
chmod 777 web/sites/default/settings.php
echo '$settings["drush_site_schema_disabled_modules"] = ["dblog"];' >> web/sites/default/settings.php
./vendor/bin/drush site-schema --format=json > $SCHEMA_PATH/test-schema.json-excluded
cd ../drush-site-schema
./vendor/bin/phpunit
27 changes: 26 additions & 1 deletion SiteSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Drush\Commands\site_schema;

use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Core\Site\Settings;
use Drupal\Core\Update\UpdateRegistry;
use Drush\Commands\DrushCommands;

Expand Down Expand Up @@ -34,10 +35,34 @@ public function schema($options = ['format' => 'table']) {
$method->invoke($registry);
$method = $reflected->getMethod('getAvailableUpdateFunctions');
$method->setAccessible(TRUE);
try {
$enabled_prop = $reflected->getProperty('enabledExtensions');
}
catch (\Throwable $e) {
// On Drupal 8 it's called this.
$enabled_prop = $reflected->getProperty('enabledModules');
}
$enabled_prop->setAccessible(TRUE);
$current = $enabled_prop->getValue($registry);
$disabled_modules = Settings::get('drush_site_schema_disabled_modules', []);
\Drupal::moduleHandler()->alter('drush_site_schema_disabled_modules', $disabled_modules);
$enabled_prop->setValue($registry, array_diff($current, $disabled_modules));
$post_update_functions = $method->invoke($registry);
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
try {
// This service was introduced in drupal 9.3.0.
/** @var \Drupal\Core\Update\UpdateHookRegistry $service */
$service = \Drupal::service('update.update_hook_registry');
$modules = $service->getAllInstalledVersions();
}
catch (\Throwable $e) {
// Maybe it's a pre-9.3.0 drupal.
$modules = drupal_get_installed_schema_version(NULL, FALSE, TRUE);
}
// Now build the table.
foreach ($modules as $module => $schema) {
if (in_array($module, $disabled_modules)) {
continue;
}
$rows[] = [
'type' => 'schema',
'module' => $module,
Expand Down
222 changes: 222 additions & 0 deletions tests/assets/test-schema.json-excluded
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
[
{
"type": "schema",
"module": "block",
"value": "8003"
},
{
"type": "schema",
"module": "dynamic_page_cache",
"value": "8000"
},
{
"type": "schema",
"module": "field",
"value": "8500"
},
{
"type": "schema",
"module": "file",
"value": "8700"
},
{
"type": "schema",
"module": "filter",
"value": "8000"
},
{
"type": "schema",
"module": "minimal",
"value": "8000"
},
{
"type": "schema",
"module": "node",
"value": "8700"
},
{
"type": "schema",
"module": "page_cache",
"value": "8000"
},
{
"type": "schema",
"module": "path_alias",
"value": "8000"
},
{
"type": "schema",
"module": "system",
"value": "8901"
},
{
"type": "schema",
"module": "text",
"value": "8000"
},
{
"type": "schema",
"module": "update",
"value": "8001"
},
{
"type": "schema",
"module": "user",
"value": "8100"
},
{
"type": "post_update",
"module": "",
"value": "block_post_update_disable_blocks_with_missing_contexts"
},
{
"type": "post_update",
"module": "",
"value": "block_post_update_disabled_region_update"
},
{
"type": "post_update",
"module": "",
"value": "block_post_update_fix_negate_in_conditions"
},
{
"type": "post_update",
"module": "",
"value": "field_post_update_email_widget_size_setting"
},
{
"type": "post_update",
"module": "",
"value": "field_post_update_entity_reference_handler_setting"
},
{
"type": "post_update",
"module": "",
"value": "field_post_update_remove_handler_submit_setting"
},
{
"type": "post_update",
"module": "",
"value": "field_post_update_save_custom_storage_property"
},
{
"type": "post_update",
"module": "",
"value": "node_post_update_configure_status_field_widget"
},
{
"type": "post_update",
"module": "",
"value": "node_post_update_glossary_view_published"
},
{
"type": "post_update",
"module": "",
"value": "node_post_update_node_revision_views_data"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_add_expand_all_items_key_in_system_menu_block"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_add_region_to_entity_displays"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_change_action_plugins"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_change_delete_action_plugins"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_classy_message_library"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_clear_menu_cache"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_entity_reference_autocomplete_match_limit"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_extra_fields"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_extra_fields_form_display"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_field_formatter_entity_schema"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_field_type_plugins"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_fix_jquery_extend"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_hashes_clear_cache"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_language_item_callback"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_layout_plugin_schema_change"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_recalculate_configuration_entity_dependencies"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_states_clear_cache"
},
{
"type": "post_update",
"module": "",
"value": "system_post_update_timestamp_plugins"
},
{
"type": "post_update",
"module": "",
"value": "text_post_update_add_required_summary_flag"
},
{
"type": "post_update",
"module": "",
"value": "text_post_update_add_required_summary_flag_form_display"
},
{
"type": "post_update",
"module": "",
"value": "user_post_update_enforce_order_of_permissions"
}
]
Loading

0 comments on commit f9cffc4

Please sign in to comment.