<?php

include_once("config.php");

if (substr($config['path'], -1) == '/') {
    $config['path'] = substr($config['path'], 0, -1);
}

include_once("{$config['path']}/common.inc.php");

if (php_sapi_name() !== 'cli') {
    die('This script can only be run from the command line');
}

$filename = getGlobalSetting("AutoUpgrade", "");
setGlobalSetting("AutoUpgrade", "");

if (empty($filename)) {
    echo "No file to do!\n";
    exit; # No file to do!
}
$apidir = __DIR__ . "/";

$command = "cd {$config['path']}/components/MaintenanceScripts/;" . $config['phpcommand'] . " upgrade.php $filename $apidir";
exec($command, $result);
echo $result[0];