capistrano-cul 0.0.17 → 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,250 @@
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,32 +1,24 @@
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_uplaod_types_version here so it can be overridden by env config
5
- set :cul_allowed_uplaod_types_version, 'v0.5.0'
1
+ set :cul_allowed_upload_types_version, 'v0.5.0' # can be overridden by an app's deploy.rb file
2
+ set :cul_allowed_upload_types_plugin_name, 'cul-allowed-upload-types'
3
+ set :cul_allowed_upload_types_downloaded_plugin_path, ->{current_path.join(fetch(:cul_allowed_upload_types_plugin_name))} # can be overridden by an app's deploy.rb file
6
4
 
7
5
  namespace :cul do
8
6
  namespace :wp do
9
- before 'deploy:starting', 'cul:wp:display_maintenance_mode_warning'
10
- after 'deploy:starting', 'cul:wp:enable_maintenance_mode'
11
- after 'deploy:starting', 'cul:wp:update_cul_allowed_upload_types_plugin'
12
- after :deploy, 'cul:wp:symlink_custom_plugins_and_themes'
13
- after :deploy, 'cul:wp:disable_maintenance_mode'
14
7
 
15
- desc "Displays a message to the deploying user about how to disable maintenance mode"
16
- task :display_maintenance_mode_warning do
17
- 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")
18
- end
8
+ set :maintenance_file_path, ->{
9
+ require_cap_variables!([:wp_docroot])
10
+ File.join(fetch(:wp_docroot), '.maintenance')
11
+ }
19
12
 
20
13
  desc "Enables maintenance mode for the WordPress site in the deploy environment"
21
14
  task :enable_maintenance_mode do
22
- path_to_maintenance_file = maintenance_file_path # save path to local variable because we can't call method inside `on roles(:web)`
23
15
  on roles(:web) do
24
16
  within fetch(:wp_docroot) do
25
17
  # Set maintenance $upgrading value to current time.
26
18
  # Note that WordPress will ignore maintenance mode file
27
19
  # after 10 minutes have passed after the maintenance time
28
20
  # we set in the file.
29
- execute :echo, "'<?php $upgrading = #{Time.now.to_i};'", '>', path_to_maintenance_file
21
+ execute :echo, "'<?php $upgrading = #{Time.now.to_i};'", '>', fetch(:maintenance_file_path)
30
22
  end
31
23
  end
32
24
  puts color_text("Maintenance mode enabled!")
@@ -34,11 +26,10 @@ namespace :cul do
34
26
 
35
27
  desc "Disable maintenance mode for the WordPress site in the deploy environment"
36
28
  task :disable_maintenance_mode do
37
- path_to_maintenance_file = maintenance_file_path # save path to local variable because we can't call method inside `on roles(:web)`
38
29
  on roles(:web) do
39
30
  within fetch(:wp_docroot) do
40
- if test("[ -f #{path_to_maintenance_file} ]")
41
- execute :rm, path_to_maintenance_file
31
+ if test("[ -f #{fetch(:maintenance_file_path)} ]")
32
+ execute :rm, fetch(:maintenance_file_path)
42
33
  else
43
34
  puts "No maintenance file found, so there's nothing to delete."
44
35
  end
@@ -47,205 +38,25 @@ namespace :cul do
47
38
  puts color_text("Maintenance mode disabled!")
48
39
  end
49
40
 
