sintonia/legacy/public/setup/general-setup.php
Jonas L 5e8d8db6e9
Feature: Support php7.4 (#1354)
* Run CI tests against php 7.4

* Sort composer dependencies

* Remove unused Aws S3 php library

* Pin simplepie dependency to ^1.5

* Pin getid3 dependency to ^1.9

* Pin composer semver to ^3.2

* Pin php-amqplib to ^2.12

* Drop sentry logging support

* Update composer dependencies

* Move propel regenerate to Makefile

* Regenerate propel files with v1.7.0

* Pin propel orm to ^1.7

* Regenerate propel files with v1.7.2

* fix: generator_version in airtime-conf-production.php

* Replace propel/propel1 with jooola/propel1

* Regenerate propel files with v1.7.3-dev

* Fix php7.4 compatibility

Using php-cs-fixer:

    '@PhpCsFixer' => true,
    'concat_space' => ['spacing' => 'one'],
    'ordered_class_elements' => false,
    'yoda_style' => false,
    '@PHP74Migration' => true,
    'assign_null_coalescing_to_coalesce_equal' => false,
    'ternary_to_null_coalescing' => false,
    'heredoc_indentation' => false,
    '@PHP74Migration:risky' => true,
    'declare_strict_types' => false,
    'void_return' => false,
    'use_arrow_functions' => false,

* Fix pre-commit
2021-10-17 17:19:53 +02:00

113 lines
3.4 KiB
PHP

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