Skip to content

Add shuffle-salts command#62

Merged
schlessera merged 12 commits intowp-cli:masterfrom
CodeProKid:feature/50
Jul 26, 2018
Merged

Add shuffle-salts command#62
schlessera merged 12 commits intowp-cli:masterfrom
CodeProKid:feature/50

Conversation

@CodeProKid
Copy link
Contributor

First pass at the shuffle-salts command here. This uses code fairly similar to what core uses here -> https://github.com/WordPress/wordpress-develop/blob/master/src/wp-admin/setup-config.php#L317-L346

I'm also relying on the internal unique_key method here which was added in #25

Working on adding tests now, just wanted to get the first pass up 👍

@CodeProKid
Copy link
Contributor Author

Woops, forgot that the issue for this was in a separate repo -> wp-cli/ideas#50

@CodeProKid
Copy link
Contributor Author

Tests are up here now. Not sure if this needs more tests or not? Seems to cover the bases pretty good though. Will wait to make sure the build passes 👍


}

$constant_list = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this multi-line, to make it more legible:

$constant_list = array(
    'AUTH_KEY',
    'SECURE_AUTH_KEY',
    'LOGGED_IN_KEY',
    'NONCE_KEY',
    'AUTH_SALT',
    'SECURE_AUTH_SALT',
    'LOGGED_IN_SALT',
    'NONCE_SALT'
);

public function shuffle_salts( $args, $assoc_args ) {

try {
for ( $i = 0; $i < 8; $i++ ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please directly couple this to the number of known constants:

foreach ( $constant_list as $key ) {
   $secret_keys[ $key ] = self::unique_key();
}

You'll have to pull the declaration of $constant_list higher up for this.

try {
$config_transformer = new WPConfigTransformer( $path );
foreach ( $constant_list as $constant ) {
$config_transformer->update( 'constant', $constant, $secret_keys[ $key ] );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $secret_keys[ $constant ] here instead. You can get rid of the numeric $key completely.

@CodeProKid
Copy link
Contributor Author

@schlessera I made the changes you requested here. Looks like tests are still failing, but it seems to be due to timeouts on travis.

@schlessera
Copy link
Member

@CodeProKid Seems like there is still a problem with this code with PHP 5.6: https://travis-ci.org/wp-cli/config-command/jobs/406183041#L648-L649
The problem might or might not be caused by the upstream wp-config-transformer library.

@CodeProKid
Copy link
Contributor Author

@schlessera I fixed the issue causing the tests to break, and added some documentation about the command in the readme.

foreach ( $constant_list as $key ) {
$secret_keys[ $key ] = trim( self::unique_key() );
}
throw new Exception( 'TEST' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's some debugging left-overs here.

~~~
wp config shuffle-salts
~~~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you manually changed the README.md file. This should be generated out of the source code docblock instead. The automatic regeneration is not yet included here so yu need to do this manually for now.

You can use the following to regenerate the README.md file:

  • Make sure the required package is installed (this one is not bundled)
    wp package install wp-cli/scaffold-package-command
    
  • Force a regeneration the README.md file
    wp scaffold package-readme . --force
    

@CodeProKid
Copy link
Contributor Author

CodeProKid commented Jul 26, 2018

@schlessera Good catch on the debug code 🤦‍♂️ also, didn't realize that about the readme, pretty cool. I ran the command to regenerate it in the latest commit.

@schlessera
Copy link
Member

@CodeProKid I forgot to mention that there's an extra step needed for the README.md regeneration, as you've added a new command (as you can see in the commit, it did not actually add the documentation).

You need to first add that new command to the 'extra.commands' section of the composer.json file: https://github.com/wp-cli/config-command/blob/v1.2.0/composer.json#L42-L52

After you've added the new command there, regenerate the README.md again and it will properly pick up the docblock of that new command.

@CodeProKid
Copy link
Contributor Author

@schlessera ahhh, I see. Never knew about the auto doc generation for commands. Very cool! Should be good now 👍

@schlessera schlessera added this to the 1.2.1 milestone Jul 26, 2018
@schlessera schlessera merged commit aae296c into wp-cli:master Jul 26, 2018
@schlessera schlessera changed the title Feature/50 adding shuffle-salts command Add shuffle-salts command Jul 26, 2018
@schlessera
Copy link
Member

Thanks for the pull request, @CodeProKid !

schlessera added a commit that referenced this pull request Jan 6, 2022
Feature/50 adding shuffle-salts command
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