capifony 0.4.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/CHANGELOG +6 -0
  2. data/bin/capifony +47 -12
  3. data/lib/capifony.rb +3 -565
  4. data/lib/symfony1.rb +569 -0
  5. data/lib/symfony2.rb +215 -0
  6. metadata +11 -9
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ == 2.0.0 / March 22, 2011
2
+
3
+ * optimized shared commands in symfony1 scripts
4
+ * added symfony2 deployment strategy
5
+ * added `use_orm` option to symfony1 recipes. Turn it off if you don't use ORM
6
+
1
7
  == 0.4.2 / September 23, 2010
2
8
 
3
9
  * added `symfony:doctrine:compile` task
@@ -3,6 +3,8 @@
3
3
  require 'optparse'
4
4
  require 'fileutils'
5
5
 
6
+ symfony_version_option = nil
7
+
6
8
  OptionParser.new do |opts|
7
9
  opts.banner = "Usage: #{File.basename($0)} [path]"
8
10
 
@@ -11,6 +13,10 @@ OptionParser.new do |opts|
11
13
  exit 0
12
14
  end
13
15
 
16
+ opts.on("-s", "--symfony VERSION", "Capify specific symfony verion (1|2)") do |version|
17
+ symfony_version_option = version.to_i
18
+ end
19
+
14
20
  begin
15
21
  opts.parse!(ARGV)
16
22
  rescue OptionParser::ParseError => e
@@ -27,7 +33,7 @@ elsif !File.exists?(ARGV.first)
27
33
  elsif !File.directory?(ARGV.first)
28
34
  abort "`#{ARGV.first}' is not a directory."
29
35
  elsif ARGV.length > 1
30
- abort "Too many arguments; please specify only the directory to capifony."
36
+ abort "Too many arguments; please specify only the directory to capify."
31
37
  end
32
38
 
33
39
  def unindent(string)
