opensupports/server/controllers/system/init-settings.php

83 lines
2.3 KiB
PHP
Raw Normal View History

<?php
class InitSettingsController extends Controller {
const PATH = '/init-settings';
public function validations() {
return [
'permission' => 'any',
'requestData' => []
];
}
public function handler() {
if (Setting::isTableEmpty()) {
$this->storeGlobalSettings();
$this->storeMailTemplates();
$this->storeMockedDepartments();
Response::respondSuccess();
} else {
Response::respondError(ERRORS::INIT_SETTINGS_DONE);
}
}
private function storeGlobalSettings() {
$this->storeSettings([
2016-07-27 06:04:29 +02:00
'language' => 'en',
'recaptcha-public' => '6LfM5CYTAAAAAGLz6ctpf-hchX2_l0Ge-Bn-n8wS',
'recaptcha-private' => '6LfM5CYTAAAAAP3dfBJfC49X2qVm0tH9IZ-VZjzw',
2016-07-27 06:04:29 +02:00
'no-reply-email' => 'noreply@opensupports.com',
'smtp-host' => 'localhost',
'smtp-port' => 7070,
'smtp-user' => '',
'smtp-pass' => '',
]);
}
private function storeMailTemplates() {
$mails = InitialMails::retrieve();
foreach ($mails as $mailType => $mailLanguages) {
foreach ($mailLanguages as $mailLanguage => $mailContent) {
$mailTemplate = new MailTemplate();
$mailTemplate->setProperties([
'type' => $mailType,
'language' => $mailLanguage,
'subject' => $mailContent['subject'],
'body' => $mailContent['body']
]);
$mailTemplate->store();
}
}
}
private function storeSettings($settings) {
foreach ($settings as $settingName => $settingValue) {
$setting = new Setting();
$setting->setProperties([
'name' => $settingName,
'value' => $settingValue
]);
$setting->store();
}
}
private function storeMockedDepartments() {
$departments = [
'Tech Support',
'Suggestions',
'Sales and Subscriptions'
];
foreach ($departments as $departmentName) {
$department = new Department();
$department->name = $departmentName;
$department->store();
}
}
}