-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathwp-cli-sync.php
59 lines (49 loc) · 1.57 KB
/
wp-cli-sync.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
/*
Plugin Name: WP-CLI Sync
Description: A WP-CLI command for syncing a live site to a development environment
Version: 1.3.2
Author: Jon Beaumont-Pike
Author URI: https://jonbp.co.uk/
License: MIT License
*/
// Set Default Vars
$env_variables = array(
'LIVE_SSH_USERNAME' => '',
'LIVE_SSH_HOSTNAME' => '',
'REMOTE_PROJECT_LOCATION' => '',
'DEV_ACTIVATED_PLUGINS' => '',
'DEV_DEACTIVATED_PLUGINS' => '',
'DEV_POST_SYNC_QUERIES' => '',
'DEV_SYNC_DIR_EXCLUDES' => '',
'DEV_TASK_DEBUG' => '',
'UPLOAD_DIR' => 'web/app/uploads'
);
foreach($env_variables as $env_variable => $env_variable_default) {
$_ENV[$env_variable] = getenv($env_variable) ?: $env_variable_default;
}
// Define Sync Command
if ( defined( 'WP_CLI' ) && WP_CLI ) {
$sync = function() {
// Include base functions
require_once(__DIR__.'/core/functions.php');
require_once(__DIR__.'/core/variables.php');
// Include tasks
require_once(__DIR__.'/tasks/connection_check.php');
require_once(__DIR__.'/tasks/database_sync.php');
require_once(__DIR__.'/tasks/uploads_sync.php');
require_once(__DIR__.'/tasks/plugins_management.php');
// Deactivate Maintenance Mode
$command = ABSPATH . '/../../vendor/bin/wp maintenance-mode deactivate';
exec($command);
// Completion Message
if ($fail_count > 0) {
task_message('Finished with '.$fail_count. ' errors', 'Warning', 33);
} else {
task_message('All Tasks Finished', 'Success', 32);
}
// Final Line Break + Color Reset
lb_cr();
};
WP_CLI::add_command('sync', $sync);
}