#!/usr/local/bin/php

<?php

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

print "Creating database schema".PHP_EOL;
`symfony console doctrine:database:create`;

print "Updating migrations and setting permissions for data folder".PHP_EOL;
`symfony console doctrine:migrations:migrate --no-interaction`;

`chown -R www-data:www-data /data`;

// import reference material

print "Importing Bible and Eccumenical Creeds".PHP_EOL;
`symfony console app:ingest-bible /var/www/html/reference/esv-bible`;
`symfony console app:import-ref /var/www/html/references/creeds/Apostles 'Apostles Creed' creed apc`;
`symfony console app:import-ref /var/www/html/references/creeds/Athanasian 'Athanasian Creed' creed ath`;
`symfony console app:import-ref /var/www/html/references/creeds/Chalcedon 'Definition of Chalcedon' creed dc`;
`symfony console app:import-ref /var/www/html/references/creeds/French 'French Confession' creed fc`;
`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;
    `symfony console app:import-ref /var/www/html/references/bc Belgic belgic BC{\$ndx}`;
    `symfony console app:import-heidelberg`;
    `symfony console app:import-canons-of-dort`;
}

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

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

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

if ($helviticConfessions) {
    print "Importing Helvitic standards".PHP_EOL;
    `symfony console app:import-ref /var/www/html/references/fhc 'First Helvetic Confession' 1hc 1HC{\$ndx}`;
    `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;
    `symfony console app:import-ref /var/www/html/references/39a 'Thirty-Nine Articles' 39a 39A{\$ndx}`;
    `symfony console app:import-ref /var/www/html/references/ac 'Augsberg Confession' agc AGC{\$ndx}`;
    `symfony console app:import-ref /var/www/html/references/lbc 'London Baptist Confession' lbc LBC{\$ndx}`;
    `symfony console app:import-ref /var/www/html/references/lsc 'Luther\'s Small Catechism' lsc LSC`;
    `symfony console app:import-ref /var/www/html/references/llc 'Luther\'s Large Catechism' llc LLC`;
    `symfony console app:import-ref /var/www/html/references/sd 'Savoy Declaration' sd SD{\$ndx}`;
}

print "Sermon Notes Ready".PHP_EOL.PHP_EOL;
