PHP Class VersionPress\Cli\VPCommand

Inheritance: extends WP_CLI_Comman\WP_CLI_Command
Show file Open project: versionpress/versionpress

Public Methods

Method Description
activate ( $args, $assoc_args ) Starts tracking the site
applyChanges ( $args = [], $assoc_args = [] ) Applies changes from the disk to the database
checkRequirements ( $args, $assoc_args ) Checks if VersionPress requirements are met.
cloneSite ( $args = [], $assoc_args = [] ) Clones site to a new folder and database.
config ( $args, $assoc_args ) Configures VersionPress. See options for details.
pull ( $args = [], $assoc_args = [] ) Pulls changes from another clone
push ( $args = [], $assoc_args = [] ) Pushes changes to another clone
restoreSite ( $args, $assoc_args ) Restores a WP site from Git repo / working directory.
rollback ( $args = [], $assoc_args = [] ) Rollbacks site to the same state as it was in the specified commit.
undo ( $args = [], $assoc_args = [] ) Reverts commits
update ( $args = [], $assoc_args = [] ) Updates VersionPress

Private Methods

Method Description
checkVpRequirements ( $assoc_args, $requirementsScope )
dropTables ( )
finishPull ( )
flushRewriteRules ( )
getInitialCommitHash ( GitRepository $repository ) : string
getRemoteUrl ( string $name ) : string | null Returns URL for a remote name, or null if the remote isn't configured.
prepareDatabase ( array $assoc_args ) Prepares an empty database - creates it if it doesn't exist or drops its WP tables if it does.
requireWpConfig ( string $wpConfigPath, string $commonConfigName ) Tries to require Wordpress config files. Throws WP-CLI error when files not found.
runVPInternalCommand ( $subcommand, $args = [], $cwd = null )
setConfigUrl ( $urlConstant, $pathConstant, $defaultPath, $baseUrl )
someWpTablesExist ( string $dbUser, string $dbPassword, string $dbName, string $dbHost, string $dbPrefix ) : boolean Checks if some tables with the given prefix exist in the database
suggestCloneUrl ( string $originUrl, string $originDirName, string $cloneDirName ) : string Suggests clone URL by replacing directory names. If no suggestion can be made, returns null.
switchMaintenance ( string $onOrOff, string | null $remoteName = null ) Switches the maintenance mode on or off for a site specified by a remote.
updateConfig ( $clonePath, $environment, $dbUser, $dbPassword, $dbName, $dbHost, $dbPrefix, $dbCharset, $dbCollate )

Method Details

activate() public method

[--yes] : Answer yes to the confirmation message.
public activate ( $args, $assoc_args )

applyChanges() public method

## EXAMPLES This command is mainly used in a merge conflict situation, after a 'pull'. When the conflict is manually resolved and committed, run this command to make sure that the database in sync with the Git repository / filesystem: wp vp apply-changes Note that this command temporarily turns on the maintenance mode.
public applyChanges ( $args = [], $assoc_args = [] )

checkRequirements() public method

Checks if VersionPress requirements are met.
public checkRequirements ( $args, $assoc_args )

cloneSite() public method

## OPTIONS --name= : Name of the clone. Used as a directory name, part of the DB prefix and an argument to the pull & push commands later. [--siteurl=] : URL of the clone. By default, the original URL is searched for and replaced with the clone name. [--dbname=] : Database name for the clone. [--dbuser=] : Database user for the clone. [--dbpass=] : Database user password for the clone. [--dbhost=] : Database host for the clone. [--dbprefix=] : Database table prefix for the clone. [--dbcharset=] : Database charset for the clone. [--dbcollate=] : Database collation for the clone. [--force] : Forces cloning even if the target directory or DB tables exists. Basically provides --yes to all warnings / confirmations. [--yes] : Another way to force the clone ## EXAMPLES The main site lives in a directory 'wpsite', uses the 'wp_' database table prefix and is accessible via 'http://localhost/wpsite'. The command wp vp clone --name=myclone does the following: - Creates new directory 'myclone' next to the current one - Clones the files there - Creates new database tables prefixed with 'wp_myclone_' - Populates database tables with data - Makes the site accessible as 'http://localhost/myclone'
public cloneSite ( $args = [], $assoc_args = [] )

config() public method

## OPTIONS : The name of the constant to set. VP_GIT_BINARY: Absolute path to the git binary. VP_PROJECT_ROOT: Absolute path to the root of your project (typically where is the .git directory) VP_VPDB_DIR: Absolute path to directory where VersionPress saves versioned database data. [] : The new value. If missing, just prints out current value.
public config ( $args, $assoc_args )

pull() public method

## OPTIONS [--from=] : Where to pull from. Can be a clone name (specified previously during the 'clone' command), a path or a URL. Defaults to 'origin' which is automatically set in every clone by the 'clone' command. [--continue] : Finishes the pull after solving merge conflicts. ## EXAMPLES Let's have a site 'wpsite' and a clone 'myclone' created from it. To pull the changes from the clone back into the main site, use: wp vp pull --from=myclone When in the clone, the pull can be run without any parameter: wp vp pull This will pull the changes from 'origin' which was set to the parent site during the 'clone' command.
public pull ( $args = [], $assoc_args = [] )

push() public method

## OPTIONS [--to=] : Name of the clone or a path to it. Defaults to 'origin' which, in a clone, points to its original site. ## EXAMPLES Push is a similar command to 'pull' but does not create a merge. To push from clone to the original site, run: wp vp push To push from the original site to the clone, use the '--to' parameter: wp vp push --to=clonename
public push ( $args = [], $assoc_args = [] )

restoreSite() public method

## OPTIONS --siteurl= : The address of the restored site. [--yes] : Answer yes to the confirmation message. ## DESCRIPTION The command will then do the following: * Drops all tables tracked by VersionPress. * Recreates and fill them with data from repository. If you just cloned the site from another repository, run wp core config first.
public restoreSite ( $args, $assoc_args )

rollback() public method

## OPTIONS : Hash of commit. ## EXAMPLES wp vp rollback a34bc28
public rollback ( $args = [], $assoc_args = [] )

undo() public method

## OPTIONS : Hashes of commit that will be reverted (separated by comma). ## EXAMPLES wp vp undo a34bc28,d12ef22
public undo ( $args = [], $assoc_args = [] )

update() public method

## OPTIONS : Path to ZIP file containing VersionPress. ## EXAMPLES wp vp update ../versionpress-4.0.zip
public update ( $args = [], $assoc_args = [] )