wordpress-deploy 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -62,6 +62,52 @@ includes PHP serialized strings).
62
62
  from = WordpressDeploy::Environments.find from.to_sym
63
63
  to = WordpressDeploy::Environments.find to.to_sym
64
64
 
65
+ # Save the correct configuration file
66
+ from.save_wp_config
67
+
68
+ # Send the files in wp_dir
69
+ from.transfer.transmit!
70
+
71
+ # Save the to database locally
72
+ to.database.save!
73
+
74
+ # Send the database to => from
75
+ to.database.send!(from)
76
+
77
+ # Now migrate the database to => from
78
+ to.database.migrate!(from)
79
+
80
+ rescue => err
81
+ Logger.error Errors::Cli::Utility::Error.wrap(err)
82
+
83
+ # Exit with an error
84
+ exit(1)
85
+ end
86
+
87
+ desc "mirror FROM TO", ""
88
+ def mirror(from, to)
89
+ # Set Logger into verbose mode (if the user requested it)
90
+ Logger.verbose = options[:verbose]
91
+
92
+ # Set environment options
93
+ Config.set_options options
94
+
95
+ # Load ALL the available environments
96
+ WordpressDeploy::Environments.load
97
+
98
+ # Get the Environment the user requested
99
+ from = WordpressDeploy::Environments.find from.to_sym
100
+ to = WordpressDeploy::Environments.find to.to_sym
101
+
102
+ # Save the to database locally
103
+ to.database.save!
104
+
105
+ # Send the database to => from
106
+ to.database.send!(from)
107
+
108
+ # Now migrate the database to => from
109
+ to.database.migrate!(from)
110
+
65
111
  rescue => err
66
112
  Logger.error Errors::Cli::Utility::Error.wrap(err)
67
113
 
@@ -19,6 +19,8 @@ module WordpressDeploy
19
19
 
20
20
  @has_port ||= true
21
21
  @has_socket ||= false
22
+
23
+ @base_url ||= @host
22
24
  end
23
25
 
24
26
  ##
@@ -122,6 +124,13 @@ module WordpressDeploy
122
124
  @prefix
123
125
  end
124
126
 
127
+ ##
128
+ #
129
+ def base_url(new_url = nil)
130
+ @base_url = new_url.to_s unless new_url.nil?
131
+ @base_url
132
+ end
133
+
125
134
  ##
126
135
  # The file that the instance would save to if
127
136
  # save is called.
@@ -151,24 +160,25 @@ module WordpressDeploy
151
160
 
152
161
  ##
153
162
  #
154
- def send!(to_config_name)
163
+ def send!(to_env)
164
+ # Get the MySql instance
165
+ to_db = to_env.database
166
+
155
167
  # Check to see if there is a SQL file
156
168
  if File.exists? file
157
- # Create the 'to' configuration
158
- mysql = self.class.new(to_config_name)
159
-
160
169
  # Open the source sql file for reading
161
- tmp_file = Tempfile.new(["#{to_config_name}", '.sql'])
170
+ tmp_file = Tempfile.new(["#{to_db.name}", '.sql'])
162
171
 
163
172
  # Write sql to tmpfile while changing the
164
173
  # the CREATE DATABASE and USE commands to make sense for
165
174
  # the 'to' configuration
166
175
  sql_dump = File.read(file)
167
- sql_dump.gsub!(/^USE\ `#{self.DB_NAME}`/, "USE `#{mysql.DB_NAME}`")
176
+ sql_dump.gsub!(/^CREATE\ DATABASE.*$/i, "")
177
+ sql_dump.gsub!(/^USE\ `#{name}`/, "USE `#{to_db.name}`")
168
178
  tmp_file.puts sql_dump
169
179
 
170
180
  # Get the MySQL load command
171
- cmd = mysqlload to_config_name, tmp_file.path
181
+ cmd = mysqlload to_db, tmp_file.path
172
182
 
173
183
  # Run the mysql command to load the mysqldump into
174
184
  # the destination mysql instance
@@ -181,21 +191,23 @@ module WordpressDeploy
181
191
 
182
192
  ##
183
193
  #
184
- def migrate!(to_config_name)
185
- mysql = self.class.new(to_config_name)
194
+ def migrate!(to_env)
195
+ # Get the MySql instance
196
+ to_db = to_env.database
186
197
 
187
198
  client = Mysql2::Client.new(
188
- :host => mysql.db_hostname,
189
- :username => mysql.DB_USER,
190
- :password => mysql.DB_PASSWORD,
191
- :port => mysql.db_port,
192
- :database => mysql.DB_NAME,
199
+ :host => to_db.host,
200
+ :username => to_db.user,
201
+ :password => to_db.password,
202
+ :port => to_db.port,
203
+ :database => to_db.name,
193
204
  #:socket = '/path/to/mysql.sock',
194
- :encoding => mysql.DB_CHARSET
205
+ :encoding => to_db.charset
195
206
  )
196
207
 
197
- value_to_find = "localhost/~lindsey/huntsvillecrawfishboil.com"
198
- value_to_replace = "huntsvillecrawfishboil.com"
208
+ # MySQL escape
209
+ value_to_find = base_url
210
+ value_to_replace = to_env.base_url
199
211
  escaped_value_to_find = client.escape(value_to_find)
200
212
 
201
213
  # wp_options option_value
@@ -288,13 +300,13 @@ module WordpressDeploy
288
300
  "#{utility("mysqldump")} #{arguments}"
289
301
  end
290
302
 
291
- def mysqlload(config_name, file_name)
303
+ def mysqlload(database, file_name)
292
304
  mysql = self.class.new config_name
293
- arg_port = mysql.db_port
294
- arg_host = mysql.db_hostname
295
- arg_user = mysql.DB_USER
296
- arg_pass = mysql.DB_PASSWORD
297
- arg_name = mysql.DB_NAME
305
+ arg_port = database.port
306
+ arg_host = database.host
307
+ arg_user = database.user
308
+ arg_pass = database.password
309
+ arg_name = database.name
298
310
  arguments = "-P \"#{arg_port}\" -u \"#{arg_user}\" -h \"#{arg_host}\" -p\"#{arg_pass}\" -D \"#{arg_name}\""
299
311
 
300
312
  "#{utility("mysql")} #{arguments} < #{file_name}"
@@ -30,6 +30,7 @@ module WordpressDeploy
30
30
  def database(&block)
31
31
  @database ||= WordpressDeploy::Database::MySql.new
32
32
  @database.instance_eval(&block) if block_given?
33
+ @database.base_url base_url
33
34
  @database
34
35
  end
35
36
 
@@ -1,3 +1,3 @@
1
1
  module WordpressDeploy
2
- VERSION = "1.0.0.rc1"
2
+ VERSION = "1.0.0.rc2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wordpress-deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-19 00:00:00.000000000 Z
12
+ date: 2012-08-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor
@@ -218,7 +218,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
218
218
  version: '0'
219
219
  segments:
220
220
  - 0
221
- hash: 860616845357121422
221
+ hash: 720648579752953508
222
222
  required_rubygems_version: !ruby/object:Gem::Requirement
223
223
  none: false
224
224
  requirements: