Files
cachet-docker/app/Http/Controllers/Admin/ApiController.php
EdeMeijer c4c55a73cb Use APC cache for Docker and fix bug with changing component sort order
By default, the file cache is used, but this breaks the throttling detection when authenticating.
The APC cache is tagged and will allow you to log in again after installation.
---
When changing the sort order, a form with hidden inputs for every component was serialized. The hidden inputs
had names in the form of `component[id]`. When you removed components, there would be holes in this ID sequence,
yielding a serialized array with empty values (since JS arrays always have every index until the highest one, even
if you don't specify a value).

This is fixed by just passing an array of component IDs in the desired sort order to the API endpoint. The API
will then update the components based on the implicit given sort order. Much simpler.
2015-04-25 12:00:53 +02:00

77 lines
2.0 KiB
PHP

<?php
/*
* This file is part of Cachet.
*
* (c) James Brooks <james@cachethq.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\IncidentTemplate;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class ApiController extends AbstractController
{
/**
* Updates a component with the entered info.
*
* @param \CachetHQ\Cachet\Models\Component $component
*
* @throws \Exception
*
* @return \CachetHQ\Cachet\Models\Component
*/
public function postUpdateComponent(Component $component)
{
if (!$component->update(Binput::except(['_token']))) {
throw new Exception(trans('dashboard.components.edit.failure'));
}
return $component;
}
/**
* Updates a components ordering.
*
* @return array
*/
public function postUpdateComponentOrder()
{
$componentData = Binput::all();
foreach ($componentData['ids'] as $order => $componentId) {
$component = Component::find($componentId);
$component->update(['order' => $order + 1]); // Ordering should be 1-based, data comes in 0-based
}
return $componentData;
}
/**
* Returns a template by slug.
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @return \CachetHQ\Cachet\Models\IncidentTemplate
*/
public function getIncidentTemplate()
{
$templateSlug = Binput::get('slug');
$template = IncidentTemplate::where('slug', $templateSlug)->first();
if ($template) {
return $template;
}
throw new ModelNotFoundException('Incident template for '.$templateSlug.' could not be found.');
}
}