---
- name: WordPress Installed?
  command: wp core is-installed {{ project.multisite.enabled | default(false) | ternary('--network', '') }}
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  register: wp_installed
  changed_when: false
  failed_when: wp_installed.stderr != ""

- name: Update WP theme paths
  command: wp eval 'wp_clean_themes_cache(); switch_theme(get_stylesheet());'
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  when: wp_installed | success

- name: Update WP database
  command: wp core update-db
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  when: wp_installed | success and not project.multisite.enabled | default(false)

- name: Warn about updating network database.
  debug:
    msg: "Updating the network database could take a long time with a large number of sites."
  when: wp_installed | success and project.multisite.enabled | default(false)

- name: Update WP network database
  command: wp core update-db --network
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  when: wp_installed | success and project.multisite.enabled | default(false)

- name: Reload php-fpm
  shell: sudo service php7.1-fpm reload
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
    warn: false

---
- name: WordPress Installed?
  command: wp core is-installed {{ project.multisite.enabled | default(false) | ternary('--network', '') }}
  args:
    chdir: "{{ deploy_helper.current_path }}"
  register: wp_installed
  changed_when: false
  failed_when: wp_installed.stderr != ""

- name: Update WP database
  command: wp core update-db
  args:
    chdir: "{{ deploy_helper.current_path }}"
  when: wp_installed | success and not project.multisite.enabled | default(false)

- name: Warn about updating network database.
  debug:
    msg: "Updating the network database could take a long time with a large number of sites."
  when: wp_installed | success and project.multisite.enabled | default(false)

- name: Update WP network database
  command: wp core update-db --network
  args:
    chdir: "{{ deploy_helper.current_path }}"
  when: wp_installed | success and project.multisite.enabled | default(false)

- name: Update WP theme paths
  command: wp eval 'wp_clean_themes_cache(); switch_theme(get_stylesheet());'
  args:
    chdir: "{{ deploy_helper.current_path }}"
  when: wp_installed | success

- name: Reload php-fpm
  shell: sudo service php7.1-fpm reload
  args:
    warn: false

Update finalize after hooks with better paths
Update finalize after hooks with better paths

`new_release_path` was being used but at this point the symlink has
already been created and the deploy finalized so we should use
`current_path`.

This also moves the themes path update task after DB updates.
