Had to change some things in global widgets management and also in html code widget. Sorry for this ugly commit..
104 lines
2.6 KiB
PHP
104 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Events\EditFile;
|
|
use App\Helpers\FileManager;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\EditUploadedFileRequest;
|
|
use App\Models\File;
|
|
use Illuminate\Support\Facades\Event;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
|
|
class EditUploadedFile extends Controller
|
|
{
|
|
/**
|
|
* Edit form
|
|
*
|
|
* Render edit form for displaying details and updating given file
|
|
*
|
|
* @param int $id file id
|
|
*
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
|
*/
|
|
public function getDetail($id)
|
|
{
|
|
try {
|
|
$file = File::findOrFail($id);
|
|
} catch (NotFoundHttpException $e) {
|
|
return $this->fileNotFound();
|
|
}
|
|
|
|
return view('admin.fileManager.edit', [
|
|
'file' => $file,
|
|
'extraInfo' => FileManager::getAdditionalInfo($file)
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Updates file
|
|
*
|
|
* User can change only keywords, original filename and description. Mime type, hash and other fields remain
|
|
* unchanged
|
|
*
|
|
* @param EditUploadedFileRequest $request
|
|
* @param $id
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
public function postEdit(EditUploadedFileRequest $request, $id)
|
|
{
|
|
try {
|
|
$file = File::findOrFail($id);
|
|
} catch (NotFoundHttpException $e) {
|
|
return $this->fileNotFound();
|
|
}
|
|
|
|
// set values from form
|
|
$file->name = $request->name;
|
|
$file->keywords = $request->keywords;
|
|
$file->description = $request->description;
|
|
$file->save();
|
|
|
|
// fire action
|
|
Event::fire(new EditFile($file));
|
|
|
|
// update successfull
|
|
return redirect()
|
|
->route('upload.detail', ['id' => $id])
|
|
->with('success', trans('admin/fileManager.successfullyChanged'));
|
|
}
|
|
|
|
/**
|
|
* Deletes file
|
|
*
|
|
* @param $id
|
|
*/
|
|
public function deleteFile($id)
|
|
{
|
|
try {
|
|
$file = File::findOrFail($id);
|
|
} catch (NotFoundHttpException $e) {
|
|
return $this->fileNotFound();
|
|
}
|
|
|
|
$file->delete();
|
|
|
|
return redirect()
|
|
->route('upload.overview')
|
|
->with('success', trans('admin/fileManager.fileDeleted'));
|
|
}
|
|
|
|
/**
|
|
* Redirects user to files overview
|
|
*
|
|
* @return \Illuminate\Http\RedirectResponse
|
|
*/
|
|
private function fileNotFound()
|
|
{
|
|
return redirect()
|
|
->route('upload.overview')
|
|
->with('error', trans('admin/fileManager.fileNotFound'));
|
|
}
|
|
}
|