module DanarchyDeploy::Applicator::WordPress
Public Class Methods
new(app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 8 def self.new(app, options) puts "\n" + self.name puts " > Checking on WordPress installation at '#{app[:path]}'." app[:prefix] = cmd_prefix(app) wpcli = WordPress::WPCLI.new(app, options) app = WordPress::WPConfig.new(app, options) # if options[:first_run] && wpcli.install if wpcli.version[:stderr] =~ /Error: This does not seem to be a WordPress install/ siteurl = wpcli.siteurl if siteurl =~ /http.*:\/\/(www.|)#{app[:domain]}/ puts " |+ Siteurl: #{siteurl} found in the WP database. Continuing with deployment." elsif siteurl =~ /Error: The site you have requested is not installed/ puts " |! Domain: #{app[:domain]} not found in current database." db_backup = app[:path] + '/' + app[:domain].gsub('.','_') + '.sql' if File.exist?(db_backup) && options[:first_run] puts " |+ Importing from local backup." import = wpcli.import else puts " |- . No database content! Skipping deployment of #{app[:domain]}." return app end else puts " ! Domain: #{app[:domain]} does not match the database's current siteurl: #{siteurl}" puts " |- Skipping #{app[:domain]} deployment" return app end if app[:autoupdate] wpcli.update else wpcli.check_update end app.delete(:prefix) app end
Private Class Methods
cmd_prefix(app)
click to toggle source
puts “n > Verifying wp-config.php for '#{app}/wp-config.php'.” wp_config_new(app, options)
app
end
# File lib/danarchy_deploy/applicator/wordpress.rb, line 73 def self.cmd_prefix(app) "sudo -u #{app[:username]} bash -c " # wp_root_mkdir(prefix, app, options) # wp_cli_install(options) # prefix end
wp_cli_install(options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 91 def self.wp_cli_install(options) wpcli_install = 'bash ' + File.expand_path( File.dirname(__FILE__) + '/wordpress/wpcli_install.sh') wpcli_result = DanarchyDeploy::Helpers.run_command(wpcli_install, options) if wpcli_result[:stderr] abort(' ! WP-CLI installation failed!') else puts ' |+ WP-CLI installed.' end end
wp_config_verify(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 139 def self.wp_config_verify(prefix, app, options) config_cmd = prefix + "wp config list DB_USER DB_PASSWORD DB_NAME DB_HOST table_prefix --path=#{app[:path]} --format=json" wp_config_current = JSON.parse(`#{config_cmd}`) p wp_config_current end
wp_ensure_installed(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 104 def self.wp_ensure_installed(prefix, app, options) installed = false version = nil if Dir.entries(app[:path]) == %w[. ..] puts " |+ Installing WordPress to: #{app[:path]}" wp_install(prefix, app, options) # wp_config_new(app, options) # return end version = wp_version(prefix, app, options) # Error: This does not seem to be a WordPress install. end
wp_install(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 119 def self.wp_install(prefix, app, options) cmd = prefix + "'wp core download --path=#{app[:path]}'" DanarchyDeploy::Helpers.run_command(cmd, options) end
wp_root_mkdir(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 80 def self.wp_root_mkdir(prefix, app, options) mkdir_cmd = prefix + "'test -d #{app[:path]} || mkdir -v #{app[:path]}'" mkdir_result = DanarchyDeploy::Helpers.run_command(mkdir_cmd, options) if mkdir_result[:stderr] abort(" ! Failed to create directory: #{app[:path]}!") elsif mkdir_result[:stdout] puts " |+ Created directory: #{app[:path]}" end end
wp_update(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 124 def self.wp_update(prefix, app, options) cmd = prefix + "'wp core update --path=#{app[:path]}'" DanarchyDeploy::Helpers.run_command(cmd, options) end
wp_verify_uptodate()
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 134 def self.wp_verify_uptodate() check_cmd = prefix + "'wp core check-update --path=#{app[:path]}'" DanarchyDeploy::Helpers.run_command(check_cmd, options) end
wp_version(prefix, app, options)
click to toggle source
# File lib/danarchy_deploy/applicator/wordpress.rb, line 129 def self.wp_version(prefix, app, options) cmd = prefix + "'wp core version --path=#{app[:path]}'" DanarchyDeploy::Helpers.run_command(cmd, options) end