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

Add scheduled user-role backup and management CLI #1982

Merged
merged 16 commits into from
Feb 17, 2021

Conversation

trepmal
Copy link
Contributor

@trepmal trepmal commented Feb 11, 2021

Description

Adds 1) a cron job to regularly backup user roles to a secondary option and 2) a CLI to manage listing/viewing/restoring those backups to the primary.

Why? In some cases of option corruption, user roles are lost and restoration is complicated and/or slow. This intends to make it quick and easy.

Note: this deals with the wp_user_roles option, not the assignments to users.

Changelog Description

Added User Role Backups

This change adds an automated daily backup of the user roles option that can be used to recover roles if they are corrupted. It also adds some CLI commands to aid in managing these backups.

Checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change works and has been tested on a Go sandbox.
  • This change has relevant unit tests (if applicable).
  • n/a This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Steps to Test

Begin by backing up current roles, then alter roles and backup again:

wp cron event run 'Automattic\VIP-backup_roles'
wp role delete editor
wp role delete author
wp role delete contributor
wp cron event run 'Automattic\VIP-backup_roles'

A couple options will now be listed in wp vip role-backup list

  1. optionally view a backup: wp vip role-backup view [<time_key>]
  2. and restore: wp vip role-backup restore [<time_key>]
  3. and confirm: wp role list

@trepmal trepmal marked this pull request as ready for review February 12, 2021 04:21
@trepmal trepmal requested a review from a team as a code owner February 12, 2021 04:21
@WPprodigy
Copy link
Contributor

Tested pretty extensively, all went well.

@@ -10,9 +10,13 @@

use Automattic\VIP\Utils\Alerts;

define( 'USER_ROLE_BACKUP_LENGTH', 3 );
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we prefix this with VIP_? And also, just curious if there would be any harm in upping this to say 5 - since we aren't autoloading it shouldn't matter, and will better help protect against maybe a weekend problem that went unnoticed for 3 days?

Copy link
Contributor

Choose a reason for hiding this comment

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

@WPprodigy this file is namespaced so that'll also cover the constant.

This reverts commit 3d3250b.

I realized this only affects staging, where there is much less impact, so splitting it up here is an over optimization
Copy link
Contributor

@nickdaugherty nickdaugherty left a comment

Choose a reason for hiding this comment

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

Tested it all out and it works great!

@nickdaugherty nickdaugherty merged commit 02729f0 into master Feb 17, 2021
@nickdaugherty nickdaugherty deleted the add/user-role-backup branch February 17, 2021 23:26
@nickdaugherty
Copy link
Contributor

r1391-stacks

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

Successfully merging this pull request may close these issues.

4 participants