2016-07-26 23:30:51 +02:00
|
|
|
<?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();
|
2016-08-04 05:59:04 +02:00
|
|
|
$this->storeMockedDepartments();
|
2016-07-26 23:30:51 +02:00
|
|
|
|
|
|
|
Response::respondSuccess();
|
|
|
|
} else {
|
|
|
|
Response::respondError(ERRORS::INIT_SETTINGS_DONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function storeGlobalSettings() {
|
|
|
|
$this->storeSettings([
|
2016-07-27 06:04:29 +02:00
|
|
|
'language' => 'en',
|
2016-08-20 23:06:41 +02:00
|
|
|
'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' => '',
|
2016-07-26 23:30:51 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 05:59:04 +02:00
|
|
|
|
|
|
|
private function storeMockedDepartments() {
|
|
|
|
$departments = [
|
|
|
|
'Tech Support',
|
|
|
|
'Suggestions',
|
|
|
|
'Sales and Subscriptions'
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($departments as $departmentName) {
|
|
|
|
$department = new Department();
|
|
|
|
$department->name = $departmentName;
|
|
|
|
$department->store();
|
|
|
|
}
|
|
|
|
}
|
2016-07-26 23:30:51 +02:00
|
|
|
}
|