50
- desc "Creates symlinks for custom plugins and themes as part of a WordPress deployment. Generally run as an `after :deploy` hook."
51
- task :symlink_custom_plugins_and_themes do
52
- symlink_custom_plugins_and_themes
53
- end
54
-
55
- # Runs normal deploy task, downloads new copy of WP, sets up docroot, runs
56
- # deploy command, sets up symlinks. Does not run WP install and does not
57
- # create any wp users.
58
- desc "Sets up a WordPress docroot and runs deployment; does not install wordpress and does not create any users"
59
- task :setup do
60
- puts "Deploying repo branch: #{fetch(:branch)}"
61
-
62
- set :wp_version, ask('WordPress version to download:', 'latest')
63
- # Printing out wp_version here because the `set` command above only runs
64
- # the first time its associated symbol is referenced, and we want to
65
- # capture version before running any other commands.
66
- puts "Setting up wp_version: #{fetch(:wp_version)}"
67
-
68
- require_cap_params!([:branch, :wp_version, :wp_docroot, :wp_content_path])
69
-
70
- on roles(:web) do
71
- wp_docroot_wp_config_file_path = File.join(fetch(:wp_docroot), 'wp-config.php')
72
- wp_docroot_robots_txt_file_path = File.join(fetch(:wp_docroot), 'robots.txt')
73
- wp_docroot_wp_content_path = File.join(fetch(:wp_docroot), 'wp-content')
74
-
75
- shared_wp_config_file_path = shared_path.join('wp-config.php')
76
- shared_robots_txt_file_path = shared_path.join('robots.txt')
77
-
78
- wp_content_path = fetch(:wp_content_path)
79
-
80
- # Create nginx logs directory if it doesn't already exist
81
- execute :mkdir, '-p', deploy_path.join('logs')
82
-
83
- # Make full path to wp_docroot directory if not exist
84
- execute :mkdir, '-p', fetch(:wp_docroot)
85
-
86
- # Make full path to wp_content_path if not exist
87
- execute :mkdir, '-p', wp_content_path
88
-
89
- invoke 'deploy' # Deploy before doing setup
90
-
91
- # If wp_docroot/wp-includes does not exist, do wordpress download
92
- unless test("[ -d #{File.join(fetch(:wp_docroot), 'wp-includes')} ]")
93
- # Download and unpack new WP instance to wp_docroot
94
- execute :wp, 'core', ['download', "--version=#{fetch(:wp_version)}", "--path=#{fetch(:wp_docroot)}"]
95
- end
96
-
97
- # Check for wp-config.php file in shared. Create if it doesn't exist.
98
- unless test("[ -f #{shared_wp_config_file_path} ]")
99
- # If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
100
- execute :cp, File.join(fetch(:wp_docroot), 'wp-config-sample.php'), shared_wp_config_file_path
101
- end
102
-
103
- # Delete original wp-sample-config.php
104
- execute :rm, '-f', File.join(fetch(:wp_docroot), 'wp-config-sample.php')
105
- # Create symlink for wp_document_root wp-config.php to 'shared' version.
106
- execute :ln, '-sf', shared_wp_config_file_path, wp_docroot_wp_config_file_path
107
-
108
- # Check for robots.txt file in shared. Create if it doesn't exist.
109
- unless test("[ -f #{shared_robots_txt_file_path} ]")
110
- execute "echo -e \"User-agent: *\nDisallow: /\" > #{shared_robots_txt_file_path}"
111
- end
112
- # Create symlink for wp_document_root robots.txt to 'shared' version.
113
- execute :ln, '-sf', shared_robots_txt_file_path, wp_docroot_robots_txt_file_path
114
-
115
- # Check for actual wp-content directory at wp_content_path. Create if it doesn't exist.
116
- unless test("[ -d #{wp_content_path} ]")
117
- # If no wp-config.php file is found in the 'shared' directory, copy WordPress built-in wp-config-sample.php to there
118
- execute :cp, '-r', wp_docroot_wp_content_path, wp_content_path
119
- end
120
- # Delete original wp-content directory
121
- execute :rm, '-rf', wp_docroot_wp_content_path
122
- # Create symlink for wp_document_root wp-content to wp_content_path
123
- execute :ln, '-sf', wp_content_path, wp_docroot_wp_content_path
124
- end
125
- symlink_custom_plugins_and_themes
126
- end
127
-
128
- desc "Runs a WordPress installation for a newly set up instance and creates a new admin user"
129
- task :install do
130
- puts "Please provide administrative credentials:"
131
- ask(:admin_user, "Admin username:")
132
- ask(:admin_password, "Admin password:", echo: false)
133
- ask(:admin_email, "Admin email:")
134
-
135
- require_cap_params!([:url, :title, :admin_user, :admin_password, :admin_email])
136
-
137
- on roles(:web) do
138
- within fetch(:wp_docroot) do
139
- execute :wp, 'core', fetch(:multisite) ? 'multisite-install' : 'install',
140
- "--url='#{fetch(:url)}'",
141
- "--title='#{fetch(:title)}'",
142
- "--admin_user='#{fetch(:admin_user)}'",
143
- "--admin_password='#{fetch(:admin_password)}'",
144
- "--admin_email='#{fetch(:admin_email)}'"
145
- end
146
- end
147
- end
148
-
149
- def self.require_cap_params!(vars)
150
- validate vars do |key, value|
151
- if value.nil? || value.empty?
152
- raise Capistrano::ValidationError, "Missing required parameter #{key}"
153
- end
154
- end
155
- end
156
-
157
- def self.symlink_custom_plugins_and_themes
158
- on roles(:web) do
159
- wp_content_path = fetch(:wp_content_path)
160
- wp_content_plugin_path = File.join(wp_content_path, 'plugins')
161
- wp_content_mu_plugin_path = File.join(wp_content_path, 'mu-plugins')
162
- wp_content_themes_path = File.join(wp_content_path, 'themes')
163
-
164
- if test("[ -d #{wp_content_path} ]")
165
-
166
- ### Create necessary directories
167
- execute :mkdir, '-p', wp_content_plugin_path
168
- execute :mkdir, '-p', wp_content_mu_plugin_path
169
- execute :mkdir, '-p', wp_content_themes_path
170
-
171
- ### Remove old symlinks
172
- [wp_content_plugin_path, wp_content_mu_plugin_path, wp_content_themes_path].each do |dir|
173
- execute :find, dir, '-maxdepth 1', '-type l', '-exec rm {} \;'
174
- end
175
-
176
- ### Add latest symlinks
177
- fetch(:wp_custom_plugins, {}).each do |plugin, repo_relative_path|
178
- execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_plugin_path, plugin)
179
- end
180
-
181
- fetch(:wp_custom_mu_plugins, {}).each do |mu_plugin, repo_relative_path|
182
- execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_mu_plugin_path, mu_plugin)
183
- end
184
-
185
- fetch(:wp_custom_themes, {}).each do |theme, repo_relative_path|
186
- execute :ln, '-sf', File.join(current_path, repo_relative_path), File.join(wp_content_themes_path, theme)
187
- end
188
-
189
- ### Also symlink to cul-allowed-upload-types plugin files
190
- within deploy_path do
191
- cul_allowed_upload_types_plugin_top_level_files_and_dirs = capture(:find, CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, '-mindepth', '2', '-maxdepth', '2').split("\n")
192
- # Symlink all plugin files and directories
193
- cul_allowed_upload_types_plugin_top_level_files_and_dirs.each do |plugin_file_or_directory_path|
194
- #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(' ')
195
- 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))
196
- end
197
- end
198
-
199
- end
200
- end
201
- end
202
-
203
- desc "Downloads the latest version of the cul-allowed-upload-types plugin"
204
- task :update_cul_allowed_upload_types_plugin do
205
- # Download plugin to deploy_path
206
- on roles(:web) do
207
- within deploy_path do
208
- # Clear out old plugin directory if it exists
209
- execute :rm, '-rf', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME
210
- # Re-create plugin directory and temp dir inside of it
211
- allowed_upload_types_tempdir = File.join(CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, 'tmp')
212
- execute :mkdir, '-p', allowed_upload_types_tempdir
213
-
214
- # Download and unzip plugin
215
- allowed_upload_types_temp_zipfile = File.join(allowed_upload_types_tempdir, 'plugin.zip')
216
- zip_file_name = "#{fetch(:cul_allowed_uplaod_types_version)}.zip"
217
- execute :curl, '-L', '--silent', '-o', allowed_upload_types_temp_zipfile, "#{CUL_ALLOWED_UPLOAD_TYPES_REPO_URL}/archive/#{zip_file_name}"
218
- execute :unzip, allowed_upload_types_temp_zipfile, '-d', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME
41
+ desc "Runs a search and replace operation on the tables in a WordPress installation"
42
+ task :searchreplace do
219
43
 
