Permalink
Browse files

Merge pull request #349 from metfan/master

add use of flush option in doctrine:clear_* task
  • Loading branch information...
2 parents a70e94d + f9c0865 commit dffab3aa48a69b3b78d1d485c3f31a469b70dc7c @willdurand willdurand committed Mar 12, 2013
Showing with 38 additions and 3 deletions.
  1. +3 −0 lib/capifony_symfony2.rb
  2. +21 −3 lib/symfony2/doctrine.rb
  3. +14 −0 spec/capifony_symfony2_doctrine_spec.rb
View
3 lib/capifony_symfony2.rb 100644 → 100755
@@ -114,6 +114,9 @@ def self.load_into(configuration)
# Doctrine custom entity manager
set :doctrine_em, false
+
+ # Use --flush option in doctrine:clear_* task
+ set :doctrine_clear_use_flush_option, false
# Symfony2 version
set(:symfony_version) { guess_symfony_version }
View
24 lib/symfony2/doctrine.rb 100644 → 100755
@@ -5,23 +5,41 @@
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}#{doctrine_em_flag}'"
+ if doctrine_clear_use_flush_option
+ flush_option = " --flush"
+ else
+ flush_option = ""
+ end
+
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-metadata --env=#{symfony_env_prod}#{doctrine_em_flag}#{flush_option}'"
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}#{doctrine_em_flag}'"
+ if doctrine_clear_use_flush_option
+ flush_option = " --flush"
+ else
+ flush_option = ""
+ end
+
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-query --env=#{symfony_env_prod}#{doctrine_em_flag}#{flush_option}'"
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}#{doctrine_em_flag}'"
+ if doctrine_clear_use_flush_option
+ flush_option = " --flush"
+ else
+ flush_option = ""
+ end
+
+ run "#{try_sudo} sh -c 'cd #{latest_release} && #{php_bin} #{symfony_console} doctrine:cache:clear-result --env=#{symfony_env_prod}#{doctrine_em_flag}#{flush_option}'"
capifony_puts_ok
end
end
View
@@ -207,5 +207,19 @@
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
+
+ context "when running symfony:doctrine:clear_* with flush option" do
+ before do
+ @configuration.set :doctrine_clear_use_flush_option, true
+
+ @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')
+ end
+
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-metadata --env=prod --flush\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-query --env=prod --flush\'') }
+ it { should have_run(' sh -c \'cd /var/www/releases/20120927 && php app/console doctrine:cache:clear-result --env=prod --flush\'') }
+ end
end

0 comments on commit dffab3a

Please sign in to comment.