<commit_before>---
- name: Create file with multisite constants defined as false
  copy:
    src: "tmp_multisite_constants.php"
    dest: "{{ deploy_helper.shared_path }}/tmp_multisite_constants.php"

- name: WordPress Installed?
  command: wp core is-installed --skip-plugins --skip-themes --require={{ deploy_helper.shared_path }}/tmp_multisite_constants.php
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  register: wp_installed
  changed_when: false
  failed_when: wp_installed.stderr | default("") != "" or wp_installed.rc > 1

- name: Get WP theme template and stylesheet roots
  shell: >
    {% if not project.multisite.enabled | default(false) %}
      wp option get {{ item }} --skip-plugins --skip-themes
    {% else %}
      wp site list --field=url | xargs -I {} bash -c 'export url="{}"; echo -n "$url " && wp option get {{ item }} --skip-plugins --skip-themes --url=$url || echo'
    {% endif %}
  args:
    chdir: "{{ deploy_helper.current_path }}"
  register: wp_template_root
  changed_when: false<commit_msg>Split is installed check into a non-multisite and a mulitsite specific one.<commit_after>---
# Is installed check
#   Non-multisite specific check
- name: WordPress Installed (non-multisite)?
  command: wp core is-installed --skip-plugins --skip-themes
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  register: wp_installed_single
  changed_when: false
  failed_when: wp_installed_single.stderr | length > 0 or wp_installed_single.rc > 1
  when:
    - not project.multisite.enabled | default(false)

#   Multisite specific check
- name: Create file with multisite constants defined as false
  copy:
    src: "tmp_multisite_constants.php"
    dest: "{{ deploy_helper.shared_path }}/tmp_multisite_constants.php"
  when:
    - project.multisite.enabled | default(false)

- name: Set variables used in "WordPress Installed?" check
  set_fact:
    php_needle_warning: "Warning: strpos\\(\\): Empty needle in {{ deploy_helper.new_release_path }}/web/wp/wp-includes/link-template.php on line 3535"
  when:
    #- project.multisite.enabled | default(false)
    - not project.multisite.enabled | default(false)

- name: WordPress Installed (multisite)?
  command: wp core is-installed --skip-plugins --skip-themes --require={{ deploy_helper.shared_path }}/tmp_multisite_constants.php
  args:
    chdir: "{{ deploy_helper.new_release_path }}"
  register: wp_installed_multisite
  changed_when: false
  failed_when: (wp_installed_multisite.stderr | length > 0 and wp_installed_multisite.stderr is not match(php_needle_warning)) or wp_installed_multisite.rc > 1
  when:
    - project.multisite.enabled | default(false)
#   /Multisite specific check

#   Because variable is always registered, even with non-applying when-condition
- name: Set "WordPress installed (non-multisite)?" result variable
  set_fact:
    wp_installed: "{{ wp_installed_single }}"
  when:
    - not project.multisite.enabled | default(false)

- name: Set "WordPress installed (multisite)?" result variable
  set_fact:
    wp_installed: "{{ wp_installed_multisite }}"
  when:
    - project.multisite.enabled | default(false)
# /Is installed check




- name: Get WP theme template and stylesheet roots
  shell: >
    {% if not project.multisite.enabled | default(false) %}
      wp option get {{ item }} --skip-plugins --skip-themes
    {% else %}
      wp site list --field=url | xargs -I {} bash -c 'export url="{}"; echo -n "$url " && wp option get {{ item }} --skip-plugins --skip-themes --url=$url || echo'
    {% endif %}
  args:
    chdir: "{{ deploy_helper.current_path }}"
  register: wp_template_root
  changed_when: false
{'fraction_non_alphanumeric': 0.12349066959385291, 'fraction_numerical': 0.002469813391877058, 'mean_word_length': 3.7897503285151117, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5511138', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1122, 'n_words': 308}