FEATURE #1865: add logging for uploaded file
This commit is contained in:
@@ -2,37 +2,33 @@
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use App\Models\FileManager\File as FileModel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
|
||||
class UploadFile extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
/**
|
||||
* @var UploadedFile
|
||||
*/
|
||||
public $uploadedFile;
|
||||
/**
|
||||
* @var
|
||||
* @var FileModel
|
||||
*/
|
||||
public $id;
|
||||
public $file;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param File $uploadedFile
|
||||
* @param $id
|
||||
* @param FileModel $file
|
||||
* @param $id
|
||||
*
|
||||
* @internal param File $uploadedFile
|
||||
*/
|
||||
public function __construct(File $uploadedFile, $id)
|
||||
public function __construct(FileModel $file)
|
||||
{
|
||||
$this->uploadedFile = $uploadedFile;
|
||||
$this->id = $id;
|
||||
$this->file = $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels the event should be broadcast on.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function broadcastOn()
|
||||
|
||||
@@ -47,7 +47,7 @@ class UploadFile extends Controller
|
||||
*/
|
||||
private function internalUpload(Request $request)
|
||||
{
|
||||
try {
|
||||
// try {
|
||||
$uploadedFiles = [];
|
||||
$files = $request->all()['files'];
|
||||
|
||||
@@ -62,9 +62,9 @@ class UploadFile extends Controller
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success', trans_choice('admin/fileManager.uploadSuccessfull', $successfullUploads));
|
||||
} catch (FileException $e) {
|
||||
return $this->invalidUpload('invalidFile');
|
||||
}
|
||||
// } catch (FileException $e) {
|
||||
// return $this->invalidUpload('invalidFile');
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Listeners;
|
||||
|
||||
use App\Events\UploadFile;
|
||||
use App\Models\FileManager\File;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Support\Facades\File as FileFacade;
|
||||
use Illuminate\Support\Str;
|
||||
@@ -12,15 +13,6 @@ use Symfony\Component\HttpFoundation\File\File as SymphonyFile;
|
||||
|
||||
class CreateImageThumbnail implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
@@ -30,10 +22,10 @@ class CreateImageThumbnail implements ShouldQueue
|
||||
*/
|
||||
public function handle(UploadFile $event)
|
||||
{
|
||||
$uploadedFile = $event->uploadedFile;
|
||||
$uploadedFile = $event->file;
|
||||
|
||||
// is uploaded file an image?
|
||||
if (!Str::startsWith($uploadedFile->getMimeType(), 'image')) {
|
||||
if (!Str::startsWith($uploadedFile->mime_type, 'image')) {
|
||||
return;
|
||||
}
|
||||
// yes, create thumbnail
|
||||
@@ -43,10 +35,12 @@ class CreateImageThumbnail implements ShouldQueue
|
||||
/**
|
||||
* Create thumbnail of given image
|
||||
*
|
||||
* @param SymphonyFile $file
|
||||
* @param File $uploadedFile
|
||||
*/
|
||||
private function createThumbnail(SymphonyFile $file)
|
||||
private function createThumbnail(File $uploadedFile)
|
||||
{
|
||||
$file = new SymphonyFile(config('app.upload_path') . '/' . $uploadedFile->filename);
|
||||
|
||||
// does thumbnail directory exist?
|
||||
if (!is_dir(config('app.thumbnail_path'))) {
|
||||
FileFacade::makeDirectory(config('app.thumbnail_path'));
|
||||
|
||||
@@ -2,30 +2,33 @@
|
||||
|
||||
namespace App\Listeners\Loggers;
|
||||
|
||||
use App\Events\Uploadfile;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use App\Events\UploadFile;
|
||||
|
||||
class LogUploadFile
|
||||
class LogUploadFile extends Logger
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param Uploadfile $event
|
||||
* @param CreateNewWidget $event
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Uploadfile $event)
|
||||
public function handle(UploadFile $event)
|
||||
{
|
||||
//
|
||||
$parameters = [
|
||||
'name' => $event->file->filename,
|
||||
'mime' => $event->file->mime_type,
|
||||
];
|
||||
|
||||
$this->saveLog($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for action name. Used only internally
|
||||
* @return mixed
|
||||
*/
|
||||
protected function getName()
|
||||
{
|
||||
return 'newFile';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\CMS\Contracts\Repositories\Content as ContentContract;
|
||||
use App\CMS\Helpers\Traits\Nullable;
|
||||
use App\CMS\Observers\Content as ContentObserver;
|
||||
use App\Models\FileManager\File;
|
||||
use App\Models\Module;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
@@ -55,7 +56,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Mark relationship with its historical records
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function history()
|
||||
@@ -65,7 +65,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Mark relationship with users table
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function author()
|
||||
@@ -75,7 +74,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Related files to content page
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function files()
|
||||
@@ -85,7 +83,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Category of content page
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function category()
|
||||
@@ -95,7 +92,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Subpages assigned to page
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function subpages()
|
||||
@@ -103,9 +99,17 @@ class Content extends Model
|
||||
return $this->hasMany(Content::class, 'parentId');
|
||||
}
|
||||
|
||||
/**
|
||||
* Module relationship
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function module()
|
||||
{
|
||||
return $this->belongsTo(Module::class, 'moduleHandler', 'handler');
|
||||
}
|
||||
|
||||
/**
|
||||
* Parent page
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function parentPage()
|
||||
@@ -115,7 +119,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Is current content draft?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDraft()
|
||||
@@ -125,7 +128,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Is current content visible for all visitors?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isPublic()
|
||||
@@ -135,7 +137,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Is current content visible only for logged users?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isProtected()
|
||||
@@ -145,7 +146,6 @@ class Content extends Model
|
||||
|
||||
/**
|
||||
* Is current content visible for logged user OR for everyone?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isVisible()
|
||||
@@ -164,6 +164,9 @@ class Content extends Model
|
||||
return parent::save($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment number of viewed content
|
||||
*/
|
||||
public function view()
|
||||
{
|
||||
$this->timestamps = false;
|
||||
|
||||
@@ -45,15 +45,15 @@ trait File
|
||||
$uploadedFile = $file->move($destination, $filename);
|
||||
|
||||
// insert record into database
|
||||
$id = $this->saveIntoDatabase($uploadedFile, $data, $file->getClientOriginalName());
|
||||
$fileInDB = $this->saveIntoDatabase($uploadedFile, $data, $file->getClientOriginalName());
|
||||
|
||||
// fire event about new file
|
||||
Event::fire(new UploadFile($uploadedFile, $id));
|
||||
Event::fire(new UploadFile($fileInDB));
|
||||
|
||||
return [
|
||||
'filename' => $filename,
|
||||
'file' => $file,
|
||||
'id' => $id
|
||||
'id' => $fileInDB->id
|
||||
];
|
||||
}
|
||||
|
||||
@@ -89,6 +89,6 @@ trait File
|
||||
'keywords' => isset($request->keyword) ? $request->keyword : ''
|
||||
]);
|
||||
|
||||
return $newFile->id;
|
||||
return $newFile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class AddNewActionLogType extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
\App\Models\ActionLog\ActionLogType::create([
|
||||
'string_id' => 'newFile',
|
||||
'name' => 'admin/actionLog.nameNewFile',
|
||||
'value' => 'admin/actionLog.newFile'
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
\App\Models\ActionLog\ActionLogType::where('string_id', 'newFile')
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,53 @@
|
||||
<?php
|
||||
return [
|
||||
"assignWidget" => "Přiřadil widget :widgetName (#:widgetId) do plochy :widgetAreaName (#:widgetAreaId)",
|
||||
"changeSettings" => "Změna nastavení",
|
||||
"createNewContent" => "Vytvořena nová obsahová stránka. Titulek <strong>:title</strong>, url :url a ID #:id",
|
||||
"createUser" => "Vytvořen nový uživatel :name s e-mailem :email.",
|
||||
"deleteContent" => 'Smazána stránka ":title", url "url a ID #:id. Tato změna je zaznamenána v revizi :revision.',
|
||||
"deleteCustomField" => "a",
|
||||
"deleteWidgetArea" => "Smazal plochu pro widget :name",
|
||||
"displayingUsersActions" => "Zobrazuji všechny akce od uživatele :name (:email).",
|
||||
"draftFromContent" => "Upraven widget :name (#:id)",
|
||||
"editContent" => 'Editace stránky - nový titulek je ":title", url :url a ID #:id. Revize změny: :revision.',
|
||||
"editCustomField" => "a",
|
||||
"editWidget" => "Upraven widget :name (#:id)",
|
||||
"editWidgetArea" => 'Upravena plocha pro widgety :name (#:id) s popisem ":description"',
|
||||
"invalidEditContentAttempt" => "Pokus o editaci obsahu s ID :contentId",
|
||||
"ip" => "IP adresa",
|
||||
"login" => "Přihlášen",
|
||||
"logout" => "Odhlášen",
|
||||
"nameAssignWidget" => "Přiřazení widgetu",
|
||||
"nameChangeSettings" => "Změna nastavení",
|
||||
"nameCreateNewContent" => "Vytvoření nové stránky",
|
||||
"nameCreateUser" => "Vytvořen uživatel",
|
||||
"nameDeleteContent" => "Smazání stránky",
|
||||
"nameDeleteCustomField" => "Smazání uživatelského pole",
|
||||
"nameDeleteWidgetArea" => "Smazání plochy pro widgety",
|
||||
"nameDraftFromContent" => "Vytvoření konceptu z publikované stránky",
|
||||
"nameEditContent" => "Úprava obsahu",
|
||||
"nameEditCustomField" => "Editace uživatelského pole",
|
||||
"nameEditWidget" => "Úprava widgetu",
|
||||
"nameEditWidgetArea" => "Úprava plochy pro widgety",
|
||||
"assignWidget" => "Přiřadil widget :widgetName (#:widgetId) do plochy :widgetAreaName (#:widgetAreaId)",
|
||||
"changeSettings" => "Změna nastavení",
|
||||
"createNewContent" => "Vytvořena nová obsahová stránka. Titulek <strong>:title</strong>, url :url a ID #:id",
|
||||
"createUser" => "Vytvořen nový uživatel :name s e-mailem :email.",
|
||||
"deleteContent" => 'Smazána stránka ":title", url "url a ID #:id. Tato změna je zaznamenána v revizi :revision.',
|
||||
"deleteCustomField" => "a",
|
||||
"deleteWidgetArea" => "Smazal plochu pro widget :name",
|
||||
"displayingUsersActions" => "Zobrazuji všechny akce od uživatele :name (:email).",
|
||||
"draftFromContent" => "Upraven widget :name (#:id)",
|
||||
"editContent" => 'Editace stránky - nový titulek je ":title", url :url a ID #:id. Revize změny: :revision.',
|
||||
"editCustomField" => "a",
|
||||
"editWidget" => "Upraven widget :name (#:id)",
|
||||
"editWidgetArea" => 'Upravena plocha pro widgety :name (#:id) s popisem ":description"',
|
||||
"invalidEditContentAttempt" => "Pokus o editaci obsahu s ID :contentId",
|
||||
"ip" => "IP adresa",
|
||||
"login" => "Přihlášen",
|
||||
"logout" => "Odhlášen",
|
||||
"nameAssignWidget" => "Přiřazení widgetu",
|
||||
"nameChangeSettings" => "Změna nastavení",
|
||||
"nameCreateNewContent" => "Vytvoření nové stránky",
|
||||
"nameCreateUser" => "Vytvořen uživatel",
|
||||
"nameDeleteContent" => "Smazání stránky",
|
||||
"nameDeleteCustomField" => "Smazání uživatelského pole",
|
||||
"nameDeleteWidgetArea" => "Smazání plochy pro widgety",
|
||||
"nameDraftFromContent" => "Vytvoření konceptu z publikované stránky",
|
||||
"nameEditContent" => "Úprava obsahu",
|
||||
"nameEditCustomField" => "Editace uživatelského pole",
|
||||
"nameEditWidget" => "Úprava widgetu",
|
||||
"nameEditWidgetArea" => "Úprava plochy pro widgety",
|
||||
"nameInvalidEditContentAttempt" => "Pokus o editaci neexistující/neplatné stránky",
|
||||
"nameLogin" => "Login",
|
||||
"nameLogout" => "Odhlášení",
|
||||
"nameNewCustomField" => "Vytvoření uživatelského pole",
|
||||
"nameNewWidget" => "Nový widget",
|
||||
"nameNewWidgetArea" => "Vytoření plochy pro widgety",
|
||||
"namePublishContent" => "Publikace stránky",
|
||||
"nameRemoveWidgetFromArea" => "Odebrání widgetu z plochy",
|
||||
"nameSetHomepage" => "Nastavení domovské stránky",
|
||||
"nameUserEdit" => "Editace uživatele",
|
||||
"newCustomField" => 'Přidal nové uživatelské pole s ID #:id a jménem ":name"',
|
||||
"newWidget" => 'Vytvořen nový widget :type se jménem :name (#:id) a popisem ":description".',
|
||||
"newWidgetArea" => 'Vytvořil plochu pro widgety :name (#:id) s popisem ":description"',
|
||||
"overview" => "Seznam všech akcí",
|
||||
"publishContent" => 'Publikována stránka ":title" (url :url, ID #:id). Revize :revision.',
|
||||
"removeWidgetFromArea" => "Odebrán widget :widgetName z oblasti :widgetAreaName (#widgetAreaId)",
|
||||
"setHomepage" => "Nastavena nová domovská stránka: :title, URL: :url a ID #:id. Revize :revision.",
|
||||
"userAgent" => "Prohlížeč",
|
||||
"userEdit" => "Upravil uživatele :name (:email)",
|
||||
"nameLogin" => "Login",
|
||||
"nameLogout" => "Odhlášení",
|
||||
"nameNewCustomField" => "Vytvoření uživatelského pole",
|
||||
"nameNewWidget" => "Nový widget",
|
||||
"nameNewWidgetArea" => "Vytoření plochy pro widgety",
|
||||
"namePublishContent" => "Publikace stránky",
|
||||
"nameRemoveWidgetFromArea" => "Odebrání widgetu z plochy",
|
||||
"nameSetHomepage" => "Nastavení domovské stránky",
|
||||
"nameUserEdit" => "Editace uživatele",
|
||||
"newCustomField" => 'Přidal nové uživatelské pole s ID #:id a jménem ":name"',
|
||||
"newWidget" => 'Vytvořen nový widget :type se jménem :name (#:id) a popisem ":description".',
|
||||
"newWidgetArea" => 'Vytvořil plochu pro widgety :name (#:id) s popisem ":description"',
|
||||
"overview" => "Seznam všech akcí",
|
||||
"publishContent" => 'Publikována stránka ":title" (url :url, ID #:id). Revize :revision.',
|
||||
"removeWidgetFromArea" => "Odebrán widget :widgetName z oblasti :widgetAreaName (#widgetAreaId)",
|
||||
"setHomepage" => "Nastavena nová domovská stránka: :title, URL: :url a ID #:id. Revize :revision.",
|
||||
"userAgent" => "Prohlížeč",
|
||||
"userEdit" => "Upravil uživatele :name (:email)",
|
||||
'newFile' => 'Nahrál soubor :name (typ :mime)',
|
||||
'nameNewFile' => 'Nahrání souboru'
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user