@@ -35,15 +41,20 @@ def unindent(string)
35
41
  string.strip.gsub(/^#{indentation}/, "")
36
42
  end
37
43
 
38
- files = {
39
- "Capfile" => unindent(<<-FILE),
40
- load 'deploy' if respond_to?(:namespace) # cap2 differentiator
41
- Dir['plugins/*/lib/recipes/*.rb'].each { |plugin| load(plugin) }
42
- load Gem.required_location('capifony', 'capifony.rb')
43
- load 'config/deploy' # remove this line to skip loading any of the default tasks
44
- FILE
44
+ base = ARGV.shift
45
+ symfony_version = (File.directory? File.join(base, 'config')) ? 1 : 2
46
+ symfony_version = symfony_version_option == nil ? symfony_version : symfony_version_option
47
+
48
+ if symfony_version == 2
49
+ files = {
50
+ "Capfile" => unindent(<<-FILE),
51
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
52
+ Dir['vendor/bundles/*/*/recipes/*.rb'].each { |bundle| load(bundle) }
53
+ load Gem.required_location('capifony', 'symfony2.rb')
54
+ load 'app/config/deploy'
55
+ FILE
45
56
 
46
- "config/deploy.rb" => 'set :application, "set your application name here"
57
+ "app/config/deploy.rb" => 'set :application, "set your application name here"
47
58
  set :domain, "#{application}.com"
48
59
  set :deploy_to, "/var/www/#{domain}"
49
60
 
@@ -55,9 +66,33 @@ role :web, domain # Your HTTP server, Apache/etc
55
66
  role :app, domain # This may be the same as your `Web` server
56
67
  role :db, domain, :primary => true # This is where Rails migrations will run
57
68
 
58
- set :keep_releases, 3'}
69
+ set :keep_releases, 3'
70
+ }
71
+ else
72
+ files = {
73
+ "Capfile" => unindent(<<-FILE),
74
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
75
+ Dir['plugins/*/lib/recipes/*.rb'].each { |plugin| load(plugin) }
76
+ load Gem.required_location('capifony', 'symfony1.rb')
77
+ load 'config/deploy'
78
+ FILE
79
+
80
+ "config/deploy.rb" => 'set :application, "set your application name here"
81
+ set :domain, "#{application}.com"
82
+ set :deploy_to, "/var/www/#{domain}"
83
+
84
+ set :repository, "#{domain}:/var/repos/#{application}.git"
85
+ set :scm, :git
86
+ # Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, `subversion` or `none`
87
+
88
+ role :web, domain # Your HTTP server, Apache/etc
89
+ role :app, domain # This may be the same as your `Web` server
90
+ role :db, domain, :primary => true # This is where Rails migrations will run
91
+
92
+ set :keep_releases, 3'
93
+ }
94
+ end
59
95
 
60
- base = ARGV.shift
61
96
  files.each do |file, content|
62
97
  file = File.join(base, file)
63
98
  if File.exists?(file)
@@ -74,4 +109,4 @@ files.each do |file, content|
74
109
  end
75
110
  end
76
111
 
77
- puts "[done] capifonied!"
112
+ puts "[done] Symfony#{symfony_version.to_s} project capifonied!"
@@ -1,28 +1,11 @@
1
- require 'yaml'
2
-
3
- # Dirs that need to remain the same between deploys (shared dirs)
4
- set :shared_children, %w(log web/uploads)
5
-
6
- # Files that need to remain the same between deploys
7
- set :shared_files, %w(config/databases.yml)
8
-
9
- # Asset folders (that need to be timestamped)
10
- set :asset_children, %w(web/css web/images web/js)
11
-
12
- # PHP binary to execute
13
- set :php_bin, "php"
14
-
15
1
  # Symfony environment on local
16
2
  set :symfony_env_local, "dev"
17
3
 
18
4
  # Symfony environment
19
- set :symfony_env, "prod"
5
+ set :symfony_env_prod, "prod"
20
6
 
21
- # Symfony default ORM
22
- set(:symfony_orm) { guess_symfony_orm }
23
-
24
- # Symfony lib path
25
- set(:symfony_lib) { guess_symfony_lib }
7
+ # PHP binary to execute
8
+ set :php_bin, "php"
26
9
 
27
10
  def prompt_with_default(var, default, &block)
28
11
  set(var) do
@@ -31,39 +14,6 @@ def prompt_with_default(var, default, &block)
31
14
  set var, default if eval("#{var.to_s}.empty?")
32
15
  end
33
16
 
34
- def guess_symfony_orm
35
- databases = YAML::load(IO.read('config/databases.yml'))
36
-
37
- if databases[symfony_env_local]
38
- databases[symfony_env_local].keys[0].to_s
39
- else
40
- databases['all'].keys[0].to_s
41
- end
42
- end
43
-
44
- def guess_symfony_lib
45
- symfony_version = capture("#{php_bin} #{latest_release}/symfony -V")
46
-
47
- /\((.*)\)/.match(symfony_version)[1]
48
- end
49
-
50
- def load_database_config(data, env)
51
- databases = YAML::load(data)
52
-
53
- if databases[env]
54
- db_param = databases[env][symfony_orm]['param']
55
- else
56
- db_param = databases['all'][symfony_orm]['param']
57
- end
58
-
59
- {
60
- 'type' => /(\w+)\:/.match(db_param['dsn'])[1],
61
- 'user' => db_param['username'],
62
- 'pass' => db_param['password'],
63
- 'db' => /dbname=([^;$]+)/.match(db_param['dsn'])[1]
64
- }
65
- end
66
-
67
17
  namespace :deploy do
68
18
  desc "Overwrite the start task because symfony doesn't need it."
69
19
  task :start do ; end
@@ -73,516 +23,4 @@ namespace :deploy do
73
23
 
74
24
  desc "Overwrite the stop task because symfony doesn't need it."
75
25
  task :stop do ; end
76
-
77
- desc "Customize migrate task because symfony doesn't need it."
78
- task :migrate do
79
- symfony.orm.migrate
80
- end
81
-
82
- desc "Symlink static directories and static files that need to remain between deployments."
83
- task :share_childs do
84
- if shared_children
85
- shared_children.each do |link|
86
- run "mkdir -p #{shared_path}/#{link}"
87
- run "if [ -d #{release_path}/#{link} ] ; then rm -rf #{release_path}/#{link}; fi"
88
- run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
89
- end
90
- end
91
- if shared_files
92
- shared_files.each do |link|
93
- link_dir = File.dirname("#{shared_path}/#{link}")
94
- run "mkdir -p #{link_dir}"
95
- run "touch #{shared_path}/#{link}"
96
- run "ln -nfs #{shared_path}/#{link} #{release_path}/#{link}"
97
- end
98
- end
99
- end
100
-
101
- desc "Customize the finalize_update task to work with symfony."
102
- task :finalize_update, :except => { :no_release => true } do
103
- run "chmod -R g+w #{latest_release}" if fetch(:group_writable, true)
104
- run "mkdir -p #{latest_release}/cache"
105
-
106
- # Share common files & folders
107
- share_childs
108
-
109
- if fetch(:normalize_asset_timestamps, true)
110
- stamp = Time.now.utc.strftime("%Y%m%d%H%M.%S")
111
- asset_paths = asset_children.map { |p| "#{latest_release}/#{p}" }.join(" ")
112
- run "find #{asset_paths} -exec touch -t #{stamp} {} ';'; true", :env => { "TZ" => "UTC" }
113
- end
114
- end
115
-
116
- desc "Need to overwrite the deploy:cold task so it doesn't try to run the migrations."
117
- task :cold do
118
- update
119
- symfony.orm.build_db_and_load
120
- start
121
- end
122
-
123
- desc "Deploy the application and run the test suite."
124
- task :testall do
125
- update_code
126
- symlink
127
- symfony.orm.build_db_and_load
128
- symfony.tests.all
129
- end
130
- end
131
-
132
- namespace :symfony do
133
- desc "Runs custom symfony task"
134
- task :default do
135
- prompt_with_default(:task_arguments, "cache:clear")
136
-
137
- stream "#{php_bin} #{latest_release}/symfony #{task_arguments}"
138
- end
139
-
140
- desc "Downloads & runs check_configuration.php on remote"
141
- task :check_configuration do
142
- prompt_with_default(:version, "1.4")
143
-
144
- run "wget http://sf-to.org/#{version}/check.php -O /tmp/check_configuration.php"
145
- stream "#{php_bin} /tmp/check_configuration.php"
146
- run "rm /tmp/check_configuration.php"
147
- end
148
-
149
- desc "Clears the cache"
150
- task :cc do
151
- run "#{php_bin} #{latest_release}/symfony cache:clear"
152
- end
153
-
154
- namespace :configure do
155
- desc "Configure database DSN"
156
- task :database do
157
- prompt_with_default(:dsn, "mysql:host=localhost;dbname=#{application}")
158
- prompt_with_default(:db_username, "root")
159
- db_password = Capistrano::CLI.password_prompt("db_password : ")
160
-
161
- # surpress debug log output to hide the password
162
- current_logger_level = self.logger.level
163
- if current_logger_level >= Capistrano::Logger::DEBUG
164
- logger.debug %(executing "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' ***")
165
- self.logger.level = Capistrano::Logger::INFO
166
- end
167
-
168
- run "#{php_bin} #{latest_release}/symfony configure:database '#{dsn}' '#{db_username}' '#{db_password}'"
169
-
170
- # restore logger level
171
- self.logger.level = current_logger_level
172
- end
173
- end
174
-
175
- namespace :project do
176
- desc "Disables an application in a given environment"
177
- task :disable do
178
- run "#{php_bin} #{latest_release}/symfony project:disable #{symfony_env}"
179
- end
180
-
181
- desc "Enables an application in a given environment"
182
- task :enable do
183
- run "#{php_bin} #{latest_release}/symfony project:enable #{symfony_env}"
184
- end
185
-
186
- desc "Fixes symfony directory permissions"
187
- task :permissions do
188
- run "#{php_bin} #{latest_release}/symfony project:permissions"
189
- end
190
-
191
- desc "Optimizes a project for better performance"
192
- task :optimize do
193
- prompt_with_default(:application, "frontend")
194
-
195
- run "#{php_bin} #{latest_release}/symfony project:optimize #{application}"
196
- end
197
-
198
- desc "Clears all non production environment controllers"
199
- task :clear_controllers do
200
- run "#{php_bin} #{latest_release}/symfony project:clear-controllers"
201
- end
202
-
203
- desc "Sends emails stored in a queue"
204
- task :send_emails do
205
- prompt_with_default(:message_limit, 10)
206
- prompt_with_default(:time_limit, 10)
207
-
208
- stream "#{php_bin} #{latest_release}/symfony project:send-emails --message-limit=#{message_limit} --time-limit=#{time_limit} --env=#{symfony_env}"
209
- end
210
-
211
- desc 'Task to set all front controllers to a specific environment'
212
- task :set_environment do
213
- if (env = fetch(:symfony_env, nil)) && env != 'prod'
214
- cmd = []
215
- apps = fetch(:symfony_apps, ['frontend'])
216
-
217
- # First application listed becomes index.php
218
- if app = apps.shift
219
- cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/index.php"
220
- end
221
-
222
- # All other apps are copied to their default controllers
223
- for app in apps
224
- cmd << "cp #{release_path}/web/#{app}_#{env}.php #{release_path}/web/#{app}.php"
225
- end
226
-
227
- run cmd.join(';') if cmd.join(';')
228
- end
229
- end
230
- end
231
-
232
- namespace :plugin do
233
- desc "Publishes web assets for all plugins"
234
- task :publish_assets do
235
- run "#{php_bin} #{latest_release}/symfony plugin:publish-assets"
236
- end
237
- end
238
-
239
- namespace :log do
240
- desc "Clears log files"
241
- task :clear do
242
- run "#{php_bin} #{latest_release}/symfony log:clear"
243
- end
244
-
245
- desc "Rotates an application's log files"
246
- task :rotate do
247
- prompt_with_default(:application, "frontend")
248
-
249
- run "#{php_bin} #{latest_release}/symfony log:rotate #{application} #{symfony_env}"
250
- end
251
- end
252
-
253
- namespace :tests do
254
- desc "Launches all tests"
255
- task :all do
256
- run "#{php_bin} #{latest_release}/symfony test:all"
257
- end
258
-
259
- desc "Launches functional tests"
260
- task :functional do
261
- prompt_with_default(:application, "frontend")
262
-
263
- run "#{php_bin} #{latest_release}/symfony test:functional #{application}"
264
- end
265
-
266
- desc "Launches unit tests"
267
- task :unit do
268
- run "#{php_bin} #{latest_release}/symfony test:unit"
269
- end
270
- end
271
-
272
- namespace :orm do
273
- desc "Ensure symfony ORM is properly configured"
274
- task :setup do
275
- find_and_execute_task("symfony:#{symfony_orm}:setup")
276
- end
277
-
278
- desc "Migrates database to current version"
279
- task :migrate do
280
- find_and_execute_task("symfony:#{symfony_orm}:migrate")
281
- end
282
-
283
- desc "Generate model lib form and filters classes based on your schema"
284
- task :build_classes do
285
- find_and_execute_task("symfony:#{symfony_orm}:build_classes")
286
- end
287
-
288
- desc "Generate code & database based on your schema"
289
- task :build_all do
290
- find_and_execute_task("symfony:#{symfony_orm}:build_all")
291
- end
292
-
293
- desc "Generate code & database based on your schema & load fixtures"
294
- task :build_all_and_load do
295
- find_and_execute_task("symfony:#{symfony_orm}:build_all_and_load")
296
- end
297
-
298
- desc "Generate sql & database based on your schema"
299
- task :build_db do
300
- find_and_execute_task("symfony:#{symfony_orm}:build_db")
301
- end
302
-
303
- desc "Generate sql & database based on your schema & load fixtures"
304
- task :build_db_and_load do
305
- find_and_execute_task("symfony:#{symfony_orm}:build_db_and_load")
306
- end
307
- end
308
-
309
- namespace :doctrine do
310
- desc "Compile doctrine"
311
- task :compile do
312
- run "#{php_bin} #{latest_release}/symfony doctrine:compile"
313
- end
314
-
315
- desc "Ensure Doctrine is correctly configured"
316
- task :setup do
317
- conf_files_exists = capture("if test -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
318
- if (!conf_files_exists.eql?("exists"))
319
- symfony.configure.database
320
- end
321
- end
322
-
323
- desc "Execute a DQL query and view the results"
324
- task :dql do
325
- prompt_with_default(:query, "")
326
-
327
- stream "#{php_bin} #{latest_release}/symfony doctrine:dql #{query} --env=#{symfony_env}"
328
- end
329
-
330
- desc "Dumps data to the fixtures directory"
331
- task :data_dump do
332
- run "#{php_bin} #{latest_release}/symfony doctrine:data-dump --env=#{symfony_env}"
333
- end
334
-
335
- desc "Loads YAML fixture data"
336
- task :data_load do
337
- run "#{php_bin} #{latest_release}/symfony doctrine:data-load --env=#{symfony_env}"
338
- end
339
-
340
- desc "Loads YAML fixture data without remove"
341
- task :data_load_append do
342
- run "#{php_bin} #{latest_release}/symfony doctrine:data-load --append --env=#{symfony_env}"
343
- end
344
-
345
- desc "Migrates database to current version"
346
- task :migrate do
347
- run "#{php_bin} #{latest_release}/symfony doctrine:migrate --env=#{symfony_env}"
348
- end
349
-
350
- desc "Generate model lib form and filters classes based on your schema"
351
- task :build_classes do
352
- run "#{php_bin} #{latest_release}/symfony doctrine:build --all-classes --env=#{symfony_env}"
353
- end
354
-
355
- desc "Generate code & database based on your schema"
356
- task :build_all do
357
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
358
- run "#{php_bin} #{latest_release}/symfony doctrine:build --all --no-confirmation --env=#{symfony_env}"
359
- end
360
- end
361
-
362
- desc "Generate code & database based on your schema & load fixtures"
363
- task :build_all_and_load do
364
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
365
- run "#{php_bin} #{latest_release}/symfony doctrine:build --all --and-load --no-confirmation --env=#{symfony_env}"
366
- end
367
- end
368
-
369
- desc "Generate sql & database based on your schema"
370
- task :build_db do
371
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
372
- run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --no-confirmation --env=#{symfony_env}"
373
- end
374
- end
375
-
376
- desc "Generate sql & database based on your schema & load fixtures"
377
- task :build_db_and_load do
378
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
379
- run "#{php_bin} #{latest_release}/symfony doctrine:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
380
- end
381
- end
382
- end
383
-
384
- namespace :propel do
385
- desc "Ensure Propel is correctly configured"
386
- task :setup do
387
- conf_files_exists = capture("if test -s #{shared_path}/config/propel.ini -a -s #{shared_path}/config/databases.yml ; then echo 'exists' ; fi").strip
388
-
389
- # share childs again (for propel.ini file)
390
- shared_files << "config/propel.ini"
391
- deploy.share_childs
392
-
393
- if (!conf_files_exists.eql?("exists"))
394
- run "cp #{symfony_lib}/plugins/sfPropelPlugin/config/skeleton/config/propel.ini #{shared_path}/config/propel.ini"
395
- symfony.configure.database
396
- end
397
- end
398
-
399
- desc "Migrates database to current version"
400
- task :migrate do
401
- puts "propel doesn't have built-in migration for now"
402
- end
403
-
404
- desc "Generate model lib form and filters classes based on your schema"
405
- task :build_classes do
406
- run "php #{latest_release}/symfony propel:build --all-classes --env=#{symfony_env}"
407
- end
408
-
409
- desc "Generate code & database based on your schema"
410
- task :build_all do
411
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
412
- run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --no-confirmation --env=#{symfony_env}"
413
- end
414
- end
415
-
416
- desc "Generate code & database based on your schema & load fixtures"
417
- task :build_all_and_load do
418
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
419
- run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
420
- end
421
- end
422
-
423
- desc "Generate sql & database based on your schema"
424
- task :build_db do
425
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database? (y/N)")
426
- run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --no-confirmation --env=#{symfony_env}"
427
- end
428
- end
429
-
430
- desc "Generate sql & database based on your schema & load fixtures"
431
- task :build_db_and_load do
432
- if Capistrano::CLI.ui.agree("Do you really want to rebuild #{symfony_env}'s database and load #{symfony_env}'s fixtures? (y/N)")
433
- run "#{php_bin} #{latest_release}/symfony propel:build --sql --db --and-load --no-confirmation --env=#{symfony_env}"
434
- end
435
- end
436
- end
437
- end
438
-
439
- namespace :database do
440
- namespace :dump do
441
- desc "Dump remote database"
442
- task :remote do
443
- filename = "#{application}.remote_dump.#{Time.now.to_i}.sql.bz2"
444
- file = "/tmp/#{filename}"
445
- sqlfile = "#{application}_dump.sql"
446
- config = ""
447
-
448
- run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
449
- config = load_database_config data, symfony_env
450
- end
451
-
452
- case config['type']
453
- when 'mysql'
454
- run "mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
455
- puts data
456
- end
457
- when 'pgsql'
458
- run "pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}" do |ch, stream, data|
459
- puts data
460
- end
461
- end
462
-
463
- `mkdir -p backups`
464
- get file, "backups/#{filename}"
465
- `cd backups && ln -nfs #{filename} #{application}.remote_dump.latest.sql.bz2`
466
- run "rm #{file}"
467
- end
468
-
469
- desc "Dump local database"
470
- task :local do
471
- filename = "#{application}.local_dump.#{Time.now.to_i}.sql.bz2"
472
- file = "backups/#{filename}"
473
- config = load_database_config IO.read('config/databases.yml'), symfony_env_local
474
- sqlfile = "#{application}_dump.sql"
475
-
476
- `mkdir -p backups`
477
- case config['type']
478
- when 'mysql'
479
- `mysqldump -u#{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
480
- when 'pgsql'
481
- `pg_dump -U #{config['user']} --password='#{config['pass']}' #{config['db']} | bzip2 -c > #{file}`
482
- end
483
-
484
- `cd backups && ln -nfs #{filename} #{application}.local_dump.latest.sql.bz2`
485
- end
486
- end
487
-
488
- namespace :move do
489
- desc "Dump remote database, download it to local & populate here"
490
- task :to_local do
491
- filename = "#{application}.remote_dump.latest.sql.bz2"
492
- config = load_database_config IO.read('config/databases.yml'), symfony_env_local
493
- sqlfile = "#{application}_dump.sql"
494
-
495
- database.dump.remote
496
-
497
- `bunzip2 -kc backups/#{filename} > backups/#{sqlfile}`
498
- case config['type']
499
- when 'mysql'
500
- `mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
501
- when 'pgsql'
502
- `psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < backups/#{sqlfile}`
503
- end
504
- `rm backups/#{sqlfile}`
505
- end
506
-
507
- desc "Dump local database, load it to remote & populate there"
508
- task :to_remote do
509
- filename = "#{application}.local_dump.latest.sql.bz2"
510
- file = "backups/#{filename}"
511
- sqlfile = "#{application}_dump.sql"
512
- config = ""
513
-
514
- database.dump.local
515
-
516
- upload(file, "/tmp/#{filename}", :via => :scp)
517
- run "bunzip2 -kc /tmp/#{filename} > /tmp/#{sqlfile}"
518
-
519
- run "cat #{shared_path}/config/databases.yml" do |ch, st, data|
520
- config = load_database_config data, symfony_env
521
- end
522
-
523
- case config['type']
524
- when 'mysql'
525
- run "mysql -u#{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
526
- puts data
527
- end
528
- when 'pgsql'
529
- run "psql -U #{config['user']} --password='#{config['pass']}' #{config['db']} < /tmp/#{sqlfile}" do |ch, stream, data|
530
- puts data
531
- end
532
- end
533
-
534
- run "rm /tmp/#{filename}"
535
- run "rm /tmp/#{sqlfile}"
536
- end
537
- end
538
- end
539
-
540
- namespace :shared do
541
- namespace :databases do
542
- desc "Download config/databases.yml from remote server"
543
- task :to_local do
544
- download("#{shared_path}/config/databases.yml", "config/databases.yml", :via => :scp)
545
- end
546
-
547
- desc "Upload config/databases.yml to remote server"
548
- task :to_remote do
549
- upload("config/databases.yml", "#{shared_path}/config/databases.yml", :via => :scp)
550
- end
551
- end
552
-
553
- namespace :log do
554
- desc "Download all logs from remote folder to local one"
555
- task :to_local do
556
- download("#{shared_path}/log", "./", :via => :scp, :recursive => true)
557
- end
558
-
559
- desc "Upload all logs from local folder to remote one"
560
- task :to_remote do
561
- upload("log", "#{shared_path}/", :via => :scp, :recursive => true)
562
- end
563
- end
564
-
565
- namespace :uploads do
566
- desc "Download all files from remote web/uploads folder to local one"
567
- task :to_local do
568
- download("#{shared_path}/web/uploads", "web", :via => :scp, :recursive => true)
569
- end
570
-
571
- desc "Upload all files from local web/uploads folder to remote one"
572
- task :to_remote do
573
- upload("web/uploads", "#{shared_path}/web", :via => :scp, :recursive => true)
574
- end
575
- end
576
- end
577
-
578
- # After finalizing update:
579
- after "deploy:finalize_update" do
580
- symfony.orm.setup # 0. Ensure that ORM is configured
581
- symfony.orm.build_classes # 1. (Re)build the model
582
- symfony.cc # 2. Clear cache
583
- symfony.plugin.publish_assets # 3. Publish plugin assets
584
- symfony.project.permissions # 4. Fix project permissions
585
- if symfony_env.eql?("prod")
586
- symfony.project.clear_controllers # 5. Clear controllers in production environment
587
- end
588
26
  end