220
- # Delete temp dir after unzip
221
- execute :rm, '-rf', allowed_upload_types_tempdir
44
+ set :search_string, ask("search string")
45
+ set :replacement_string, ask("replacement string")
222
46
 
223
- # Remove .gitignore file from plugin directory so we don't symlink to it later
224
- execute :find, CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME, '-name', '.gitignore', '-delete'
225
- end
47
+ unless enter_y_to_continue(color_text("This will replace all occurrences of \"#{fetch(:search_string)}\" with \"#{fetch(:replacement_string)}\"."))
48
+ puts 'Search and replace cancelled because "y" was not entered.'
49
+ next
226
50
  end
227
- end
228
51
 
229
- desc "Runs a search and replace operation on the tables in a WordPress installation"
230
- task :searchreplace do
231
52
  on roles(:web) do
232
53
  within fetch(:wp_docroot) do
233
- set :search_string, ask("search string")
234
- set :replacement_string, ask("replacement string")
235
- puts "Are you sure you want to replace all occurrences of \"#{fetch(:search_string)}\" with \"#{fetch(:replacement_string)}\"?"
236
- set :confirm, ask('"y" or "yes" to continue')
237
-
238
- unless ['y', 'yes'].include?(fetch(:confirm))
239
- puts 'Search and replace operation has been cancelled because neither "y" nor "yes" were entered.'
240
- next
241
- end
242
-
243
54
  puts 'Running search and replace. This may take a while for large databases...'
