. */ namespace SP\Modules\Web\Controllers\Traits; use Exception; use JsonException; use SP\Core\Bootstrap\BootstrapBase; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Ports\ConfigFileService; use SP\Http\JsonMessage; 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, ConfigFileService $config, callable $onSuccess = null ): bool { try { if ($configData->isDemoEnabled()) { return $this->returnJsonResponse(JsonMessage::JSON_WARNING, __u('Ey, this is a DEMO!!')); } $config->save($configData); if (BootstrapBase::$LOCK !== false && $configData->isMaintenance() === false) { Util::unlockApp(); } if ($onSuccess !== null) { $onSuccess(); } return $this->returnJsonResponse(JsonMessage::JSON_SUCCESS, __u('Configuration updated')); } catch (Exception $e) { processException($e); return $this->returnJsonResponse( JsonMessage::JSON_ERROR, __u('Error while saving the configuration'), [$e] ); } } }