/** * Updates a setting value. * * @param string $name * @param string|null $value * * @return void */ public function set($name, $value) { $this->stale = true; if ($value === null) { $this->model->where('name', $name)->delete(); } else { $this->model->updateOrCreate(compact('name'), compact('value')); } }
/** * Creates or updates a setting value. * * @param string $name * @param string|null $value * * @return void */ public function set($name, $value) { if ($value === null) { $this->model->where('name', $name)->delete(); if ($this->settings && isset($this->settings[$name])) { unset($this->settings[$name]); } } else { $this->model->updateOrCreate(compact('name'), compact('value')); if ($this->settings) { $this->settings[$name] = $value; } } }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { if (Binput::get('remove_banner') == "1") { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::back()->withErrorMessage("You need to upload an image that is less than {$maxSize}."); } if (!$file->isValid() || $file->getError()) { return Redirect::back()->withErrorMessage($file->getErrorMessage()); } if (strpos($file->getMimeType(), 'image/') !== 0) { return Redirect::back()->withErrorMessage('Only images may be uploaded.'); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::back()->withSaved(false); } return Redirect::back()->withSaved(true); }
/** * Returns the segment write key. * * @return string */ public function fetch() { $writeKey = null; try { // Firstly, does the setting exist? if (null === ($writeKey = Setting::get('segment_write_key'))) { // No, let's go fetch it. $writeKey = $this->repository->fetch(); Setting::set('segment_write_key', $writeKey); } else { // It does, but how old is it? $setting = SettingModel::where('name', 'segment_write_key')->first(); // It's older than an hour, let's refresh if ($setting->updated_at->lt(Carbon::now()->subHour())) { $writeKey = $this->repository->fetch(); // Update the setting. This is done manual to make sure updated_at is overwritten. $setting->value = $writeKey; $setting->updated_at = Carbon::now(); $setting->save(); } } } catch (QueryException $e) { // Just return it until we're setup. $writeKey = $this->repository->fetch(); } return $writeKey; }
/** * Run the has setting filter. * * We're verifying that the given setting exists in our database. If it * doesn't, then we're sending the user to the setup page so that they can * complete the installation of Cachet on their server. * * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * @param string $settingName * * @return \Illuminate\Http\Response|null */ public function filter(Route $route, Request $request, $settingName) { try { $setting = Setting::where('name', $settingName)->first(); if (!$setting || !$setting->value) { return Redirect::to('setup'); } } catch (Exception $e) { return Redirect::to('setup'); } }
/** * Run the is setup filter. * * We're verifying that Cachet is correctly setup. If it is, they we're * sending the user to the dashboard so they can use Cachet. * * @param \Illuminate\Routing\Route $route * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response|null */ public function filter(Route $route, Request $request) { try { $setting = Setting::where('name', 'app_name')->first(); if ($setting && $setting->value) { return Redirect::to('/dashboard'); } } catch (Exception $e) { // do nothing } }
/** * Run the is setup filter. * * We're verifying that Cachet is correctly setup. If it is, they we're * sending the user to the dashboard so they can use Cachet. * * @param \Illuminate\Routing\Route $route * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { try { $setting = Setting::where('name', 'app_name')->first(); if ($setting && $setting->value) { return Redirect::route('dashboard'); } } catch (Exception $e) { // do nothing } return $next($request); }
/** * Run the has setting middleware. * * We're verifying that the given setting exists in our database. If it * doesn't, then we're sending the user to the setup page so that they can * complete the installation of Cachet on their server. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $settingName = $this->getSettingName($request); try { $setting = Setting::where('name', $settingName)->first(); if (!$setting || !$setting->value) { return Redirect::to('setup'); } } catch (Exception $e) { return Redirect::to('setup'); } return $next($request); }
/** * Updates the status page settings. * * @return \Illuminate\View\View */ public function postSettings() { $redirectUrl = Session::get('redirect_to', route('dashboard.settings.setup')); if (Binput::get('remove_banner') === '1') { $setting = Setting::where('name', 'app_banner'); $setting->delete(); } if (Binput::hasFile('app_banner')) { $file = Binput::file('app_banner'); // Image Validation. // Image size in bytes. $maxSize = $file->getMaxFilesize(); if ($file->getSize() > $maxSize) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.too-big', ['size' => $maxSize])); } if (!$file->isValid() || $file->getError()) { return Redirect::to($redirectUrl)->withErrors($file->getErrorMessage()); } if (!starts_with($file->getMimeType(), 'image/')) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.app-setup.images-only')); } // Store the banner. Setting::firstOrCreate(['name' => 'app_banner'])->update(['value' => base64_encode(file_get_contents($file->getRealPath()))]); // Store the banner type Setting::firstOrCreate(['name' => 'app_banner_type'])->update(['value' => $file->getMimeType()]); } try { foreach (Binput::except(['app_banner', 'remove_banner']) as $settingName => $settingValue) { if ($settingName === 'app_analytics_pi_url') { $settingValue = rtrim($settingValue, '/'); } Setting::firstOrCreate(['name' => $settingName])->update(['value' => $settingValue]); } } catch (Exception $e) { return Redirect::to($redirectUrl)->withErrors(trans('dashboard.settings.edit.failure')); } if (Binput::has('app_locale')) { Lang::setLocale(Binput::get('app_locale')); } return Redirect::to($redirectUrl)->withSuccess(trans('dashboard.settings.edit.success')); }
/** * Deletes a setting. * * @param string $name * * @return void */ public function delete($name) { $this->stale = true; $this->model->where('name', $name)->delete(); }