Permalink
Browse files

Implemented :doctrine_em configuration option

* Added :doctrine_em symbol with default value of `false`
* Added `before` hooks for relevant symfony:doctrine:* commands to assemble --em flag
* Added flag variable to commands being run
* Added tests for --em flag in spec file

Fixes everzet/capifony#321
  • Loading branch information...
1 parent c878e14 commit da982a808ecd917a1ebd16edcba452147648bbde @EvanK EvanK committed Jan 22, 2013
Showing with 67 additions and 11 deletions.
  1. +19 −0 lib/capifony_symfony2.rb
  2. +11 −11 lib/symfony2/doctrine.rb
  3. +37 −0 spec/capifony_symfony2_doctrine_spec.rb
View
19 lib/capifony_symfony2.rb
@@ -112,6 +112,9 @@ def self.load_into(configuration)
# Model manager: (doctrine, propel)
set :model_manager, "doctrine"
+ # Doctrine custom entity manager
+ set :doctrine_em, false
+
# Symfony2 version
set(:symfony_version) { guess_symfony_version }
@@ -191,6 +194,22 @@ def write(s)
end
end
+ [
+ "symfony:doctrine:cache:clear_metadata",
+ "symfony:doctrine:cache:clear_query",
+ "symfony:doctrine:cache:clear_result",
+ "symfony:doctrine:schema:create",
+ "symfony:doctrine:schema:drop",
+ "symfony:doctrine:schema:update",
+ "symfony:doctrine:load_fixtures",
+ "symfony:doctrine:migrations:migrate",
+ "symfony:doctrine:migrations:status",
+ ].each do |action|
+ before action do
+ set :doctrine_em_flag, doctrine_em ? " --em=#{doctrine_em}" : ""
+ end
+ end
+
["symfony:composer:install", "symfony:composer:update"].each do |action|
before action do
if copy_vendors
View
22 lib/symfony2/doctrine.rb
@@ -5,23 +5,23 @@
task :clear_metadata, :roles => :app, :except => { :no_release => true } do
capifony_pretty_print "--> Clearing Doctrine metadata cache"
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-metadata --env=#{symfony_env_prod}'"
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-metadata --env=#{symfony_env_prod}#{doctrine_em_flag}'"
capifony_puts_ok
end
desc "Clears all query cache for a entity manager"
task :clear_query, :roles => :app, :except => { :no_release => true } do
capifony_pretty_print "--> Clearing Doctrine query cache"
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-query --env=#{symfony_env_prod}'"
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-query --env=#{symfony_env_prod}#{doctrine_em_flag}'"
capifony_puts_ok
end
desc "Clears result cache for a entity manager"
task :clear_result, :roles => :app, :except => { :no_release => true } do
capifony_pretty_print "--> Clearing Doctrine result cache"
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-result --env=#{symfony_env_prod}'"
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-result --env=#{symfony_env_prod}#{doctrine_em_flag}'"
capifony_puts_ok
end
end
@@ -51,7 +51,7 @@
task :create, :roles => :app, :except => { :no_release => true } do
capifony_pretty_print "--> Creating schema"
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:create --env=#{symfony_env_prod}'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:create --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true
capifony_puts_ok
end
@@ -60,7 +60,7 @@
capifony_pretty_print "--> Droping schema"
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to drop #{symfony_env_prod}'s database schema? (y/N)")
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:drop --force --env=#{symfony_env_prod}'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:drop --force --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true
end
capifony_puts_ok
end
@@ -69,21 +69,21 @@
task :update, :roles => :app, :except => { :no_release => true } do
capifony_pretty_print "--> Updating schema"
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:update --force --env=#{symfony_env_prod}'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:schema:update --force --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true
capifony_puts_ok
end
end
desc "Load data fixtures"
task :load_fixtures, :roles => :app, :except => { :no_release => true } do
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:fixtures:load --env=#{symfony_env_prod}'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:fixtures:load --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true
end
namespace :migrations do
desc "Executes a migration to a specified version or the latest available version"
task :migrate, :roles => :app, :only => { :primary => true }, :except => { :no_release => true } do
currentVersion = nil
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} --no-ansi doctrine:migrations:status --env=#{symfony_env_prod}'", :once => true do |ch, stream, out|
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} --no-ansi doctrine:migrations:status --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true do |ch, stream, out|
if stream == :out and out =~ /Current Version:.+\(([\w]+)\)/
currentVersion = Regexp.last_match(1)
end
@@ -99,18 +99,18 @@
on_rollback {
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database back to version #{currentVersion}? (y/N)")
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate #{currentVersion} --env=#{symfony_env_prod} --no-interaction#{doctrine_em_flag}'", :once => true
end
}
if !interactive_mode || Capistrano::CLI.ui.agree("Do you really want to migrate #{symfony_env_prod}'s database? (y/N)")
- run "#{try_sudo} sh -c ' cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction'", :once => true
+ run "#{try_sudo} sh -c ' cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:migrate --env=#{symfony_env_prod} --no-interaction#{doctrine_em_flag}'", :once => true
end
end
desc "Views the status of a set of migrations"
task :status, :roles => :app, :except => { :no_release => true } do
- run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}'", :once => true
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:migrations:status --env=#{symfony_env_prod}#{doctrine_em_flag}'", :once => true
end
end
View
37 spec/capifony_symfony2_doctrine_spec.rb
@@ -99,6 +99,18 @@
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:schema:update --force --env=prod\'') }
end
+ it "defines symfony:doctrine:load_fixtures task" do
+ @configuration.find_task('symfony:doctrine:load_fixtures').should_not == nil
+ end
+
+ context "when running symfony:doctrine:load_fixtures" do
+ before do
+ @configuration.find_and_execute_task('symfony:doctrine:load_fixtures')
+ end
+
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:fixtures:load --env=prod\'') }
+ end
+
it "defines symfony:doctrine:migrations tasks" do
@configuration.find_task('symfony:doctrine:migrations:migrate').should_not == nil
@configuration.find_task('symfony:doctrine:migrations:status').should_not == nil
@@ -171,4 +183,29 @@
it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console init:acl --env=prod\'') }
end
+
+ context "when running symfony:doctrine:* with custom entity manager" do
+ before do
+ @configuration.set :doctrine_em, 'custom_em'
+
+ @configuration.find_and_execute_task('symfony:doctrine:cache:clear_metadata')
+ @configuration.find_and_execute_task('symfony:doctrine:cache:clear_query')
+ @configuration.find_and_execute_task('symfony:doctrine:cache:clear_result')
+ @configuration.find_and_execute_task('symfony:doctrine:schema:create')
+ @configuration.find_and_execute_task('symfony:doctrine:schema:drop')
+ @configuration.find_and_execute_task('symfony:doctrine:schema:update')
+ @configuration.find_and_execute_task('symfony:doctrine:load_fixtures')
+ @configuration.find_and_execute_task('symfony:doctrine:migrations:status')
+ end
+
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-metadata --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-query --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-result --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:schema:create --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:schema:drop --force --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:schema:update --force --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:fixtures:load --env=prod --em=custom_em\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:migrations:status --env=prod --em=custom_em\'') }
+ end
+
end

0 comments on commit da982a8

Please sign in to comment.