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-12-21 03:29:19 +01:00
|
|
|
$this->storeLanguages();
|
2016-08-04 05:59:04 +02:00
|
|
|
$this->storeMockedDepartments();
|
2016-09-24 21:26:37 +02:00
|
|
|
$this->createMockedStaff();
|
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:24:22 +02:00
|
|
|
'recaptcha-public' => '',
|
|
|
|
'recaptcha-private' => '',
|
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-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',
|
|
|
|
'allow-attachments' => 0,
|
2017-01-16 22:15:28 +01:00
|
|
|
'max-size' => 1024,
|
2017-01-04 23:29:23 +01:00
|
|
|
'title' => 'Support Center',
|
2017-01-10 19:22:36 +01:00
|
|
|
'url' => 'http://www.opensupports.com/support',
|
2017-01-16 20:07:53 +01:00
|
|
|
'registration' => true,
|
2017-01-16 21:11:45 +01:00
|
|
|
'user-system-enabled' => true,
|
2017-01-14 01:58:59 +01:00
|
|
|
'last-stat-day' => '20170101', //TODO: get current date
|
2017-01-12 20:45:01 +01:00
|
|
|
'ticket-gap' => Hashing::generateRandomPrime(100000, 999999),
|
|
|
|
'file-gap' => Hashing::generateRandomPrime(100000, 999999),
|
|
|
|
'file-first-number' => Hashing::generateRandomNumber(100000, 999999),
|
2017-01-12 22:29:50 +01:00
|
|
|
'file-quantity' => 0
|
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-12-21 03:29:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private function storeLanguages() {
|
|
|
|
foreach(Language::LANGUAGES as $languageCode) {
|
|
|
|
$language = new Language();
|
|
|
|
$language->setProperties([
|
|
|
|
'code' => $languageCode,
|
|
|
|
'allowed' => 1,
|
|
|
|
'supported' => ($languageCode === 'en')
|
|
|
|
]);
|
|
|
|
|
|
|
|
$language->store();
|
2016-07-26 23:30:51 +02:00
|
|
|
}
|
|
|
|
}
|
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-09-24 21:26:37 +02:00
|
|
|
|
|
|
|
private function createMockedStaff() {
|
|
|
|
$staff = new Staff();
|
|
|
|
$staff->setProperties([
|
|
|
|
'name' => 'Emilia Clarke',
|
|
|
|
'email' => 'staff@opensupports.com',
|
|
|
|
'password' => Hashing::hashPassword('staff'),
|
2016-11-05 17:56:33 +01:00
|
|
|
'profilePic' => 'http://www.opensupports.com/profilepic.jpg',
|
2016-10-03 21:44:41 +02:00
|
|
|
'level' => 3,
|
|
|
|
'sharedDepartmentList' => Department::getAll(),
|
2016-09-24 21:26:37 +02:00
|
|
|
'sharedTicketList' => []
|
|
|
|
]);
|
2016-12-10 22:55:12 +01:00
|
|
|
foreach(Department::getAll() as $department) {
|
|
|
|
$department->owners++;
|
|
|
|
$department->store();
|
|
|
|
}
|
2016-09-24 21:26:37 +02:00
|
|
|
$staff->store();
|
|
|
|
}
|
2016-07-26 23:30:51 +02:00
|
|
|
}
|