#!/usr/bin/env php

<?php

print "Updating packages and compiling assets".PHP_EOL;
shell_exec("COMPOSE_ALLOW_SUPERUSER=1 composer update");
//`symfony console asset-map:compile");

print "Creating database schema".PHP_EOL;
shell_exec("symfony console doctrine:database:create --if-not-exists");

print "Updating migrations and setting permissions for data folder".PHP_EOL;
shell_exec("symfony console doctrine:schema:create");

shell_exec("chown -R www-data:www-data /data /var/www/html/var/cache");

// import reference material

print "Importing Bible and Eccumenical Creeds".PHP_EOL;
shell_exec("symfony console app:import-bible /var/www/html/references/esv-bible");
shell_exec("symfony console app:import-ref /var/www/html/references/creeds/Apostles 'Apostles Creed' creed apc");
shell_exec("symfony console app:import-ref /var/www/html/references/creeds/Athanasian 'Athanasian Creed' creed ath");
shell_exec("symfony console app:import-ref /var/www/html/references/creeds/Chalcedon 'Definition of Chalcedon' creed dc");
shell_exec("symfony console app:import-ref /var/www/html/references/creeds/French 'French Confession' creed fc");
shell_exec("symfony console app:import-ref /var/www/html/references/creeds/Nicene 'Nicene Creed' creed nc");

$dutchStandards = (
    strtolower(
        readline("Do you want to import the Dutch standards (Belgic Confession, Heidelberg Catechism, Canons of Dort) (y/n)? ")
    ) == 'y'
);

if ($dutchStandards) {
    print "Importing Dutch Standards".PHP_EOL;
    shell_exec("symfony console app:import-ref /var/www/html/references/bc Belgic belgic BC{\$ndx}");
    shell_exec("symfony console app:import-heidelberg /var/www/html/references/hc");
    shell_exec("symfony console app:import-ref /var/www/html/references/cd Canons cd CD");
}

$westminsterStandards = (
    strtolower(
        readline("Do you want to import the Westminster Standards (y/n)? ")
    ) == 'y'
);

if ($westminsterStandards) {
    print "Importing Westminster Standards".PHP_EOL;
    shell_exec("symfony console app:import-ref /var/www/html/references/wcf 'Westminster Confession' wcf WCF{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/wsc 'Westminster Shorter' wsc WSC{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/wlc 'Westminster Larger' wlc WLC{\$ndx}");
}

$helveticConfessions = (
    strtolower(
        readline("Do you want to import the Helvetic Confessions (1st & 2nd) (y/n)? ")
    ) == 'y'
);

if ($helveticConfessions) {
    print "Importing Helvitic standards".PHP_EOL;
    shell_exec("symfony console app:import-ref /var/www/html/references/fhc 'First Helvetic Confession' 1hc 1HC{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/shc 'Second Helvetic Confession' 2hc 2HC{\$ndx}");
}

$miscStandards = (
    strtolower(
        readline("Do you want to import the misc other standards (39 Articles, Augsberg Confession, London Baptist Confession, Luther's Small and Large Catechism, and Savoy Declaration) (y/n)? ")
    ) == 'y'
);

if ($miscStandards) {
    print "Importing misc standards".PHP_EOL;
    shell_exec("symfony console app:import-ref /var/www/html/references/39a 'Thirty-Nine Articles' 39a 39A{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/ac 'Augsberg Confession' agc AGC{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/lbc 'London Baptist Confession' lbc LBC{\$ndx}");
    shell_exec("symfony console app:import-ref /var/www/html/references/lsc 'Luther\'s Small Catechism' lsc LSC");
    shell_exec("symfony console app:import-ref /var/www/html/references/llc 'Luther\'s Large Catechism' llc LLC");
    shell_exec("symfony console app:import-ref /var/www/html/references/sd 'Savoy Declaration' sd SD{\$ndx}");
}

print "Sermon Notes Ready".PHP_EOL.PHP_EOL;
