Skip to content

Commit

Permalink
Merge pull request #349 from metfan/master
Browse files Browse the repository at this point in the history
add use of flush option in doctrine:clear_* task
  • Loading branch information
willdurand committed Mar 12, 2013
2 parents a70e94d + f9c0865 commit dffab3a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/capifony_symfony2.rb 100644 → 100755
Expand Up @@ -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 }
Expand Down
24 changes: 21 additions & 3 deletions lib/symfony2/doctrine.rb 100644 → 100755
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/capifony_symfony2_doctrine_spec.rb 100644 → 100755
Expand Up @@ -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.