Skip to content

Add wp user spam command#74

Merged
schlessera merged 13 commits intowp-cli:masterfrom
BhargavBhandari90:feature/GH-50
Sep 8, 2017
Merged

Add wp user spam command#74
schlessera merged 13 commits intowp-cli:masterfrom
BhargavBhandari90:feature/GH-50

Conversation

@BhargavBhandari90
Copy link
Contributor

@BhargavBhandari90 BhargavBhandari90 commented Sep 2, 2017

Command:

  • wp user spam 123

For : #50

Command:
- wp user spam 123
Validations:
- If user is super-user, then don't set as spam
- Show warning if user is already reported as spam
@BhargavBhandari90 BhargavBhandari90 changed the title WIP: Add command for user marked as a spam Add command for user marked as a spam Sep 2, 2017
@miya0001
Copy link
Member

miya0001 commented Sep 3, 2017

I think we shouldn't try to use SQL as much as possible.
Can you use update_user_status() or so?

@BhargavBhandari90
Copy link
Contributor Author

yes, @miya0001 I just saw that function. Applying that only.

@miya0001
Copy link
Member

miya0001 commented Sep 3, 2017

Thanks @BhargavBhandari90 😄

@BhargavBhandari90
Copy link
Contributor Author

Behat test for user.feature shows following error for spam command

PHP Fatal error: Call to undefined function get_network() in src/User_Command.php on line 1064
Fatal error: Call to undefined function get_network() in src/User_Command.php on line 1064
cwd: /tmp/wp-cli-test-run-user-test.feature.3-59abbe9ab397d9.99056625/
exit status: 255

However, I am not getting this error while running command into the terminal.

So I am confused, is my code has something wrong or what?

@miya0001
Copy link
Member

miya0001 commented Sep 3, 2017

Ah, I guess we should do like following.
https://github.com/wp-cli/entity-command/blob/master/features/site.feature#L4

@BhargavBhandari90
Copy link
Contributor Author

BhargavBhandari90 commented Sep 3, 2017

@miya0001 Yes, see I just did that. That was real time 😛 Thank you for giving your time.

@miya0001
Copy link
Member

miya0001 commented Sep 3, 2017

Hi,

If wp user spam is passed multiple arguments and there is an error from one of them, then status code should be 1.
But I guess your implementation will return 0.

We need consistency between same commands, so following is a good example to handle multiple arguments.

@BhargavBhandari90
Copy link
Contributor Author

ok. Checking this.

@miya0001 miya0001 added command:user-spam Related to 'user spam' command command:user Related to 'user' command labels Sep 3, 2017
@miya0001 miya0001 added this to the 1.1.0 milestone Sep 3, 2017
@BhargavBhandari90
Copy link
Contributor Author

One test is failing. because I used a function which was not available in that WP version.
How to tackle that situation?

Here is the error https://travis-ci.org/wp-cli/entity-command/jobs/271378052

@miya0001
Copy link
Member

miya0001 commented Sep 3, 2017

Do you want to use get_network() to mark spam the user's site too?
I guess there is a good example. :)
https://github.com/wp-cli/entity-command/blob/master/src/Site_Command.php#L749-L766

@BhargavBhandari90
Copy link
Contributor Author

If wp user spam is passed multiple arguments and there is an error from one of them, then status code should be 1.
But I guess your implementation will return 0.

@miya0001 As you said we need wp user unspam for this. So I will implement this.

- made a common function for updating user data
@BhargavBhandari90
Copy link
Contributor Author

BhargavBhandari90 commented Sep 6, 2017

Hi @miya0001

If wp user spam is passed multiple arguments and there is an error from one of them, then status code should be 1.

I have implemented this thing. But I don't know how to get return code so that I can add it into feature file.

Currently, I am not adding that line into users.feature.

@miya0001
Copy link
Member

miya0001 commented Sep 6, 2017

@BhargavBhandari90

Please write test like following.

When I try `wp user spam {BBEE_ID} 9999`
Then STERR should contain:
  """
  Warning: User 9999 doesn't exist.
  """
And the return code should be 1

@miya0001
Copy link
Member

miya0001 commented Sep 6, 2017

Ah, sorry, it should be like following.

When I try `wp user spam {BBEE_ID} 9999`
Then STOUT should contain:
  """
  User {BBEE_ID} marked as spam.
  """
And STOUT should contain:
  """
  Warning: User 9999 doesn't exist.
  """
And the return code should be 1

@BhargavBhandari90
Copy link
Contributor Author

@miya0001 This should be fine now.


// If site is not multisite, then stop execution.
if ( ! is_multisite() ) {
WP_CLI::error( 'Sorry! this command is for multisite only.' );
Copy link
Member

Choose a reason for hiding this comment

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

This should mimic the other commands:

WP_CLI::error( 'This is not a multisite install.' );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. @schlessera

@schlessera
Copy link
Member

schlessera commented Sep 8, 2017

The grammar is off for the batch results, but this needs to be fixed in WP_CLI\Utils. I've opened an issue for this here: wp-cli/wp-cli#4338

@schlessera schlessera changed the title Add command for user marked as a spam Add wp user spam command Sep 8, 2017
@schlessera schlessera merged commit 49df45f into wp-cli:master Sep 8, 2017
@schlessera
Copy link
Member

Thanks, @BhargavBhandari90 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:user Related to 'user' command command:user-spam Related to 'user spam' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants