#!/usr/bin/make

SHELL = /bin/sh

USER_UID := $(shell id -u)
USER_UNAME := $(shell id -un)
USER_GID := $(shell id -g)
USER_GNAME := $(shell id -gn)
DATE_NOW := $(shell date '+%Y-%m-%d_%H%M%S')

export USER_UID
export USER_UNAME
export USER_GID
export USER_GNAME
# export DATE_NOW


pull:
		docker-compose pull

build:
		docker-compose build --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)

buildnc:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME)

buildnc_php_d9:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) php_d9

buildncnginx:
		docker-compose build --no-cache --build-arg USER_UID=$(USER_UID) --build-arg USER_UNAME=$(USER_UNAME) --build-arg USER_GID=$(USER_GID) --build-arg USER_GNAME=$(USER_GNAME) nginx

downbuildup: down build up

up:
		docker-compose up -d

ps:
		docker-compose ps

logs:
		docker-compose logs -f

d9_maj_config: d9_crd d9_composer_install d9_updb d9_cim d9_sync_struct d9_cr d9_pag

d9_crd:
		docker exec popsu-php_d9-1 /bin/bash -c "drush cache-clear drush"

d9_composer_install:
		docker exec popsu-php_d9-1 /bin/bash -c "composer install --no-dev"

d9_updb:
		docker exec popsu-php_d9-1 /bin/bash -c "drush updb -y"

d9_cim:
		docker exec popsu-php_d9-1 /bin/bash -c "drush config-import -y"

d9_sync_struct:
		docker exec popsu-php_d9-1 /bin/bash -c "drush im --choice safe && drush ib --choice full"

d9_cr:
		docker exec popsu-php_d9-1 /bin/bash -c "drush cr"

d9_pag:
		docker exec popsu-php_d9-1 /bin/bash -c "drush pag all canonical_entities:node && drush pag all canonical_entities:taxonomy_term"

d9_restart:
		docker-compose restart php_d9

down:
		docker-compose down

exec_nginx:
		docker exec -it popsu-nginx-1 bash

exec_php_d7:
		docker exec -it popsu-php_d7-1 bash

exec_php_d9:
		docker exec -it popsu-php_d9-1 bash

exec_mysql_d7:
		docker exec -it popsu-mysql_d7-1 bash

exec_mysql_d9:
		docker exec -it popsu-mysql_d9-1 bash

dump_d7_db:
	docker exec popsu-mysql_d7-1 sh -c 'exec mysqldump -uroot -ppopsu popsu-d7' > ./ressources/popsu-d7-$(DATE_NOW)-local.sql

dump_d9_db:
	docker exec popsu-mysql_d9-1 sh -c 'exec mysqldump -uroot -ppopsu popsu_d9' > ./ressources/popsu-d9-$(DATE_NOW)-local.sql