---
- name: Install Composer
  shell: >-
    curl -fsSL https://getcomposer.org/installer
    | php -- --install-dir=/usr/bin --filename=composer
  args:
    warn: false

- name: Clear existing vendor folder
  file:
    path: "{{ www_base }}/vendor"
    state: absent

- name: Recreate vendor folder
  file:
    path: "{{ www_base }}/vendor"
    state: directory
    owner: azuracast
    group: www-data
    mode: 0744

- name: Ensure composer.lock exists
  file:
    path: "{{ www_base }}/composer.lock"
    state: file
    owner: azuracast
    group: www-data
    mode: 0744

- name: Install Composer Dependencies (Development)
  become: true
  become_user: azuracast
  command: >-
    composer install --ignore-platform-req=php
  args:
    chdir: "{{ www_base }}"
  when: app_env == "development"

- name: Install Composer Dependencies (Production)
  become: true
  become_user: azuracast
  command: >-
    composer install --ignore-platform-req=php --no-dev --optimize-autoloader
  args:
    chdir: "{{ www_base }}"
  when: app_env == "production"
