<?php
//ssh -L 12345:127.0.0.1:3306 root@stagingdev.museum-joanneum.at
if(php_sapi_name() === 'cli'){

}else{

    if (class_exists('\TYPO3\CMS\Core\Core\Environment')) {
        $applicationContext = \TYPO3\CMS\Core\Core\Environment::getContext();
        if($applicationContext->isDevelopment()) {
            //Disable Caching in Typo3 Back/Frontend
            foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'] as $cacheName => $cacheConfiguration) {
                $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations'][$cacheName]['backend'] = \TYPO3\CMS\Core\Cache\Backend\NullBackend::class;
            }

            $_SERVER['REMOTE_ADDR'] = "185.222.129.212";
        }
    }

}

//Backend Debug
$GLOBALS['TYPO3_CONF_VARS']['BE']['debug'] = true;
//Frontend Debug
$GLOBALS['TYPO3_CONF_VARS']['FE']['debug'] = true;
$GLOBALS['TYPO3_CONF_VARS']['SYS']['displayErrors'] = true;
//$GLOBALS['TYPO3_CONF_VARS']['SYS']['errorHandler'] = 'TYPO3\CMS\Core\Error\ErrorHandler';
$GLOBALS['TYPO3_CONF_VARS']['SYS']['devIPmask'] = '';

//Enable StackTrace Errors
$GLOBALS['TYPO3_CONF_VARS']['SYS']['debugExceptionHandler'] = 'TYPO3\CMS\Core\Error\DebugExceptionHandler';



//Configuration of the Database

$DatabaseConnection =  [
    'Default' => [
        'charset' => 'utf8mb4',
        'dbname' => '[ADD DBNAME HERE]',
        'driver' => 'mysqli',
        'host' => '[ADD IP HERE]',
        'password' => '[ADD PASSWORD HERE]',
        'port' => 3306,
        'tableoptions' => [
            'charset' => 'utf8mb4',
            'collate' => 'utf8mb4_unicode_ci',
        ],
        'user' => '[ADD USER HERE]',
    ],
];

//Override Configuration from LocalConfiguration.php
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'] = $DatabaseConnection;

//Get files from staging for development. If unavailable, fallback to placeholder. Using ichhabrecht/filefill EXT
//$storages contains all storge IDs
$storages = [1,2,3,6];
foreach ($storages as $storageId){
    $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['filefill']['storages'][$storageId] = [
        [
            'identifier' => 'domain',
            'configuration' => 'https://stagingdev.museum-joanneum.at/',
        ],
        [
            'identifier' => 'placeholder',
        ]
    ];
}