. */ namespace SP\Modules\Web\Controllers\Traits; use Exception; use SP\Core\Bootstrap\BootstrapBase; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Ports\ConfigInterface; use SP\Http\JsonResponse; use SP\Util\Util; /** * Trait ConfigTrait * * @package SP\Modules\Web\Controllers\Traits */ trait ConfigTrait { use JsonTrait; /** * Guardar la configuración * * @throws \JsonException */ protected function saveConfig( ConfigDataInterface $configData, ConfigInterface $config, callable $onSuccess = null ): bool { try { if ($configData->isDemoEnabled()) { return $this->returnJsonResponse(JsonResponse::JSON_WARNING, __u('Ey, this is a DEMO!!')); } $config->saveConfig($configData); if (BootstrapBase::$LOCK !== false && $configData->isMaintenance() === false) { Util::unlockApp(); } if ($onSuccess !== null) { $onSuccess(); } return $this->returnJsonResponse(JsonResponse::JSON_SUCCESS, __u('Configuration updated')); } catch (Exception $e) { processException($e); return $this->returnJsonResponse( JsonResponse::JSON_ERROR, __u('Error while saving the configuration'), [$e] ); } } }