Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed subcommand registration, namespace, and package files. #5

Merged
merged 6 commits into from
Oct 1, 2021

Conversation

sun
Copy link
Member

@sun sun commented Sep 29, 2021

Objectives

@sun
Copy link
Member Author

sun commented Sep 29, 2021

@sun
Copy link
Member Author

sun commented Sep 30, 2021

Updated for the committed vendor packages. Ensure to use composer dump --optimize to generate the autoloader in that case.

@sun
Copy link
Member Author

sun commented Sep 30, 2021

The subcommand works correctly when registering for the user command instead of the db command. The db command seems to be registered in a special way.

diff --git a/plugin.php b/plugin.php
index d2cc886..8ede851 100644
--- a/plugin.php
+++ b/plugin.php
@@ -26,4 +26,5 @@ include_once __DIR__ . '/vendor/autoload.php';
 
 add_action('cli_init', function () {
   WP_CLI::add_command('db export-clean', __NAMESPACE__ . '\CliCommand');
+  WP_CLI::add_command('user export-clean', __NAMESPACE__ . '\CliCommand');
 });

@sun
Copy link
Member Author

sun commented Sep 30, 2021

wp-cli/wp-cli#5274 might be a relevant fix.

The registration of db and user commands appears to be the same:

The commands themselves, too:

One difference is this directive on the DB class:

 * @when after_wp_config_load

It causes the db commands to skip most of the WordPress bootstrap:

Therefore, WP-CLI dispatches to the db command very early in the bootstrap (visible when running with --debug). At that point, only wp-config.php has been loaded, but no must-use plugins yet.

The solution is to restore the wp-cli.yml in the project root to load the additional command in the early WP-CLI bootstrap:

require:
  - wp-content/mu-plugins/wp-cli-db-export-clean.php

And also override the bootstrap level for the export-clean command (class method) to load the whole WordPress environment:

   * @when after_wp_load

Just committed those changes.

@bogdanarizancu bogdanarizancu merged commit 85315af into main Oct 1, 2021
@bogdanarizancu bogdanarizancu deleted the fix/subcommand-sun branch October 1, 2021 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants