#!/usr/bin/env sh
PATH=/opt/remi/php56/root/usr/bin/:$PATH

if [ -x /usr/local/bin/drush ]; then
    echo "Reactivate corpus module"
    /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal pm-enable -y corpus
    echo "Clear drupal cache"
    /usr/local/bin/drush -r /var/www/corpusdelaparole/drupal cc all
fi

if [ -d /var/www/corpusdelaparole/corpus-back/ ]; then
    pushd /var/www/corpusdelaparole/corpus-back/

    echo "Migrating back office database"
    php artisan migrate

    echo "Optimizing framework"
    php artisan optimize

    echo "Correcting file permissions for back office"
    chgrp -R apache storage bootstrap/cache
    chmod -R ug+rwx storage bootstrap/cache

    popd
fi

echo "Restart httpd"
/usr/bin/systemctl restart httpd
