#!/bin/bash

export PATH=/opt/plesk/php/8.2/bin:$PATH;

cd /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/
sudo git pull

echo "$(tput setab 2)matsen frontend has been PULLED$(tput sgr 0)"

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/composer.lock
#cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/httpdocs/composer.lock /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs
rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/composer.json
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/composer.json /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/config
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/config /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/bin
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/bin /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/migrations
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/migrations /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/src
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/src /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs

rm -rf /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/public/index.php
cp -rf /var/www/vhosts/spawntree.de/git_repo_clones/futbase-fe/public/index.php /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/public

echo "$(tput setab 2)Files have been copied$(tput sgr 0)"

cd /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs
composer update --no-scripts

echo "$(tput setab 2)COMPOSER UPDATED updated$(tput sgr 0)"

php /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/bin/console doctrine:migrations:migrate

echo "$(tput setab 2)DATABASE SCHEMA updated$(tput sgr 0)"

cd /var/www/vhosts/spawntree.de/
sudo chmod 777 matsen.spawntree.de
cd /var/www/vhosts/spawntree.de/matsen.spawntree.de/
sudo chmod 777 -R *

cd /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/var/cache/
rm -R *

php /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/bin/console cache:clear
php /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/bin/console cache:warmup

echo "$(tput setab 2)CACHE HAS BEEN CLEARED$(tput sgr 0)"

cd /var/www/vhosts/spawntree.de/matsen.spawntree.de/httpdocs/var/
chmod 777 -R *
chmod 777 cache/ *
chmod 777 cache/

#service apache2 restart

#echo "$(tput setab 2)CACHE cleared$(tput sgr 0)"

echo "$(tput setab 7)$(tput setaf 1)THINK ABOUT POSSIBLE PATCHES!"

echo "You have updated matsen api!$(tput sgr 0)"
