capistrano-cul 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- metadata +1 -3
- data/lib/capistrano/tasks/wp-old.cap +0 -250
- data/lib/capistrano/tasks/wp/migrate-old.cap +0 -268
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5d82a7a06ebae390facf636f6505f66d9f8a93c
|
4
|
+
data.tar.gz: 1a8b7288032a93ce2f9b7b03d42620f084c120ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 655d5ab7c8db37374a8f21d79ecb6f9206e330ca3d6401134915f73c66760f3390f6100388273d14ca225b4c6da9ad38dc1ed151d2cc3cc958550b8580c52203
|
7
|
+
data.tar.gz: e6dbecd9ea3e373b5ec8a7ed7b0dc2d5f4379bd76fdc2095962e4480bd89792447b43a29a937b77dc6b66e74df9eb9f6a996ca99ba2d7bc5a007cac9f58fba20
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.19
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capistrano-cul
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carla Galarza
|
@@ -72,11 +72,9 @@ files:
|
|
72
72
|
- lib/capistrano/cul/tasks.rb
|
73
73
|
- lib/capistrano/cul/wp.rb
|
74
74
|
- lib/capistrano/tasks/cul.cap
|
75
|
-
- lib/capistrano/tasks/wp-old.cap
|
76
75
|
- lib/capistrano/tasks/wp.cap
|
77
76
|
- lib/capistrano/tasks/wp/deploy.cap
|
78
77
|
- lib/capistrano/tasks/wp/install.cap
|
79
|
-
- lib/capistrano/tasks/wp/migrate-old.cap
|
80
78
|
- lib/capistrano/tasks/wp/migrate.cap
|
81
79
|
- lib/capistrano/tasks/wp/setup.cap
|
82
80
|
- lib/capistrano/tasks/wp/update.cap
|
@@ -1,250 +0,0 @@
|
|
1
|
-
CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME = 'cul-allowed-upload-types'
|
2
|
-
CUL_ALLOWED_UPLOAD_TYPES_REPO_URL = "https://github.com/cul/#{CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME}"
|
3
|
-
|
4
|
-
# Set cul_allowed_upload_types_version here so it can be overridden by env config
|
5
|
-
set :cul_allowed_upload_types_version, 'v0.5.0'
|
6
|
-
|
7
|
-
namespace :cul do
|
8
|
-
namespace :wp do
|
9
|
-
|
10
|
-
before 'deploy:starting', 'cul:wp:require_deploy_params'
|
11
|
-
|
12
|
-
before 'deploy:starting', 'cul:wp:display_maintenance_mode_warning'
|
13
|
-
after 'deploy:starting', 'cul:wp:enable_maintenance_mode'
|
14
|
-
after 'deploy:starting', 'cul:wp:update_cul_allowed_upload_types_plugin'
|
15
|
-
after :deploy, 'cul:wp:symlink_custom_plugins_and_themes'
|
16
|
-
after :deploy, 'cul:wp:disable_maintenance_mode'
|
17
|
-
|
18
|
-
|
19
|
-
task :require_deploy_params do
|
20
|
-
require_cap_variables!([:branch, :wp_version, :wp_docroot, :wp_content_path])
|
21
|
-
end
|
22
|
-
|
23
|
-
desc "Displays a message to the deploying user about how to disable maintenance mode"
|
24
|
-
task :display_maintenance_mode_warning do
|
25
|
-
puts color_text("WARNING: Starting a deployment will set WordPress to maintenance mode. If you cancel deployment mid-way through, you'll need to manually disable maintenance mode by running: cap [env] cul:wp:disable_maintenance_mode")
|
26
|
-
end
|
27
|
-
|
28
|
-
desc "Enables maintenance mode for the WordPress site in the deploy environment"
|
29
|
-
task :enable_maintenance_mode do
|
30
|
-
path_to_maintenance_file = maintenance_file_path # save path to local variable because we can't call method inside `on roles(:web)`
|
31
|
-
on roles(:web) do
|
32
|
-
within fetch(:wp_docroot) do
|
33
|
-
# Set maintenance $upgrading value to current time.
|
34
|
-
# Note that WordPress will ignore maintenance mode file
|
35
|
-
# after 10 minutes have passed after the maintenance time
|
36
|
-
# we set in the file.
|
37
|
-
execute :echo, "'<?php $upgrading = #{Time.now.to_i};'", '>', path_to_maintenance_file
|
38
|
-
end
|
39
|
-
end
|
40
|
-
puts color_text("Maintenance mode enabled!")
|
41
|
-
end
|
42
|
-
|
43
|
-
desc "Disable maintenance mode for the WordPress site in the deploy environment"
|
44
|
-
task :disable_maintenance_mode do
|
45
|
-
path_to_maintenance_file = maintenance_file_path # save path to local variable because we can't call method inside `on roles(:web)`
|
46
|
-
on roles(:web) do
|
47
|
-
within fetch(:wp_docroot) do
|
48
|
-
if test("[ -f #{path_to_maintenance_file} ]")
|
49
|
-
execute :rm, path_to_maintenance_file
|
50
|
-
else
|
51
|
-
puts "No maintenance file found, so there's nothing to delete."
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
puts color_text("Maintenance mode disabled!")
|
56
|
-
end
|
57
|
-
|
58
|
-
desc "Creates symlinks for custom plugins and themes as part of a WordPress deployment. Generally run as an `after :deploy` hook."
|
59
|
-
task :symlink_custom_plugins_and_themes do
|
60
|
-
symlink_custom_plugins_and_themes
|
61
|
-
end
|
62
|
-
|
63
|
-
# Runs normal deploy task, downloads new copy of WP, sets up docroot, runs
|
64
|
-
# deploy command, sets up symlinks. Does not run WP install and does not
|
65
|
-
# create any wp users.
|
66
|
-
desc "Sets up a WordPress docroot and runs deployment; does not install wordpress and does not create any users"
|
67
|
-
task :setup do
|
68
|
-
puts "Deploying repo branch: #{fetch(:branch)}"
|
69
|
-
|
70
|
-
set :wp_version, ask('WordPress version to download:', 'latest')
|
71
|
-
# Printing out wp_version here because the `set` command above only runs
|
72
|
-
# the first time its associated symbol is referenced, and we want to
|
73
|
-
# capture version before running any other commands.
|
74
|
-
puts "Setting up wp_version: #{fetch(:wp_version)}"
|
75
|
-
|
76
|
-
require_cap_variables!([:branch, :wp_version, :wp_docroot, :wp_content_path])
|
77
|
-
|
78
|
-
on roles(:web) do
|
79
|
-
wp_docroot_wp_config_file_path = File.join(fetch(:wp_docroot), 'wp-config.php')
|
80
|
-
wp_docroot_robots_txt_file_path = File.join(fetch(:wp_docroot), 'robots.txt')
|
81
|
-
wp_docroot_wp_content_path = File.join(fetch(:wp_docroot), 'wp-content')
|
82
|
-
|
83
|
-
shared_wp_config_file_path = shared_path.join('wp-config.php')
|
84
|
-
shared_robots_txt_file_path = shared_path.join('robots.txt')
|
85
|
-
|
86
|
-
wp_content_path = fetch(:wp_content_path)
|
87
|
-
|
88
|
-
# Create nginx logs directory if it doesn't already exist
|
89
|
-
execute :mkdir, '-p', deploy_path.join('logs')
|
90
|
-
|
91
|
-
# Make full path to wp_docroot directory if not exist
|
92
|
-
execute :mkdir, '-p', fetch(:wp_docroot)
|
93
|
-
|
94
|
-
# Make full path to wp_content_path if not exist
|
95
|
-
execute :mkdir, '-p', wp_content_path
|
96
|
-
|
97
|
-
invoke 'deploy' # Deploy before doing setup
|
98
|
-
|
99
|
-
# If wp_docroot/wp-includes does not exist, do wordpress download
|
100
|
-
unless test("[ -d #{File.join(fetch(:wp_docroot), 'wp-includes')} ]")
|
101
|
-
# Download and unpack new WP instance to wp_docroot
|
102
|
-
execute :wp, 'core', ['download', "--version=#{fetch(:wp_version)}", "--path=#{fetch(:wp_docroot)}"]
|
103
|
-
end
|
104
|
-
|
105
|
-
# Check for wp-config.php file in shared. Create if it doesn't exist.
|
106
|
-
unless test("[ -f #{shared_wp_config_file_path} ]")
|
107
|
-
# If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
|
108
|
-
execute :cp, File.join(fetch(:wp_docroot), 'wp-config-sample.php'), shared_wp_config_file_path
|
109
|
-
end
|
110
|
-
|
111
|
-
# Delete original wp-sample-config.php
|
112
|
-
execute :rm, '-f', File.join(fetch(:wp_docroot), 'wp-config-sample.php')
|
113
|
-
# Create symlink for wp_document_root wp-config.php to 'shared' version.
|
114
|
-
execute :ln, '-sf', shared_wp_config_file_path, wp_docroot_wp_config_file_path
|
115
|
-
|
116
|
-
# Check for robots.txt file in shared. Create if it doesn't exist.
|
117
|
-
unless test("[ -f #{shared_robots_txt_file_path} ]")
|
118
|
-
execute "echo -e \"User-agent: *\nDisallow: /\" > #{shared_robots_txt_file_path}"
|
119
|
-
end
|
120
|
-
# Create symlink for wp_document_root robots.txt to 'shared' version.
|
121
|
-
execute :ln, '-sf', shared_robots_txt_file_path, wp_docroot_robots_txt_file_path
|
122
|
-
|
123
|
-
# Check for actual wp-content directory at wp_content_path. Create if it doesn't exist.
|
124
|
-
unless test("[ -d #{wp_content_path} ]")
|
125
|
-
# If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
|
126
|
-
execute :cp, '-r', wp_docroot_wp_content_path, wp_content_path
|
127
|
-
end
|
128
|
-
# Delete original wp-content directory
|
129
|
-
execute :rm, '-rf', wp_docroot_wp_content_path
|
130
|
-
# Create symlink for wp_document_root wp-content to wp_content_path
|
131
|
-
execute :ln, '-sf', wp_content_path, wp_docroot_wp_content_path
|
132
|
-
end
|
133
|
-
symlink_custom_plugins_and_themes
|
134
|
-
end
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
def self.symlink_custom_plugins_and_themes
|
139
|
-
on roles(:web) do
|
140
|
-
wp_content_path = fetch(:wp_content_path)
|
141
|
-
wp_content_plugin_path = File.join(wp_content_path, 'plugins')
|
142
|
-
wp_content_mu_plugin_path = File.join(wp_content_path, 'mu-plugins')
|
143
|
-
wp_content_themes_path = File.join(wp_content_path, 'themes')
|
144
|
-
|
145
|
-
if test("[ -d #{wp_content_path} ]")
|
146
|
-
|
147
|
-
### Create necessary directories
|
148
|
-
execute :mkdir, '-p', wp_content_plugin_path
|
149
|
-
execute :mkdir, '-p', wp_content_mu_plugin_path
|
150
|
-
execute :mkdir, '-p', wp_content_themes_path
|
151
|
-
|
152
|
-
### Remove old symlinks
|
153
|
-
[wp_content_plugin_path, wp_content_mu_plugin_path, wp_content_themes_path].each do |dir|
|
154
|
-
execute :find, dir, '-maxdepth 1', '-type l', '-exec rm {} \;'
|
155
|
-
end
|
156
|
-
|
157
|
-
### Add latest symlinks
|
158
|
-
fetch(:wp_custom_plugins, {}).each do |plugin, repo_relative_path|
|
159
|
-
execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_plugin_path, plugin)
|
160
|
-
end
|
161
|
-
|
162
|
-
fetch(:wp_custom_mu_plugins, {}).each do |mu_plugin, repo_relative_path|
|
163
|
-
execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_mu_plugin_path, mu_plugin)
|
164
|
-
end
|
165
|
-
|
166
|
-
fetch(:wp_custom_themes, {}).each do |theme, repo_relative_path|
|
167
|
-
execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_themes_path, theme)
|
168
|
-
end
|
169
|
-
|
170
|
-
### Also symlink to cul-allowed-upload-types plugin files
|
171
|
-
within deploy_path do
|
172
|
-
cul_allowed_upload_types_plugin_top_level_files_and_dirs = capture(:find, CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, '-mindepth', '2', '-maxdepth', '2').split("\n")
|
173
|
-
# Symlink all plugin files and directories
|
174
|
-
cul_allowed_upload_types_plugin_top_level_files_and_dirs.each do |plugin_file_or_directory_path|
|
175
|
-
#puts 'Run: ' + [:ln, '-sf', File.join(deploy_path, plugin_file_or_directory_path), File.join(wp_content_mu_plugin_path, File.basename(plugin_file_or_directory_path))].join(' ')
|
176
|
-
execute :ln, '-sf', File.join(deploy_path, plugin_file_or_directory_path), File.join(wp_content_mu_plugin_path, File.basename(plugin_file_or_directory_path))
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
desc "Downloads the latest version of the cul-allowed-upload-types plugin"
|
185
|
-
task :update_cul_allowed_upload_types_plugin do
|
186
|
-
# Download plugin to deploy_path
|
187
|
-
on roles(:web) do
|
188
|
-
within deploy_path do
|
189
|
-
# Clear out old plugin directory if it exists
|
190
|
-
execute :rm, '-rf', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME
|
191
|
-
# Re-create plugin directory and temp dir inside of it
|
192
|
-
allowed_upload_types_tempdir = File.join(CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, 'tmp')
|
193
|
-
execute :mkdir, '-p', allowed_upload_types_tempdir
|
194
|
-
|
195
|
-
# Download and unzip plugin
|
196
|
-
allowed_upload_types_temp_zipfile = File.join(allowed_upload_types_tempdir, 'plugin.zip')
|
197
|
-
zip_file_name = "#{fetch(:cul_allowed_upload_types_version)}.zip"
|
198
|
-
execute :curl, '-L', '--silent', '-o', allowed_upload_types_temp_zipfile, "#{CUL_ALLOWED_UPLOAD_TYPES_REPO_URL}/archive/#{zip_file_name}"
|
199
|
-
execute :unzip, allowed_upload_types_temp_zipfile, '-d', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME
|
200
|
-
|
201
|
-
# Delete temp dir after unzip
|
202
|
-
execute :rm, '-rf', allowed_upload_types_tempdir
|
203
|
-
|
204
|
-
# Remove .gitignore file from plugin directory so we don't symlink to it later
|
205
|
-
execute :find, CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, '-name', '.gitignore', '-delete'
|
206
|
-
end
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
desc "Runs a search and replace operation on the tables in a WordPress installation"
|
211
|
-
task :searchreplace do
|
212
|
-
on roles(:web) do
|
213
|
-
within fetch(:wp_docroot) do
|
214
|
-
set :search_string, ask("search string")
|
215
|
-
set :replacement_string, ask("replacement string")
|
216
|
-
puts "Are you sure you want to replace all occurrences of \"#{fetch(:search_string)}\" with \"#{fetch(:replacement_string)}\"?"
|
217
|
-
set :confirm, ask('"y" or "yes" to continue')
|
218
|
-
|
219
|
-
unless ['y', 'yes'].include?(fetch(:confirm))
|
220
|
-
puts 'Search and replace operation has been cancelled because neither "y" nor "yes" were entered.'
|
221
|
-
next
|
222
|
-
end
|
223
|
-
|
224
|
-
puts 'Running search and replace. This may take a while for large databases...'
|
225
|
-
start_time = Time.now
|
226
|
-
|
227
|
-
if fetch(:multisite, false)
|
228
|
-
puts "Since this is a multisite, you'll need to specify the source multisite instance domain to continue:"
|
229
|
-
set :multisite_url, ask('source multisite instance domain (e.g. blogs.cul.columbia.edu)')
|
230
|
-
|
231
|
-
execute :wp, "--url=#{fetch(:multisite_url)}", 'search-replace', "'#{fetch(:search_string)}'", "'#{fetch(:replacement_string)}'", '--all-tables', '--skip-columns=guid'
|
232
|
-
else
|
233
|
-
execute :wp, 'search-replace', "'#{fetch(:search_string)}'", "'#{fetch(:replacement_string)}'", '--skip-columns=guid'
|
234
|
-
end
|
235
|
-
|
236
|
-
puts "Search and replace complete (took #{(Time.now - start_time).to_s} seconds)"
|
237
|
-
end
|
238
|
-
end
|
239
|
-
end
|
240
|
-
|
241
|
-
def self.cul_allowed_upload_types_plugin_path
|
242
|
-
File.join('mu-plugins', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME)
|
243
|
-
end
|
244
|
-
|
245
|
-
def self.maintenance_file_path
|
246
|
-
File.join(fetch(:wp_docroot), '.maintenance')
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
250
|
-
end
|
@@ -1,268 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
namespace :cul do
|
5
|
-
namespace :wp do
|
6
|
-
namespace :migrate do
|
7
|
-
|
8
|
-
desc "Copies the WordPress installation from one environment to another (e.g. prod to dev)"
|
9
|
-
task :copy_from do
|
10
|
-
# Need to store path as local variable so it can be referenced in `on roles(:web) do` portion of script
|
11
|
-
path_to_allowed_upload_types_plugin = cul_allowed_upload_types_plugin_path
|
12
|
-
|
13
|
-
require_cap_variables!([:wp_docroot, :wp_content_path])
|
14
|
-
|
15
|
-
if fetch(:multisite, false)
|
16
|
-
puts "Since this is a multisite, you'll need to specify the source multisite instance domain to continue:"
|
17
|
-
set :source_site_multisite_url, ask('source multisite instance domain (e.g. blogs.cul.columbia.edu)')
|
18
|
-
fetch(:source_site_multisite_url)
|
19
|
-
|
20
|
-
puts "And you'll also need to specify the destination multisite instance domain to continue:"
|
21
|
-
set :destination_site_multisite_url, ask('destination multisite instance domain (e.g. blogs-dev.cul.columbia.edu)')
|
22
|
-
fetch(:destination_site_multisite_url)
|
23
|
-
end
|
24
|
-
|
25
|
-
# TODO: Would be nice to verify that destination wordpress has already had the setup and deploy tasks run for it
|
26
|
-
set :src_wp_docroot, ask("server path to source WordPress installation (to copy from)")
|
27
|
-
|
28
|
-
# Confirm operation because it is destructive
|
29
|
-
puts "\nWARNING: This operation will obliterate all content in environment [#{fetch(:stage)}] and replace it with content from [#{fetch(:src_wp_docroot)}]."
|
30
|
-
puts "Are you sure you want to continue?"
|
31
|
-
set :confirm, ask('"y" or "yes" to continue')
|
32
|
-
unless ['y', 'yes'].include?(fetch(:confirm))
|
33
|
-
puts 'Copy operation has been cancelled because neither "y" nor "yes" were entered.'
|
34
|
-
next
|
35
|
-
end
|
36
|
-
|
37
|
-
# Don't really care about maintenance mode because we're completely destroying the target environment
|
38
|
-
# Enter maintenance mode
|
39
|
-
#invoke 'cul:wp:enable_maintenance_mode'
|
40
|
-
|
41
|
-
# Check WP version on source WordPress instance
|
42
|
-
failure = false
|
43
|
-
on roles(:web) do
|
44
|
-
within fetch(:src_wp_docroot) do
|
45
|
-
# Ensure that source WordPress is running the latest version
|
46
|
-
result = capture :wp, (fetch(:multisite, false) ? "--url=#{fetch(:source_site_multisite_url)}" : ''), 'core', 'check-update'
|
47
|
-
unless result.index('Success')
|
48
|
-
puts 'Could not copy from source WordPress because it is not running the latest version of WordPress. Please update source before running a copy operation.'
|
49
|
-
failure = true
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
next if failure # End if the previous checks failed
|
54
|
-
|
55
|
-
on roles(:web) do
|
56
|
-
# Destroy current wp_docroot
|
57
|
-
execute :rm, '-rf', fetch(:wp_docroot)
|
58
|
-
execute :mkdir, fetch(:wp_docroot)
|
59
|
-
end
|
60
|
-
|
61
|
-
# Download new copy of wordpress
|
62
|
-
invoke 'cul:wp:setup'
|
63
|
-
|
64
|
-
path_to_list_of_files_to_copy = ''
|
65
|
-
|
66
|
-
on roles(:web) do
|
67
|
-
# In source site's wp-content directory, generate file list to copy
|
68
|
-
within File.join(fetch(:src_wp_docroot), 'wp-content') do
|
69
|
-
# We're going to be copying wp-content in two parts
|
70
|
-
# 1. Everything else under wp-content EXCEPT uploads, blogs.dir,
|
71
|
-
# plugins, themes, mu-plugins
|
72
|
-
# 2. Everything under uploads AND wpblogs.dir with
|
73
|
-
# cul-allowed-upload-types file extension filter applied
|
74
|
-
|
75
|
-
# Make sure find command handles non-ASCII chars
|
76
|
-
#execute 'LC_ALL=en_US.iso885915'
|
77
|
-
|
78
|
-
# Generate two find commands for the above searches
|
79
|
-
find_non_upload_dirs = '. -type f ' +
|
80
|
-
# EXCLUDE plugins, themes, mu-plugins, uploads, and blogs.dir
|
81
|
-
"-not \\( -path './plugins/*' -o -path './mu-plugins/*' -o -path './themes/*' -o -path './uploads/*' -o -path './blogs.dir/*' \\) " +
|
82
|
-
# EXCLUDE certain unwanted files and paths
|
83
|
-
"-a -not \\( -name '.nfs*' -o -name '*.tmp.*' \\) " +
|
84
|
-
"-a -not \\( -path '*/.git*' -o -path '*/.svn*' -o -path '*/.hg*' \\)"
|
85
|
-
|
86
|
-
find_upload_dirs = '. -type f ' +
|
87
|
-
# INCLUDE ONLY uploads and blogs.dir
|
88
|
-
"\\( -path './uploads/*' -o -path './blogs.dir/*' \\) " +
|
89
|
-
# EXCLUDE certain unwanted files and paths
|
90
|
-
"-a -not \\( -name '.nfs*' -o -name '*.tmp.*' \\) " +
|
91
|
-
"-a -not \\( -path '*/.git*' -o -path '*/.svn*' -o -path '*/.hg*' \\) " +
|
92
|
-
# INCLUDE ONLY certain file extensions
|
93
|
-
"-a \\( " + JSON.parse(capture(:wp, (fetch(:multisite, false) ? "--url=#{fetch(:source_site_multisite_url)}" : ''), 'eval', '"echo cul_allowed_upload_file_extensions_as_json();"')).map{ |allowed_file_extension|
|
94
|
-
"-iname '*.#{allowed_file_extension}'"
|
95
|
-
}.join(' -o ') + " \\) "
|
96
|
-
|
97
|
-
path_to_list_of_files_to_copy = '/tmp/WP' + fetch(:wp_docroot).gsub('/', '-') + '-' + Time.now.to_i.to_s + '-files.txt'
|
98
|
-
execute :find, find_non_upload_dirs, ' > ', path_to_list_of_files_to_copy
|
99
|
-
execute :find, find_upload_dirs, ' >> ', path_to_list_of_files_to_copy
|
100
|
-
|
101
|
-
# Print out which files won't be copied
|
102
|
-
files_not_copied = capture(:comm, '-23', "<(find . -type f \\( -path './uploads/*' -o -path './blogs.dir/*' \\) | sort)", "<(find #{find_upload_dirs} | sort)")
|
103
|
-
|
104
|
-
puts (
|
105
|
-
"The following files will not be copied:\n" +
|
106
|
-
"-------------------------\n" +
|
107
|
-
"./plugins\n" +
|
108
|
-
"./mu-plugins\n" +
|
109
|
-
"./themes\n" +
|
110
|
-
files_not_copied + "\n" +
|
111
|
-
"-------------------------"
|
112
|
-
)
|
113
|
-
end
|
114
|
-
|
115
|
-
# For destination wordpress, delete and recreate the wp-content directory
|
116
|
-
execute :rm, '-rf', fetch(:wp_content_path)
|
117
|
-
execute :mkdir, fetch(:wp_content_path)
|
118
|
-
|
119
|
-
# Copy wp-content files (from path_to_list_of_files_to_copy) from source WP to destination WP
|
120
|
-
# Note that because we have the '--copy-links' flag below, we're transforming all symlinks into real file copies
|
121
|
-
rsync_params = [
|
122
|
-
'--recursive',
|
123
|
-
'--perms',
|
124
|
-
'--times',
|
125
|
-
'--devices',
|
126
|
-
'--specials',
|
127
|
-
'--copy-links',
|
128
|
-
'--prune-empty-dirs'
|
129
|
-
]
|
130
|
-
|
131
|
-
# we're only copying files from the given file list
|
132
|
-
rsync_params << "--files-from=#{path_to_list_of_files_to_copy}"
|
133
|
-
|
134
|
-
src_wp_content_dir = File.join(fetch(:src_wp_docroot), 'wp-content/')
|
135
|
-
# Run a find operation on the wp-content dir to pre-cache all non-UTF compliant files prior to our rsync operation (to handle files with smart quotes, em dashes, foreign characters, etc.)
|
136
|
-
#execute :find, src_wp_content_dir, '-print0', '|', 'perl', '-n0e', '\'chomp; print $_, "\n" if /[[:^ascii:][:cntrl:]]/\''
|
137
|
-
|
138
|
-
# src directory (--files-from values are relative to this src directory)
|
139
|
-
rsync_params << src_wp_content_dir
|
140
|
-
# dest directory
|
141
|
-
rsync_params << fetch(:wp_content_path) + '/'
|
142
|
-
|
143
|
-
puts 'Copying wp-content. This may take a while for sites with a lot of uploads...'
|
144
|
-
|
145
|
-
puts 'rsync args:'
|
146
|
-
puts rsync_params.join(' ')
|
147
|
-
|
148
|
-
# begin
|
149
|
-
execute :rsync, *rsync_params
|
150
|
-
# rescue
|
151
|
-
# puts '--- Rsync failed, but will continue with deployment anyway!'
|
152
|
-
# end
|
153
|
-
|
154
|
-
# clean up path_to_list_of_files_to_copy file
|
155
|
-
execute :rm, path_to_list_of_files_to_copy
|
156
|
-
|
157
|
-
# Next, create symlinks to repo-managed plugins and themes, which will also recreate plugins, mu-plugins, and themes directories
|
158
|
-
|
159
|
-
within fetch(:wp_docroot) do
|
160
|
-
# Regenerate symlinks
|
161
|
-
invoke! 'cul:wp:symlink_custom_plugins_and_themes'
|
162
|
-
end
|
163
|
-
|
164
|
-
# Now it's time to copy the database
|
165
|
-
|
166
|
-
db_export_tempfile_path = ''
|
167
|
-
|
168
|
-
within fetch(:src_wp_docroot) do
|
169
|
-
# On source WordPress...
|
170
|
-
|
171
|
-
puts 'Exporting database from source site. This may take a while for large sites...'
|
172
|
-
# Export source WP DB to a temporary file
|
173
|
-
db_export_tempfile_path = Dir::Tmpname.make_tmpname '/tmp/', 'db_export_tempfile.sql'
|
174
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:source_site_multisite_url)}" : ''), 'db', 'export', db_export_tempfile_path
|
175
|
-
end
|
176
|
-
|
177
|
-
within fetch(:wp_docroot) do
|
178
|
-
# On destination WordPress...
|
179
|
-
|
180
|
-
puts 'Importing database. This may take a while for large sites...'
|
181
|
-
|
182
|
-
# Drop all tables
|
183
|
-
execute :wp, 'db', 'reset', '--yes'
|
184
|
-
|
185
|
-
# Read in db file
|
186
|
-
execute :wp, 'db', 'import', db_export_tempfile_path
|
187
|
-
|
188
|
-
# Delete db file now that we're done with it
|
189
|
-
execute :rm, db_export_tempfile_path
|
190
|
-
|
191
|
-
# Invoke searchreplace task to update URL
|
192
|
-
puts "\nYou'll probably want to run the cul:wp:searchreplace command now, since it's likely that your WP URL differs between environments."
|
193
|
-
puts "Do you want to run a search and replace operation?"
|
194
|
-
set :confirm_searchreplace, ask('"y" or "yes" to continue')
|
195
|
-
if ['y', 'yes'].include?(fetch(:confirm_searchreplace))
|
196
|
-
invoke 'cul:wp:searchreplace'
|
197
|
-
else
|
198
|
-
puts '- Skipping search and replace because neither "y" nor "yes" were entered.'
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
# Next, install all plugins and themes from src wordpress, matching all versions and active vs. inactive plugin and theme states
|
203
|
-
|
204
|
-
data_for_plugins = []
|
205
|
-
data_for_themes = []
|
206
|
-
|
207
|
-
# Within src wp instance, get list of all plugins and themes with version
|
208
|
-
within File.join(fetch(:src_wp_docroot)) do
|
209
|
-
data_for_plugins = JSON.parse(capture(:wp, (fetch(:multisite, false) ? "--url=#{fetch(:source_site_multisite_url)}" : ''), 'plugin', 'list', '--fields=name,version,status', '--format=json'))
|
210
|
-
data_for_themes = JSON.parse(capture(:wp, (fetch(:multisite, false) ? "--url=#{fetch(:source_site_multisite_url)}" : ''), 'theme', 'list', '--fields=name,version,status', '--format=json'))
|
211
|
-
end
|
212
|
-
|
213
|
-
# Within dest wp instance, install specifically versioned plugins and themes
|
214
|
-
within File.join(fetch(:wp_docroot)) do
|
215
|
-
# Get list of repo-managed plugins and themes so that we don't attempt to overwrite these directories
|
216
|
-
repo_managed_plugin_names = fetch(:wp_custom_plugins, {}).keys
|
217
|
-
repo_managed_theme_names = fetch(:wp_custom_themes, {}).keys
|
218
|
-
|
219
|
-
puts "Downloading new copies of non-repo-managed plugins and themes..."
|
220
|
-
|
221
|
-
data_for_plugins.delete_if{|plugin_info| repo_managed_plugin_names.include?(plugin_info['name']) }.each do |plugin_info|
|
222
|
-
name = plugin_info['name']
|
223
|
-
version = plugin_info['version']
|
224
|
-
status = plugin_info['status']
|
225
|
-
|
226
|
-
case status
|
227
|
-
when 'active'
|
228
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:destination_site_multisite_url)}" : ''), 'plugin', 'install', name, "--version=#{version}", '--activate'
|
229
|
-
when 'active-network'
|
230
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:destination_site_multisite_url)}" : ''), 'plugin', 'install', name, "--version=#{version}", '--activate-network'
|
231
|
-
when 'inactive'
|
232
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:destination_site_multisite_url)}" : ''), 'plugin', 'install', name, "--version=#{version}"
|
233
|
-
when 'must-use'
|
234
|
-
puts "--- WARNING: must-use plugin #{name} was not migrated over. It should be put in your blog's repository and deployed through a regular deployment."
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
data_for_themes.delete_if{|theme_info| repo_managed_theme_names.include?(theme_info['name']) }.each do |theme_info|
|
239
|
-
name = theme_info['name']
|
240
|
-
version = theme_info['version']
|
241
|
-
status = theme_info['status']
|
242
|
-
|
243
|
-
case status
|
244
|
-
when 'active'
|
245
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:destination_site_multisite_url)}" : ''), 'theme', 'install', name, "--version=#{version}", '--activate'
|
246
|
-
when 'inactive', 'parent'
|
247
|
-
execute :wp, (fetch(:multisite, false) ? "--url=#{fetch(:destination_site_multisite_url)}" : ''), 'theme', 'install', name, "--version=#{version}"
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
|
252
|
-
within fetch(:wp_docroot) do
|
253
|
-
# Make docroot readable and executable for "other" user so nginx, which runs as "nobody", can read
|
254
|
-
# Use -L flag because we want to follow symlinks. The whole deployment relies on symlinks.
|
255
|
-
execute :find, '-L', File.join(fetch(:wp_docroot), 'wp-content'), '-type d -exec chmod o+rx "{}" \;'
|
256
|
-
execute :find, '-L', File.join(fetch(:wp_docroot), 'wp-content'), '-type f -exec chmod o+r "{}" \;'
|
257
|
-
# Make sure that wp-config file is not world readable
|
258
|
-
execute :chmod, 'o-r', shared_path.join('wp-config.php')
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
#after 'cul:wp:migrate:copy_from', 'cul:wp:disable_maintenance_mode'
|
265
|
-
|
266
|
-
end
|
267
|
-
end
|
268
|
-
end
|