class Wordmove::SqlAdapter::Wpcli

Attributes

from[R]
local_path[R]
sql_content[RW]
to[R]

Public Class Methods

new(source_config, dest_config, config_key, local_path) click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 7
def initialize(source_config, dest_config, config_key, local_path)
  @from = source_config[config_key]
  @to = dest_config[config_key]
  @local_path = local_path
end

Public Instance Methods

command() click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 13
def command
  unless wp_in_path?
    raise UnmetPeerDependencyError, "WP-CLI is not installed or not in your $PATH"
  end

  opts = [
    "--path=#{cli_config_path}",
    from,
    to,
    "--quiet",
    "--skip-columns=guid",
    "--all-tables",
    "--allow-root"
  ]

  "wp search-replace #{opts.join(' ')}"
end

Private Instance Methods

cli_config_path() click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 37
def cli_config_path
  load_from_yml || load_from_cli || local_path
end
load_from_cli() click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 48
def load_from_cli
  cli_config = JSON.parse(`wp cli param-dump --with-values`, symbolize_names: true)
  cli_config.dig(:path, :current)
end
load_from_yml() click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 41
def load_from_yml
  cli_config_path = File.join(local_path, "wp-cli.yml")
  return unless File.exist?(cli_config_path)

  YAML.load_file(cli_config_path).with_indifferent_access["path"]
end
wp_in_path?() click to toggle source
# File lib/wordmove/sql_adapter/wpcli.rb, line 33
def wp_in_path?
  system('which wp > /dev/null 2>&1')
end