sintonia/legacy/public/setup/general-setup.php

114 lines
3.5 KiB
PHP
Raw Normal View History

2014-12-09 23:48:16 +01:00
<?php
2021-10-11 16:10:47 +02:00
define('CONFIG_PATH', dirname(dirname(__DIR__)) . '/application/configs/');
2020-05-19 16:16:31 +02:00
2021-10-11 16:10:47 +02:00
require_once dirname(dirname(__DIR__)) . '/vendor/propel/propel1/runtime/lib/Propel.php';
2020-05-19 16:16:31 +02:00
2021-10-11 16:10:47 +02:00
require_once CONFIG_PATH . 'conf.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/CcPref.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/CcPrefPeer.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/CcPrefQuery.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/map/CcPrefTableMap.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/om/BaseCcPref.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/om/BaseCcPrefPeer.php';
require_once dirname(dirname(__DIR__)) . '/application/models/airtime/om/BaseCcPrefQuery.php';
2020-05-19 16:16:31 +02:00
2014-12-09 23:48:16 +01:00
/**
* User: sourcefabric
2021-10-11 16:10:47 +02:00
* Date: 08/12/14.
2014-12-09 23:48:16 +01:00
*
* Class GeneralSetup
*
* Wrapper class for validating and setting up general settings during the installation process
*/
2021-10-11 16:10:47 +02:00
class GeneralSetup extends Setup
{
2014-12-09 23:48:16 +01:00
// airtime.conf section header
2021-10-11 16:10:47 +02:00
protected static $_section = '[general]';
2014-12-09 23:48:16 +01:00
2020-05-19 16:16:31 +02:00
// Array of key->value pairs for airtime.conf
protected static $_properties;
2014-12-09 23:48:16 +01:00
// Constant form field names for passing errors back to the front-end
2021-10-11 16:10:47 +02:00
public const GENERAL_PORT = 'generalPort';
public const GENERAL_HOST = 'generalHost';
public const CORS_URL = 'corsUrl';
2014-12-09 23:48:16 +01:00
2021-10-11 16:10:47 +02:00
public static $cors_url;
2014-12-09 23:48:16 +01:00
// Message and error fields to return to the front-end
2021-10-11 16:10:47 +02:00
public static $message;
public static $errors = [];
public function __construct($settings)
{
self::$_properties = [
'api_key' => $this->generateRandomString(),
'base_url' => $settings[self::GENERAL_HOST],
'base_port' => $settings[self::GENERAL_PORT],
'cors_url' => $settings[self::CORS_URL],
];
2020-05-19 16:16:31 +02:00
self::$cors_url = $settings[self::CORS_URL];
2014-12-09 23:48:16 +01:00
}
/**
* @return array associative array containing a display message and fields with errors
*/
2021-10-11 16:10:47 +02:00
public function runSetup()
{
2014-12-15 15:53:50 +01:00
// TODO Do we need to validate these settings?
2014-12-09 23:48:16 +01:00
if (count(self::$errors) <= 0) {
$this->writeToTemp();
}
2020-05-19 16:16:31 +02:00
if (strlen(self::$cors_url) == 0) {
2021-10-11 16:10:47 +02:00
} else {
2020-05-19 16:16:31 +02:00
$this->setupCorsUrl();
}
2021-10-11 16:10:47 +02:00
return [
'message' => self::$message,
'errors' => self::$errors,
];
2014-12-09 23:48:16 +01:00
}
2021-10-11 16:10:47 +02:00
2020-05-19 16:16:31 +02:00
/**
* If the user entered a CORS Url then add it to the system preferences
2021-10-11 16:10:47 +02:00
* TODO Make sure we check for existing CORS URLs and display them on initial form.
2020-05-19 16:16:31 +02:00
*/
2021-10-11 16:10:47 +02:00
public function setupCorsUrl()
{
2020-05-19 16:16:31 +02:00
try {
$_SERVER['AIRTIME_CONF'] = AIRTIME_CONF_TEMP_PATH;
2021-10-11 16:10:47 +02:00
Propel::init(CONFIG_PATH . 'airtime-conf-production.php');
2020-05-19 16:16:31 +02:00
$con = Propel::getConnection();
2021-10-11 16:10:47 +02:00
} catch (Exception $e) {
2020-05-19 16:16:31 +02:00
self::$message = "Failed to insert Cors URL; database isn't configured properly!";
self::$errors[] = self::CORS_URL;
2021-10-11 16:10:47 +02:00
2020-05-19 16:16:31 +02:00
return;
}
$this->runCorsUrlQuery($con);
}
2014-12-09 23:48:16 +01:00
2021-10-11 16:10:47 +02:00
public function runCorsUrlQuery($con)
{
2020-05-19 16:16:31 +02:00
try {
2021-10-11 16:10:47 +02:00
Application_Model_Preference::SetAllowedCorsUrls(self::$cors_url);
Propel::close();
//unset($_SERVER['AIRTIME_CONF']);
2020-05-19 16:16:31 +02:00
} catch (Exception $e) {
2021-10-11 16:10:47 +02:00
self::$message = 'Failed to insert ' . self::$cors_url . ' into cc_pref' . $e;
2020-05-19 16:16:31 +02:00
self::$errors[] = self::CORS_URL;
}
}
2021-10-11 16:10:47 +02:00
}