Class: Wordmove::Hook::Remote

Inherits:
Object
  • Object
show all
Defined in:
lib/wordmove/hook.rb

Class Method Summary collapse

Class Method Details

.loggerObject



92
93
94
# File 'lib/wordmove/hook.rb', line 92

def self.logger
  parent.logger
end

.run(commands, options, simulate = false) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/wordmove/hook.rb', line 96

def self.run(commands, options, simulate = false)
  logger.task "Running remote hooks"

  ssh_options = options[:ssh]
  wordpress_path = options[:wordpress_path]

  copier = Photocopier::SSH.new(ssh_options).tap { |c| c.logger = logger }
  commands.each do |command|
    logger.task_step false, "Exec command: #{command}"
    return true if simulate

    stdout, stderr, exit_code =
      copier.exec!("cd #{wordpress_path} && #{command}")

    if exit_code.zero?
      logger.task_step false, "Output: #{stdout}"
      logger.success ""
    else
      logger.task_step false, "Output: #{stderr}"
      logger.error "Error code #{exit_code}"
      raise Wordmove::RemoteHookException
    end
  end
end