---
# file: roles/php/tasks/php.yml

- name: "PHP | Install required packages."
  apt:
    pkg={{ item }}
    state=installed
  with_items:
    - php5
    - php-apc
    - php-soap
    - php5-mysql
    - php5-xmlrpc
    - php5-gd
    - php5-mcrypt
    - php5-imap
    - php5-curl
    - php5-xdebug
    - php5-dev
    - php-pear
  notify:
    - "PHP | Restart Apache"

# TODO: Upgrade APCu on Ubuntu 14.04
# @see https://github.com/owncloud/core/issues/14175#issuecomment-74573088
# wget https://launchpad.net/~ondrej/+archive/ubuntu/php5/+build/6149263/+files/php5-apcu_4.0.6-1%2Bdeb.sury.org~utopic%2B1_amd64.deb
# sudo dpkg -i php5-apcu_4.0.6-1+deb.sury.org~utopic+1_amd64.deb

- name: "PHP | Configuration file, php.ini"
  template:
    src=etc-php5-apache2-php.ini
    dest=/etc/php5/apache2/php.ini
    owner=root
    group=root
    mode=0644
  notify:
    - "PHP | Restart Apache"

- name: "PHP | Cache configuration file, apc.ini"
  template:
    src=etc-php5-conf-d-apc.ini
    dest=/etc/php5/{{ php_conf_dir }}/apc.ini
    owner=root
    group=root
    mode=0644
  notify:
    - "PHP | Restart Apache"

- name: "PHP | Create extra directory for browscap"
  file:
    dest=/etc/php5/apache2/extra
    state=directory
    owner=root
    group=root
  when: php_browscap

- name: "PHP | browscap.ini"
  copy:
    src=browscap.ini
    dest=/etc/php5/apache2/extra/browscap.ini
    owner=root
    group=root
  when: php_browscap
  notify:
    - "PHP | Restart Apache"

- name: "PHP | Enable PHP modules"
  shell: php5enmod {{ item }}
  with_items:
    - mcrypt
    - imap
  when: php_conf_dir == 'mods-available'
  notify:
    - "PHP | Restart Apache"

- name: "PHP | Create htdocs directory for apc status"
  file:
    dest=/var/www/apc
    state=directory
    owner=www-data
    group=www-data

- name: "PHP | Copy APC status php script"
  copy:
    src=apc.php
    dest=/var/www/apc
    owner=www-data
    group=www-data

- name: "PHP | Check OCI Requirement"
  shell: ls /usr/lib/php5/20090626/pdo_oci.so
  register: oci_available
  when: php_needs_oci8
  ignore_errors: yes
  changed_when: oci_available.stdout != '/usr/lib/php5/20090626/pdo_oci.so'
  notify:
    - "PHP | Restart Apache"

- include: oci.yml
  when: repository is defined and php_needs_oci8 and oci_available.stdout != '/usr/lib/php5/20090626/pdo_oci.so'
