Repository navigation
Expand file tree
/
Copy pathwordpress.php
More file actions
136 lines (112 loc) · 5.18 KB
/
Copy pathwordpress.php
File metadata and controls
136 lines (112 loc) · 5.18 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
namespace Deployer;
set('cache_dir', get('cache_dir', 'web/app/cache'));
set('bin/wp', get('bin/wp', function () {
return run('which wp');
}));
desc('Clear timber cache');
task('cache:clear:wp:timber', function () {
run('cd {{deploy_path}}/current && rm -rf {{cache_dir}}/timber');
});
desc('Clear WP Super Cache cache');
task('cache:clear:wp:wpsc', function () {
run('cd {{deploy_path}}/current && rm -rf {{cache_dir}}/{blogs,meta,supercache,wp-cache-*}');
});
desc('Clear WP Object Cache');
task('cache:clear:wp:objectcache', function () {
run('cd {{deploy_path}}/current/web && {{bin/wp}} cache flush');
});
desc('Clear Acorn Caches');
task('cache:clear:wp:acorn', function () {
run('cd {{deploy_path}}/current/web && {{bin/wp}} acorn optimize:clear');
});
desc('Generate Acorn Caches');
task('cache:wp:acorn', function () {
run('cd {{deploy_path}}/current/web && {{bin/wp}} acorn optimize');
});
desc('Clear Kinsta Caches');
task('cache:clear:kinsta', function () {
// Kinsta's page and Edge cache, never the CDN: the request and answer
// kinsta-mu-plugins' `wp kinsta cache purge --site` uses. Any other answer
// means nothing was purged, so say so instead of passing silently.
$response = rtrim(run("curl -sSk -w '\\n%{http_code}' https://localhost/kinsta-clear-cache-all"));
$split = (int) strrpos($response, "\n");
$body = trim(substr($response, 0, $split));
$code = trim(substr($response, $split));
if ($code !== '200' || $body !== 'Cache has been cleared.') {
warning("Kinsta page cache was not cleared: HTTP $code $body");
}
});
/**
* WP-CLI commands that bring the database up to the deployed code, run by
* `wp:update` in the order given. A string runs as is; an entry with `network`
* appends those arguments on a multisite network, so every site is upgraded:
*
* add('wp_update_commands', ['wc update']);
*
* Each command must be a no-op when there is nothing to do, since this runs on
* every deploy.
*/
set('wp_update_commands', [
['cmd' => 'core update-db', 'network' => '--network'],
]);
desc('Run the database updates the deployed code needs');
task('wp:update', function () {
$network = test('cd {{deploy_path}}/current/web && {{bin/wp}} core is-installed --network');
info('wp:update: '.($network ? 'multisite network' : 'single site'));
foreach (get('wp_update_commands') as $command) {
if (is_string($command)) {
$command = ['cmd' => $command];
}
$args = $command['cmd'];
if ($network && ! empty($command['network'])) {
$args .= ' '.$command['network'];
}
info("wp $args");
// Not best-effort: a pending database upgrade locks editors out of
// wp-admin, so fail the deploy where it can be seen. On a network
// `--network` boots WordPress once per site, which can outlast the
// default 300 s.
writeln(run("cd {{deploy_path}}/current/web && {{bin/wp}} $args", timeout: 1800));
}
});
task('scaffold:env', function () {
if (test('[ -f {{deploy_path}}/shared/.env ]')) {
$confirm = askConfirmation('Environment file already exists, are you usre you want to rewrite it?');
if (! $confirm) {
return;
}
}
$url = get('url', 'https://');
$dbHost = ask('DB_HOST', 'localhost');
$dbName = ask('DB_NAME', get('scaffold_machine_name', ''));
$dbUser = ask('DB_USER', get('scaffold_machine_name', ''));
$dbPassword = askHiddenResponse('DB_PASSWORD');
$wpEnv = ask('WP_ENV', currentHost()->getAlias());
$wpHome = ask('WP_HOME', $url);
$domainCurrentSite = ask('DOMAIN_CURRENT_SITE', parse_url($url, PHP_URL_HOST));
run('mkdir -p {{deploy_path}}/shared');
upload(get('scaffold_env_file'), '{{deploy_path}}/shared/.env');
run('sed -i "/^DB_HOST=/c\\DB_HOST='.$dbHost.'" {{deploy_path}}/shared/.env');
run('sed -i "/^DB_NAME=/c\\DB_NAME='.$dbName.'" {{deploy_path}}/shared/.env');
run('sed -i "/^DB_USER=/c\\DB_USER='.$dbUser.'" {{deploy_path}}/shared/.env');
run('sed -i "/^DB_PASSWORD=/c\\DB_PASSWORD=\''.$dbPassword.'\'" {{deploy_path}}/shared/.env');
run('sed -i "/^WP_ENV=/c\\WP_ENV='.$wpEnv.'" {{deploy_path}}/shared/.env');
run('sed -i "/^WP_HOME=/c\\WP_HOME='.$wpHome.'" {{deploy_path}}/shared/.env');
run('sed -i "/^DOMAIN_CURRENT_SITE=/c\\DOMAIN_CURRENT_SITE='.$domainCurrentSite.'" {{deploy_path}}/shared/.env');
foreach (['AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT'] as $key) {
run('sed -i "/^'.$key.'=/c\\'.$key.'=\''.hash('sha256', uniqid(rand(), true)).'\'" {{deploy_path}}/shared/.env');
}
// @todo scaffold database.
});
desc('Clean directories which are emptied by dropin installer');
task('deploy:cleanup:dropin', function () {
run('cd {{release_path}} && rm -rf vendor/koodimonni-language');
run('cd {{release_path}} && rm -rf vendor/koodimonni-plugin-language');
run('cd {{release_path}} && rm -rf vendor/koodimonni-theme-language');
});
/**
* We need to prune the empty directories left by dropin installer or else
* they wont be downloaded again.
*/
before('deploy:vendors', 'deploy:cleanup:dropin');