2016-07-26 23:30:51 +02:00
|
|
|
<?php
|
2020-01-22 18:26:07 +01:00
|
|
|
use RedBeanPHP\Facade as RedBean;
|
2017-03-15 06:17:16 +01:00
|
|
|
use Respect\Validation\Validator as DataValidator;
|
|
|
|
DataValidator::with('CustomValidations', true);
|
2016-07-26 23:30:51 +02:00
|
|
|
|
2017-05-12 06:58:40 +02:00
|
|
|
/**
|
|
|
|
* @api {post} /system/init-settings Init settings
|
2020-06-17 02:26:04 +02:00
|
|
|
* @apiVersion 4.7.0
|
2017-05-12 06:58:40 +02:00
|
|
|
*
|
|
|
|
* @apiName Init settings
|
|
|
|
*
|
|
|
|
* @apiGroup System
|
|
|
|
*
|
|
|
|
* @apiDescription This path sets the initial settings. It can only be used once during installation.
|
|
|
|
*
|
|
|
|
* @apiPermission any
|
|
|
|
*
|
|
|
|
* @apiParam {String} language Indicates the default language of the system.
|
|
|
|
* @apiParam {String} registration Indicates if the registration should be enabled.
|
2018-12-24 01:44:59 +01:00
|
|
|
* @apiParam {String} server-email Email from where automated emails will be sent.
|
2017-06-28 15:02:54 +02:00
|
|
|
* @apiParam {String} smtp-host SMTP Server address.
|
|
|
|
* @apiParam {String} smtp-port SMTP Server port.
|
|
|
|
* @apiParam {String} smtp-user SMTP Authentication User.
|
|
|
|
* @apiParam {String} smtp-pass SMTP Authentication Password.
|
|
|
|
* @apiParam {String} allow-attachments Indicates if files can be attached to tickets and comments.
|
|
|
|
* @apiParam {String} title Title of the support center
|
|
|
|
* @apiParam {String} url Url of the frontend client.
|
2020-05-13 00:22:51 +02:00
|
|
|
* @apiParam {Boolean} mandatory-login Indicates if the login is mandatory.
|
2020-06-15 21:27:45 +02:00
|
|
|
* @apiParam {Number} default-department-id Indicates the id of the default department
|
|
|
|
* @apiParam {Boolean} locked-department Indicates if the default department is locked or not
|
2017-05-12 06:58:40 +02:00
|
|
|
* @apiUse INVALID_LANGUAGE
|
|
|
|
* @apiUse INIT_SETTINGS_DONE
|
|
|
|
*
|
|
|
|
* @apiSuccess {Object} data Empty object
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2016-07-26 23:30:51 +02:00
|
|
|
class InitSettingsController extends Controller {
|
|
|
|
const PATH = '/init-settings';
|
2017-02-08 19:09:15 +01:00
|
|
|
const METHOD = 'POST';
|
2016-07-26 23:30:51 +02:00
|
|
|
|
|
|
|
public function validations() {
|
|
|
|
return [
|
|
|
|
'permission' => 'any',
|
2017-03-15 06:17:16 +01:00
|
|
|
'requestData' => [
|
|
|
|
'language' => [
|
|
|
|
'validation' => DataValidator::validLanguage(),
|
|
|
|
'error' => ERRORS::INVALID_LANGUAGE
|
|
|
|
]
|
|
|
|
]
|
2016-07-26 23:30:51 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handler() {
|
|
|
|
if (Setting::isTableEmpty()) {
|
2020-01-22 18:26:07 +01:00
|
|
|
RedBean::exec(file_get_contents('data/db_schema.sql'));
|
2016-07-26 23:30:51 +02:00
|
|
|
$this->storeGlobalSettings();
|
|
|
|
$this->storeMailTemplates();
|
2016-12-21 03:29:19 +01:00
|
|
|
$this->storeLanguages();
|
2016-08-04 05:59:04 +02:00
|
|
|
$this->storeMockedDepartments();
|
2016-07-26 23:30:51 +02:00
|
|
|
|
|
|
|
Response::respondSuccess();
|
|
|
|
} else {
|
2018-11-20 23:41:00 +01:00
|
|
|
throw new RequestException(ERRORS::INIT_SETTINGS_DONE);
|
2016-07-26 23:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function storeGlobalSettings() {
|
|
|
|
$this->storeSettings([
|
2017-03-15 06:17:16 +01:00
|
|
|
'language' => Controller::request('language'),
|
2016-08-20 23:24:22 +02:00
|
|
|
'recaptcha-public' => '',
|
|
|
|
'recaptcha-private' => '',
|
2019-01-12 06:31:09 +01:00
|
|
|
'server-email' => Controller::request('server-email'),
|
2018-12-24 01:44:59 +01:00
|
|
|
'imap-host' => Controller::request('imap-host'),
|
|
|
|
'imap-user' => Controller::request('imap-user'),
|
|
|
|
'imap-pass' => Controller::request('imap-pass'),
|
2017-06-13 23:12:10 +02:00
|
|
|
'smtp-host' => Controller::request('smtp-host'),
|
|
|
|
'smtp-user' => Controller::request('smtp-user'),
|
2018-12-24 01:44:59 +01:00
|
|
|
'smtp-pass' => Controller::request('smtp-pass'),
|
2016-12-13 04:19:57 +01:00
|
|
|
'time-zone' => 0,
|
2016-12-13 04:21:06 +01:00
|
|
|
'maintenance-mode' => 0,
|
2016-12-13 04:19:57 +01:00
|
|
|
'layout' => 'boxed',
|
2017-06-07 07:29:25 +02:00
|
|
|
'allow-attachments' => !!Controller::request('allow-attachments'),
|
2018-09-20 20:52:27 +02:00
|
|
|
'max-size' => 1,
|
2017-06-13 23:12:10 +02:00
|
|
|
'title' => Controller::request('title') ? Controller::request('title') : 'Support Center',
|
|
|
|
'url' => Controller::request('url') ? Controller::request('url') : ('http://' . $_SERVER['HTTP_HOST']),
|
2017-03-16 20:11:27 +01:00
|
|
|
'registration' => !!Controller::request('registration'),
|
2017-03-15 06:17:16 +01:00
|
|
|
'last-stat-day' => date('YmdHi', strtotime(' -12 day ')),
|
2017-12-07 00:53:10 +01:00
|
|
|
'ticket-gap' => Hashing::generateRandomPrime(100000, 999999),
|
|
|
|
'ticket-first-number' => Hashing::generateRandomNumber(100000, 999999),
|
2018-11-15 02:53:46 +01:00
|
|
|
'session-prefix' => 'opensupports-'.Hashing::generateRandomToken().'_',
|
2019-01-19 00:58:30 +01:00
|
|
|
'mail-template-header-image' => 'https://s3.amazonaws.com/opensupports/logo.png',
|
2020-06-15 21:27:45 +02:00
|
|
|
'default-department-id' => 1,
|
|
|
|
'default-is-locked' => false,
|
2019-01-19 00:58:30 +01:00
|
|
|
'imap-token' => '',
|
2020-06-15 21:27:45 +02:00
|
|
|
'mandatory-login' => !!Controller::request('mandatory-login')
|
2016-07-26 23:30:51 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function storeMailTemplates() {
|
2018-11-14 16:28:01 +01:00
|
|
|
$mailLanguages = MailTexts::getTexts();
|
2017-10-31 22:31:14 +01:00
|
|
|
|
2018-11-14 16:28:01 +01:00
|
|
|
foreach ($mailLanguages as $language => $mailTemplate) {
|
|
|
|
foreach ($mailTemplate as $template => $texts) {
|
2016-07-26 23:30:51 +02:00
|
|
|
$mailTemplate = new MailTemplate();
|
|
|
|
|
|
|
|
$mailTemplate->setProperties([
|
2018-11-14 16:28:01 +01:00
|
|
|
'template' => $template,
|
|
|
|
'language' => $language,
|
|
|
|
'subject' => $texts[0],
|
|
|
|
'text1' => array_key_exists(1, $texts) ? $texts[1] : '',
|
|
|
|
'text2' => array_key_exists(2, $texts) ? $texts[2] : '',
|
|
|
|
'text3' => array_key_exists(3, $texts) ? $texts[3] : '',
|
2016-07-26 23:30:51 +02:00
|
|
|
]);
|
|
|
|
|
|
|
|
$mailTemplate->store();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function storeSettings($settings) {
|
|
|
|
foreach ($settings as $settingName => $settingValue) {
|
|
|
|
$setting = new Setting();
|
|
|
|
$setting->setProperties([
|
|
|
|
'name' => $settingName,
|
|
|
|
'value' => $settingValue
|
|
|
|
]);
|
|
|
|
|
|
|
|
$setting->store();
|
2016-12-21 03:29:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private function storeLanguages() {
|
2017-06-28 09:37:25 +02:00
|
|
|
$defaultLanguage = Controller::request('language');
|
2017-10-31 22:31:14 +01:00
|
|
|
|
2016-12-21 03:29:19 +01:00
|
|
|
foreach(Language::LANGUAGES as $languageCode) {
|
|
|
|
$language = new Language();
|
|
|
|
$language->setProperties([
|
|
|
|
'code' => $languageCode,
|
|
|
|
'allowed' => 1,
|
2017-06-28 09:37:25 +02:00
|
|
|
'supported' => ($languageCode === $defaultLanguage)
|
2016-12-21 03:29:19 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$language->store();
|
2016-07-26 23:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-04 05:59:04 +02:00
|
|
|
|
|
|
|
private function storeMockedDepartments() {
|
|
|
|
$departments = [
|
2017-03-15 06:17:16 +01:00
|
|
|
'Help and Support'
|
2016-08-04 05:59:04 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($departments as $departmentName) {
|
|
|
|
$department = new Department();
|
|
|
|
$department->name = $departmentName;
|
2020-06-15 21:27:45 +02:00
|
|
|
$department->private = 0;
|
2016-08-04 05:59:04 +02:00
|
|
|
$department->store();
|
|
|
|
}
|
|
|
|
}
|
2017-04-23 07:21:45 +02:00
|
|
|
}
|