Ejemplo n.º 1
0
$ini = array('database_type' => 'mysql', 'database_host' => 'localhost', 'database_name' => 'bec', 'database_username' => 'www-data', 'database_user_password' => '', 'gmail_application_name' => 'BEC Fault Monitoring', 'gmail_credentials_path' => __DIR__ . '/bec_fault_mon.json', 'gmail_client_secret_path' => __DIR__ . '/client_secret.json', 'gmail_username' => 'me', 'gmail_from' => '*****@*****.**', 'simtricity_base_uri' => 'https://trial.simtricity.com', 'simtricity_token_path' => __DIR__ . '/simtricity_token.txt', 'forecast_io_api_key_path' => __DIR__ . '/forecast_io_api_key.txt');
// Read configuration from ini file to override defaults
if (file_exists($iniFilename)) {
    $ini = array_merge($ini, parse_ini_file($iniFilename));
} else {
    if ($iniFilename != BECFM_INI_FILENAME) {
        die("Error: Requested ini file '{$iniFilename}' not found\n");
    }
}
// Connect to the BEC database
$becDB = new BECDB($ini['database_type'], $ini['database_host'], $ini['database_name'], $ini['database_username'], $ini['database_user_password']);
// Create Centre data: get the Gmail API client and construct the service object.
$gmail = new BECGmailWrapper();
if ($deleteCCRMode) {
    // Drop the Create Centre table from the database
    $result = $becDB->exec('DROP TABLE ' . BEC_DB_CREATE_CENTRE_RAW_TABLE);
    if ($result !== FALSE) {
        $result = $gmail->deleteLabel('IMPORTED');
    }
    exit($result !== FALSE ? 0 : 1);
}
if ($deleteSimtricityMode) {
    // Drop Simtricity reading tables
    $meterInfo = $becDB->getMeterInfoArray();
    $result = TRUE;
    foreach ($meterInfo as $meter) {
        $tableName = 'dailyreading_' . $becDB->meterDBName($meter['code']);
        $res = $becDB->exec('DROP TABLE ' . $tableName);
        if ($res === FALSE) {
            print "Error: Failed when trying to remove table {$tableName}\n";
            $result = $res;