class Shuttle::Wordpress

Public Instance Methods

activate_theme() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 209
def activate_theme
  name = config.wordpress.theme
  result = ssh.run("cd #{release_path} && wp theme activate #{name}")

  if result.failure?
    error "Unable to activate theme. Error: #{result.output}"
  end
end
check_config() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 114
def check_config
  if !ssh.file_exists?(shared_path('wordpress/core/wp-config.php'))
    log "Creating wordpress config"
    generate_config
  end
end
check_dependencies() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 69
def check_dependencies
  if !svn_installed?
    log "Installing Subversion"
    if ssh.run("sudo apt-get install -y subversion").success?
      log "Subversion installed"
    end
  end
end
check_plugins() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 178
def check_plugins
  plugins = config.wordpress.plugins

  if plugins
    if plugins.kind_of?(Array)
      plugins.each do |p|
        if p.kind_of?(String)
          plugin_install(p)
        elsif p.kind_of?(Hash)
          name, url = p.to_a.flatten.map(&:to_s)
          plugin_custom_install(name, url)
        end
      end
    else
      error "Config file has invalid plugins section"
    end
  end
end
checkout_theme() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 197
def checkout_theme
  if config.wordpress
    if config.wordpress.theme
      checkout_code("wp-content/themes/#{config.wordpress.theme}")
    else
      error "Theme name is not defined."
    end
  else
    error "Config does not contain 'wordpress' section"
  end
end
deploy() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 46
def deploy
  setup
  update_code
  link_shared_data
  checkout_theme

  if vip_required?
    vip_install if !vip_installed?
    vip_link
  end

  if !site_installed?
    site_install
    network_install
  end

  check_plugins
  activate_theme

  link_release
  cleanup_releases
end
generate_config() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 91
def generate_config
  mysql = config.wordpress.mysql
  if mysql.nil?
    error "Missing :mysql section of the config."
  end

  cmd = [
    "wp core config",
    "--dbname=#{mysql.database}",
    "--dbhost=#{mysql.host || 'localhost'}",
    "--dbuser=#{mysql.user}"
  ]

  cmd << "--dbpass=#{mysql.password}" if mysql.password

  res = ssh.run("cd #{core_path} && #{cmd.join(' ')}")
  if res.success?
    log "A new wordpress config has been generated"
  else
    error "Unable to generate config. Error: #{res.output}"
  end
end
network_install() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 154
def network_install
  if config.wordpress.network
    network = config.wordpress.network

    cmd = [
      "wp core install-network",
      "--title=#{network.title}",
    ].join(' ')

    result = ssh.run("cd #{release_path} && #{cmd}")
    if result.failure?
      error "Failed to setup WP network. #{result.output}"
    end
  end
end
setup() click to toggle source
Calls superclass method Shuttle::Php#setup
# File lib/shuttle/deployment/wordpress.rb, line 13
def setup
  if config.wordpress.nil?
    error "Please add :wordpress section to your config"
  end

  super

  setup_shared_dirs
  check_dependencies

  if !cli_installed?
    cli_install
  else
    version = ssh.capture("cd #{core_path} && wp --version")
    version.gsub!('wp-cli', '').to_s.strip!
    log "WordPress CLI version: #{version}"
  end

  if !core_installed?      
    core_install
  else
    res = ssh.run("cd #{core_path} && wp core version")

    if res.success?
      log "WordPress core version: #{res.output}"
    else
      warn "Unable to detect WordPress core version: #{res.output}"
    end
  end

  check_config
end
setup_shared_dirs() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 78
def setup_shared_dirs
  dirs = [
    'wordpress',
    'wordpress/uploads',
    'wordpress/core',
    'wordpress/plugins'
  ]

  dirs.each do |path|
    ssh.run("mkdir -p #{shared_path(path)}")
  end
end
site_install() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 132
def site_install
  if config.wordpress.site
    site = config.wordpress.site

    cmd = [
      "wp core install",
      "--url=#{site.url}",
      "--title=#{site.title.gsub(" ", "\\ ")}",
      "--admin_name=#{site.admin_name}",
      "--admin_email=#{site.admin_email}",
      "--admin_password=#{site.admin_password}"
    ].join(' ')

    result = ssh.run("cd #{release_path} && #{cmd}")
    if result.failure?
      error "Failed to setup site. #{result.output}"
    end
  else
    error "Please define :site section"
  end
end
site_installed?() click to toggle source
# File lib/shuttle/deployment/wordpress.rb, line 121
def site_installed?
  result = ssh.run("cd #{release_path} && wp core is-installed")

  if result.failure? && debug?
    log "Wordpress core check failed:"
    log result.output
  end

  result.success?
end