244
55
  start_time = Time.now
245
56
 
246
57
  if fetch(:multisite, false)
247
- puts "Since this is a multisite, you'll need to specify the source multisite instance domain to continue:"
248
- set :multisite_url, ask('source multisite instance domain (e.g. blogs.cul.columbia.edu)')
58
+ puts "Since this is a multisite, you'll need to specify the original multisite instance domain to continue:"
59
+ set :multisite_url, ask('original multisite instance domain (e.g. blogs.cul.columbia.edu)')
249
60
 
250
61
  execute :wp, "--url=#{fetch(:multisite_url)}", 'search-replace', "'#{fetch(:search_string)}'", "'#{fetch(:replacement_string)}'", '--all-tables', '--skip-columns=guid'
251
62
  else
@@ -257,18 +68,20 @@ namespace :cul do
257
68
  end
258
69
  end
259
70
 
260
- def self.cul_allowed_upload_types_plugin_path
261
- File.join('mu-plugins', CUL_ALLOWED_UPLOAD_TYPES_PLUGIN_NAME)
262
- end
263
-
264
- def self.maintenance_file_path
265
- File.join(fetch(:wp_docroot), '.maintenance')
71
+ def self.require_dest_wp_domain_if_multisite!
72
+ if(fetch(:multisite))
73
+ puts "Since this is a multisite, you'll need to specify the DESTINATION instance domain to continue:"
74
+ set :dest_multisite_domain, ask('destination multisite instance domain (e.g. blogs-dev.cul.columbia.edu)')
75
+ require_cap_variables!([:dest_multisite_domain])
76
+ end
266
77
  end
267
78
 
268
- def self.color_text(message, color_number=35)
269
- text_color = "\e[#{color_number}m"
270
- default_color = "\e[0m"
271
- text_color + message + default_color
79
+ def self.require_src_wp_domain_if_multisite!
80
+ if(fetch(:multisite))
81
+ puts "Since this is a multisite, you'll need to specify the SOURCE instance domain to continue:"
82
+ set :src_multisite_domain, ask('source multisite instance domain (e.g. blogs.cul.columbia.edu)')
83
+ require_cap_variables!([:src_multisite_domain])
84
+ end
272
85
  end
273
86
 
274
87
  end
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.17
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carla Galarza
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2018-02-15 00:00:00.000000000 Z
12
+ date: 2018-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: capistrano-git-with-submodules
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -58,8 +72,13 @@ files:
58
72
  - lib/capistrano/cul/tasks.rb
59
73
  - lib/capistrano/cul/wp.rb
60
74
  - lib/capistrano/tasks/cul.cap
75
+ - lib/capistrano/tasks/wp-old.cap
61
76
  - lib/capistrano/tasks/wp.cap
77
+ - lib/capistrano/tasks/wp/deploy.cap
78
+ - lib/capistrano/tasks/wp/install.cap
79
+ - lib/capistrano/tasks/wp/migrate-old.cap
62
80
  - lib/capistrano/tasks/wp/migrate.cap
81
+ - lib/capistrano/tasks/wp/setup.cap
63
82
  - lib/capistrano/tasks/wp/update.cap
64
83
  homepage: https://github.com/cul/capistrano-cul
65
84
  licenses: