-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6627543
commit e2c13c0
Showing
7 changed files
with
107 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Wordmove | ||
module Wpcli | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
private_class_method :load_from_wpcli, :load_from_yml | ||
end | ||
|
||
class_methods do # rubocop:disable Metrics/BlockLength | ||
def wp_in_path? | ||
system('which wp > /dev/null 2>&1') | ||
end | ||
|
||
def wpcli_search_replace_command(context, config_key) | ||
[ | ||
'wp search-replace', | ||
"--path=#{wpcli_config_path(context)}", | ||
context.remote_options[config_key], | ||
context.local_options[config_key], | ||
'--quiet', | ||
'--skip-columns=guid', | ||
'--all-tables', | ||
'--allow-root' | ||
].join(' ') | ||
end | ||
|
||
def wpcli_config_path(context) | ||
load_from_yml(context) || load_from_wpcli || context.local_options[:wordpress_path] | ||
end | ||
|
||
def load_from_yml(context) | ||
yml_path = File.join(context.local_options[:wordpress_path], 'wp-cli.yml') | ||
|
||
return unless File.exist?(yml_path) | ||
|
||
YAML.load_file(yml_path).with_indifferent_access['path'] | ||
end | ||
|
||
def load_from_wpcli | ||
wpcli_config = JSON.parse(`wp cli param-dump --with-values`, symbolize_names: true) | ||
wpcli_config.dig(:path, :current) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
path: /path/to/steak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
|
||
describe Wordmove::Wpcli do | ||
subject do | ||
Class.new do | ||
include Wordmove::Wpcli | ||
end | ||
end | ||
|
||
let(:a_context) do | ||
OrganizerContextFactory.make_for(Wordmove::Actions::Ssh::WpcliAdapter::AdaptLocalDb, :pull) | ||
end | ||
|
||
context '.wpcli_config_path' do | ||
context 'when having wp-cli.yml in wordpress root directory' do | ||
it 'returns the path configured in YAML file' do | ||
a_context[:local_options][:wordpress_path] = fixture_folder_root_relative_path | ||
|
||
expect(subject.wpcli_config_path(a_context)).to eq('/path/to/steak') | ||
end | ||
end | ||
|
||
context 'when there is not wp-cli.yml in wordpress root directory' do | ||
context 'if wp-cli is configured someway with a custom path' do | ||
before do | ||
allow(subject) | ||
.to receive(:`) | ||
.with('wp cli param-dump --with-values') | ||
.and_return("{\"path\":{\"current\":\"\/path\/to\/pudding\"}}") | ||
end | ||
|
||
it 'returns the configured path' do | ||
expect(subject.wpcli_config_path(a_context)).to eq('/path/to/pudding') | ||
end | ||
end | ||
end | ||
end | ||
|
||
context '.wpcli_search_replace_command' do | ||
it 'returns the expected command' do | ||
a_context[:local_options][:wordpress_path] = fixture_folder_root_relative_path | ||
expect(subject.wpcli_search_replace_command(a_context, :wordpress_path)) | ||
.to eq('wp search-replace --path=/path/to/steak /var/www/your_site spec/fixtures --quiet '\ | ||
'--skip-columns=guid --all-tables --allow-root') | ||
end | ||
end | ||
end |