// for more info see bug report 5804 Default and Tech Emails shouldnt break install
require_once SQ_FUDGE_PATH . '/general/www.inc';
$SQ_CONF_DEFAULT_EMAIL = SQ_CONF_DEFAULT_EMAIL;
if (!empty($SQ_CONF_DEFAULT_EMAIL) && !valid_email($SQ_CONF_DEFAULT_EMAIL)) {
    echo "Value '{$SQ_CONF_DEFAULT_EMAIL}' configued for 'SQ_CONF_DEFAULT_EMAIL' in main.inc is not valid.\nPlease fix it and try running the script again.\n";
    exit(1);
}
$SQ_CONF_TECH_EMAIL = SQ_CONF_TECH_EMAIL;
if (!empty($SQ_CONF_TECH_EMAIL) && !valid_email($SQ_CONF_TECH_EMAIL)) {
    echo "Value '{$SQ_CONF_TECH_EMAIL}' configured for 'SQ_CONF_TECH_EMAIL' in main.inc is not valid.\nPlease fix it and try running the script again.\n";
    exit(1);
}
// Clean up any remembered data.
require_once $SYSTEM_ROOT . '/core/include/deja_vu.inc';
$deja_vu = new Deja_Vu();
if ($deja_vu->enabled()) {
    $deja_vu->forgetAll();
}
// get the list of functions used during install
require_once $SYSTEM_ROOT . '/install/install.inc';
$GLOBALS['SQ_SYSTEM']->changeDatabaseConnection('db2');
$GLOBALS['SQ_SYSTEM']->doTransaction('BEGIN');
// let everyone know we are installing
$GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_FORCED);
// Install all DAL core and package queries upfront
$result = install_dal_queries('__core__');
if (!$result) {
    trigger_error('Unable to install core dal queries.', E_USER_ERROR);
    exit(1);
}
$packages = get_package_list();
}
if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT . '/core/include/init.inc')) {
    echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
    usage();
}
if ($DISABLE_FORCE) {
    // forcibly disable deja vu before even include init.inc
    file_put_contents($SYSTEM_ROOT . '/data/private/conf/.dejavu', '0');
    echo "Deja Vu is forcibly disabled.\n";
    exit;
}
require_once $SYSTEM_ROOT . '/core/include/init.inc';
require_once $SYSTEM_ROOT . '/core/include/deja_vu.inc';
$deja_vu = new Deja_Vu();
if ($SHOW_STATUS) {
    if ($deja_vu->enabled() == FALSE) {
        echo "Deja Vu is currently disabled.\n";
    } else {
        echo "Deja Vu is currently enabled.\n";
        echo "Recaching delay time: " . $deja_vu->getRecachingDelay() . "s.\n";
        echo "Cache storage: " . $deja_vu->getCacheStorage() . ".\n";
    }
    // Further options are ignored if any
    exit;
}
// 'enable', 'disable' and 'forget' options are mutually exclusive
if ($ENABLE_DEJA_VU) {
    if ($deja_vu->enabled() == TRUE) {
        echo "Deja Vu is already enabled.\n";
    } else {
        $ok = $deja_vu->checkRequirements();