mirror of
				https://github.com/opensupports/opensupports.git
				synced 2025-11-03 21:15:00 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?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([
 | 
						|
            'language' => 'en',
 | 
						|
            '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();
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |