<?php

/**
 * This file contains package_ecoyn_core_ajax_licenseUpload
 */

/**
 * @return array
 */

use QUI\System\License;

QUI::getAjax()->registerFunction(
    'package_ecoyn_core_ajax_licenseUpload',
    function ($File) {
        try {
            License::registerLicenseFile($File);
            License::activateSystem();
        } catch (\Exception $Exception) {
            QUI\System\Log::writeException($Exception);

            QUI::getMessagesHandler()->addError(
                QUI::getLocale()->get(
                    'quiqqer/core',
                    'message.ajax.licenseKey.upload.error'
                )
            );

            return;
        }

        QUI::getMessagesHandler()->addSuccess(
            QUI::getLocale()->get(
                'quiqqer/core',
                'message.ajax.licenseKey.upload.success'
            )
        );
    },
    ['File'],
    'Permission::checkAdminUser'
);
