Skip to content

Commit 670e920

Browse files
committed
chore(main): release 0.1.0
1 parent 52d398e commit 670e920

14 files changed

+1340
-0
lines changed

.distignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.DS_Store
2+
.git
3+
.gitignore
4+
.gitlab-ci.yml
5+
.editorconfig
6+
.travis.yml
7+
behat.yml
8+
circle.yml
9+
phpcs.xml.dist
10+
phpunit.xml.dist
11+
bin/
12+
features/
13+
utils/
14+
*.zip
15+
*.tar.gz
16+
*.swp
17+
*.txt
18+
*.log
19+
.release-please-manifest.json
20+
release-please-config.json

.editorconfig

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
# From https://github.com/WordPress/wordpress-develop/blob/trunk/.editorconfig with a couple of additions.
8+
9+
root = true
10+
11+
[*]
12+
charset = utf-8
13+
end_of_line = lf
14+
insert_final_newline = true
15+
trim_trailing_whitespace = true
16+
indent_style = tab
17+
18+
[{*.yml,*.feature,.jshintrc,*.json}]
19+
indent_style = space
20+
indent_size = 2
21+
22+
[*.md]
23+
trim_trailing_whitespace = false
24+
25+
[{*.txt,wp-config-sample.php}]
26+
end_of_line = crlf

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
wp-cli.local.yml
2+
/node_modules
3+
/vendor
4+
*.zip
5+
*.tar.gz
6+
*.swp
7+
*.txt
8+
*.log
9+
composer.lock
10+
phpunit.xml
11+
phpcs.xml
12+
.phpcs.xml
13+
.phpunit.result.cache

README.md

+104
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
11
# wp-cli-move
2+
23
Sync your WordPress content (database and uploads) between stages using the power of WP-CLI aliases.
4+
5+
## Install
6+
7+
Using composer:
8+
9+
```sh
10+
composer require n5s/wp-cli-move --dev
11+
```
12+
13+
Using `wp package install`:
14+
15+
```sh
16+
wp package install n5s/wp-cli-move
17+
```
18+
19+
## Requirements
20+
21+
The requirements must be met on both stages.
22+
23+
- SSH access
24+
- WP-CLI
25+
- mysql/mysqldump
26+
- rsync
27+
- gzip (optional, can be disabled with the `--disable-compress` flag)
28+
29+
Before running commands, make sure you have WP-CLI aliases set up. This can be done either with the [`wp cli alias`](https://developer.wordpress.org/cli/commands/cli/alias/) command or by editing your `wp-cli.yml` file.
30+
31+
Once you're done, quickly check that remote WP-CLI commands work as expected:
32+
33+
```sh
34+
wp @your-alias option get home
35+
36+
# It should print your alias home URL
37+
https://example.org
38+
```
39+
40+
For more information about alias configuration, refer to the following WP-CLI documentation:
41+
42+
- https://make.wordpress.org/cli/handbook/guides/running-commands-remotely/#aliases
43+
- https://make.wordpress.org/cli/handbook/references/config/
44+
45+
## Usage
46+
47+
Depending on the sync direction, use either the `pull` or `push` commands.
48+
49+
```sh
50+
wp move pull/push [<alias>] [--db] [--uploads] [--disable-compress] [--dry-run]
51+
```
52+
53+
If you omit the `--db` or `--uploads` flags, both data types will be synced by default.
54+
55+
Note that the `<alias>` argument is optional. Configured aliases will be shown in a menu to choose from if left empty.
56+
57+
> [!CAUTION]
58+
> Just like any tool that manipulates your data, it's **always a good idea to make a backup before running commands**.
59+
>
60+
> Especially when syncing uploads, which uses the `rsync` command with the `--delete` flag under the hood and can wipe all your media files if used incorrectly.
61+
>
62+
> **Be sure to know what you're doing.**
63+
64+
### Options
65+
66+
Both `pull` and `push` commands use the same options.
67+
68+
- `[<alias>]`: The alias you want to sync with.
69+
- `--db`: Sync only the database.
70+
- `--uploads`: Sync only the uploads.
71+
- `--disable-compress`: Disable database dump compression.
72+
- `--dry-run`: Print the command sequence without making any changes.
73+
74+
> [!NOTE]
75+
> Each time you sync your database from one stage to another, `wp-cli-move` will locally backup the database of the synced stage (a local database dump when pulling, a remote database dump when pushing).
76+
77+
### Examples
78+
79+
### Pulling content
80+
81+
Pull your production content to your local environment:
82+
83+
```sh
84+
wp move pull @production
85+
```
86+
87+
> [!TIP]
88+
> Using `@` as declared in `wp-cli.yml` is optional. For example, `production` and `@production` will resolve the same alias.
89+
90+
### Pushing content
91+
92+
Push your local content to your staging environment:
93+
94+
```sh
95+
wp move push staging
96+
```
97+
98+
## Credits
99+
100+
This WP-CLI package aims to replace the (still working but unmaintained) awesome [Wordmove](https://github.com/welaika/wordmove) Ruby gem 💎. It has been a time and life saver for many years. I'll be forever grateful to [@alessandro-fazzi](https://github.com/alessandro-fazzi) for creating it! 🙌
101+
102+
Although [Wordmove](https://github.com/welaika/wordmove) is a great and handy tool for your daily WordPress work, some reasons led me to come with a simpler, more WordPress flavoured alternative:
103+
104+
- It has become harder to easily install the gem over the years as the required Ruby version has been deprecated, especially for non-Ruby developers (at least for me).
105+
- Most importantly, [an idea I submitted years ago](https://github.com/welaika/wordmove/issues/601#issue-612726521) has never been implemented. This feature would remove a lot of tedious configuration setup (database credentials, etc.).
106+
- It's written in Ruby 😄

command.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use n5s\WpCliMove\Model\Alias;
4+
5+
if ( ! class_exists( 'WP_CLI' ) ) {
6+
return;
7+
}
8+
9+
$wp_cli_move_autoloader = __DIR__ . '/vendor/autoload.php';
10+
11+
if ( file_exists( $wp_cli_move_autoloader ) ) {
12+
require_once $wp_cli_move_autoloader;
13+
}
14+
15+
WP_CLI::add_command(
16+
'move',
17+
n5s\WpCliMove\MoveCommand::class,
18+
[
19+
'before_invoke' => function (): void {
20+
$runner = WP_CLI::get_runner();
21+
22+
if ( in_array( Alias::LOCAL_ALIAS, array_keys( $runner->aliases ), true ) ) {
23+
WP_CLI::error(
24+
sprintf( '"%s" is a reserved alias name by the `move` command, Please rename your alias.', Alias::LOCAL_ALIAS )
25+
);
26+
}
27+
28+
if ( null !== $runner->alias ) {
29+
WP_CLI::error( 'You cannot use the `move` command with an alias.' );
30+
}
31+
},
32+
]
33+
);

composer.json

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "n5s/wp-cli-move",
3+
"description": "Sync your WordPress content (database and uploads) between stages using the power of WP-CLI aliases.",
4+
"license": "MIT",
5+
"type": "wp-cli-package",
6+
"authors": [
7+
{
8+
"name": "Nicolas Lemoine",
9+
"email": "[email protected]",
10+
"homepage": "https://n5s.dev/"
11+
}
12+
],
13+
"require": {
14+
"php": "^8.1"
15+
},
16+
"require-dev": {
17+
"ergebnis/composer-normalize": "^2.45",
18+
"php-stubs/wordpress-stubs": "^6.7",
19+
"phpstan/extension-installer": "^1.4",
20+
"phpstan/phpstan": "^2.1",
21+
"rector/rector": "^2.0",
22+
"slevomat/coding-standard": "^8.14",
23+
"szepeviktor/phpstan-wordpress": "^2.0",
24+
"wp-cli/config-command": "^2.3",
25+
"wp-cli/core-command": "^2.1",
26+
"wp-cli/db-command": "^2.0",
27+
"wp-cli/eval-command": "^2.2",
28+
"wp-cli/search-replace-command": "^2.1",
29+
"wp-cli/wp-cli-tests": "^4.2"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"n5s\\WpCliMove\\": "src/"
34+
},
35+
"files": [
36+
"command.php"
37+
]
38+
},
39+
"autoload-dev": {
40+
"psr-4": {
41+
"n5s\\WpCliMove\\Tests\\": "tests/"
42+
}
43+
},
44+
"config": {
45+
"allow-plugins": {
46+
"dealerdirect/phpcodesniffer-composer-installer": true,
47+
"ergebnis/composer-normalize": true,
48+
"phpstan/extension-installer": true
49+
}
50+
},
51+
"scripts": {
52+
"behat": "run-behat-tests",
53+
"behat-rerun": "rerun-behat-tests",
54+
"lint": "run-linter-tests",
55+
"phpcbf": "run-phpcbf-cleanup",
56+
"phpcs": "run-phpcs-tests",
57+
"phpunit": "run-php-unit-tests",
58+
"prepare-tests": "install-package-tests",
59+
"test": [
60+
"@lint",
61+
"@phpcs",
62+
"@phpunit",
63+
"@behat"
64+
]
65+
},
66+
"licence": "MIT"
67+
}

phpcs.xml.dist

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="wp-cli-move">
3+
<description>Custom ruleset for wp-cli-move</description>
4+
5+
<!-- What to scan. -->
6+
<file>.</file>
7+
8+
<!-- Show progress. -->
9+
<arg value="p"/>
10+
11+
<!-- Strip the filepaths down to the relevant bit. -->
12+
<arg name="basepath" value="./"/>
13+
14+
<!-- Check up to 8 files simultaneously. -->
15+
<arg name="parallel" value="8"/>
16+
17+
<!-- For help understanding the `testVersion` configuration setting:
18+
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
19+
<config name="testVersion" value="8.1-"/>
20+
21+
<!-- Rules: Include the base ruleset for WP-CLI projects. -->
22+
<rule ref="WP_CLI_CS"/>
23+
24+
<!-- Verify that everything in the global namespace is either namespaced or prefixed.
25+
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
26+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
27+
<properties>
28+
<property name="prefixes" type="array">
29+
<element value="n5s\WpCliMove"/><!-- Namespaces. -->
30+
<element value="wp_cli_move"/><!-- Global variables and such. -->
31+
</property>
32+
</properties>
33+
</rule>
34+
35+
<!-- Whitelist property name for a a JSON-decoded object. -->
36+
<rule ref="WordPress.NamingConventions.ValidVariableName">
37+
<properties>
38+
<property name="allowed_custom_properties" type="array">
39+
<element value="sourcesContent"/>
40+
<element value="functionsScannerClass"/>
41+
</property>
42+
</properties>
43+
</rule>
44+
45+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
46+
47+
</ruleset>

phpstan.neon.dist

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src/
5+
scanFiles:
6+
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
7+
scanDirectories:
8+
- %rootDir%/../../wp-cli/wp-cli
9+
ignoreErrors:
10+
- '#Function WP_CLI\\Utils\\esc_cmd invoked with [0-9]+ parameters, 1 required.#'

rector.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths(
9+
[
10+
__DIR__ . '/src',
11+
]
12+
)
13+
// uncomment to reach your current PHP version
14+
->withPhpSets( php81: true )
15+
->withTypeCoverageLevel( 0 )
16+
->withDeadCodeLevel( 0 )
17+
->withCodeQualityLevel( 0 );
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace n5s\WpCliMove\Exception;
4+
5+
use n5s\WpCliMove\Model\ProcessResult;
6+
use RuntimeException;
7+
8+
class ProcessFailedException extends RuntimeException {
9+
10+
public function __construct(
11+
private readonly ProcessResult $result
12+
) {
13+
parent::__construct(
14+
sprintf(
15+
'The command "%s" failed.' . "\n\nExit Code: %d\n\n(%s)",
16+
$result->command,
17+
$result->exit_code,
18+
$result->stderr
19+
),
20+
$result->exit_code
21+
);
22+
}
23+
24+
public function getProcessResult(): ProcessResult {
25+
return $this->result;
26+
}
27+
}

0 commit comments

Comments
 (0)