Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117969284
D4400.1775508244.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D4400.1775508244.diff
View Options
diff --git a/src/app/EventLog.php b/src/app/EventLog.php
new file mode 100644
--- /dev/null
+++ b/src/app/EventLog.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace App;
+
+use App\Traits\UuidStrKeyTrait;
+use Dyrynda\Database\Support\NullableFields;
+use Illuminate\Database\Eloquent\Model;
+
+/**
+ * The eloquent definition of an EventLog record.
+ *
+ * @property ?string $comment Optional event description
+ * @property ?array $data Optional event data
+ * @property string $id Log record identifier
+ * @property string $object_id Object identifier
+ * @property string $object_type Object type (class)
+ * @property int $type Event type (0-255)
+ * @property ?string $user_email Acting user email
+ */
+class EventLog extends Model
+{
+ use NullableFields;
+ use UuidStrKeyTrait;
+
+ public const TYPE_SUSPENDED = 1;
+ public const TYPE_UNSUSPENDED = 2;
+ public const TYPE_COMMENT = 3;
+
+ /** @var array<int, string> The attributes that are mass assignable */
+ protected $fillable = [
+ 'comment',
+ // extra event info (json)
+ 'data',
+ 'type',
+ // user, domain, etc.
+ 'object_id',
+ 'object_type',
+ // actor, if any
+ 'user_email',
+ ];
+
+ /** @var array<string, string> Casts properties as type */
+ protected $casts = [
+ 'created_at' => 'datetime:Y-m-d H:i:s',
+ 'data' => 'array',
+ 'type' => 'integer',
+ ];
+
+ /** @var array<int, string> The attributes that can be not set */
+ protected $nullable = ['comment', 'data', 'user_email'];
+
+ /** @var string Database table name */
+ protected $table = 'eventlog';
+
+
+ /**
+ * Principally an object such as Domain, User, Group.
+ * Note that it may be trashed (soft-deleted).
+ *
+ * @return mixed
+ */
+ public function object()
+ {
+ return $this->morphTo()->withTrashed(); // @phpstan-ignore-line
+ }
+
+ /**
+ * Get a string for use in translation tables derived from the object type.
+ *
+ * @return ?string Lower-case object type, e.g. user, domain, etc.
+ */
+ private function objectTypeToLabelString(): ?string
+ {
+ if (empty($this->object_type)) {
+ return null;
+ }
+
+ return strtolower(class_basename($this->object_type));
+ }
+
+ /**
+ * Event type mutator
+ *
+ * @throws \Exception
+ */
+ public function setTypeAttribute($type)
+ {
+ $type = (int) $type;
+
+ if ($type < 0 || $type > 255) {
+ throw new \Exception("Expecting an event type between 0 and 255");
+ }
+
+ $this->attributes['type'] = $type;
+ }
+}
diff --git a/src/app/Observers/EventLogObserver.php b/src/app/Observers/EventLogObserver.php
new file mode 100644
--- /dev/null
+++ b/src/app/Observers/EventLogObserver.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace App\Observers;
+
+use App\EventLog;
+
+class EventLogObserver
+{
+ /**
+ * Ensure the event entry ID is a custom ID (uuid).
+ *
+ * @param \App\EventLog $eventlog The EventLog object
+ */
+ public function creating(EventLog $eventlog): void
+ {
+ if (!isset($eventlog->user_email)) {
+ $eventlog->user_email = \App\Utils::userEmailOrNull();
+ }
+
+ if (empty($eventlog->event)) {
+ throw new \Exception("Unset event type");
+ }
+ }
+}
diff --git a/src/app/PackageSku.php b/src/app/PackageSku.php
--- a/src/app/PackageSku.php
+++ b/src/app/PackageSku.php
@@ -37,9 +37,6 @@
'cost',
];
- /** @var string Database table name */
- protected $table = 'package_skus';
-
/** @var bool Indicates if the model should be timestamped. */
public $timestamps = false;
diff --git a/src/app/Providers/AppServiceProvider.php b/src/app/Providers/AppServiceProvider.php
--- a/src/app/Providers/AppServiceProvider.php
+++ b/src/app/Providers/AppServiceProvider.php
@@ -69,6 +69,7 @@
{
\App\Domain::observe(\App\Observers\DomainObserver::class);
\App\Entitlement::observe(\App\Observers\EntitlementObserver::class);
+ \App\EventLog::observe(\App\Observers\EventLogObserver::class);
\App\Group::observe(\App\Observers\GroupObserver::class);
\App\GroupSetting::observe(\App\Observers\GroupSettingObserver::class);
\App\Meet\Room::observe(\App\Observers\Meet\RoomObserver::class);
diff --git a/src/database/migrations/2023_06_06_100000_create_eventlog_table.php b/src/database/migrations/2023_06_06_100000_create_eventlog_table.php
new file mode 100644
--- /dev/null
+++ b/src/database/migrations/2023_06_06_100000_create_eventlog_table.php
@@ -0,0 +1,43 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::create(
+ 'eventlog',
+ function (Blueprint $table) {
+ $table->string('id', 36)->primary();
+ $table->string('object_id', 36);
+ $table->string('object_type', 36);
+ $table->tinyInteger('type')->unsigned();
+ $table->string('user_email')->nullable();
+ $table->string('comment', 1024)->nullable();
+ $table->text('data')->nullable(); // json
+ $table->timestamp('created_at')->useCurrent();
+
+ $table->index(['object_id', 'object_type', 'type']);
+ $table->index('created_at');
+ }
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('eventlog');
+ }
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 8:44 PM (20 m, 49 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18839473
Default Alt Text
D4400.1775508244.diff (5 KB)
Attached To
Mode
D4400: Event Log (History)
Attached
Detach File
Event Timeline