1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Updated activities table format

Renamed some columns to be more generic and applicable.
Removed now redundant book_id column.
Allowed nullable entity morph columns for non-entity activity.

Ran tests and made required changes.
This commit is contained in:
Dan Brown
2020-11-08 00:03:19 +00:00
parent ee7e1122d3
commit 712ccd23c4
12 changed files with 106 additions and 50 deletions

View File

@ -5,16 +5,16 @@ namespace BookStack\Actions;
use BookStack\Auth\User;
use BookStack\Entities\Entity;
use BookStack\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* @property string $key
* @property string $type
* @property User $user
* @property Entity $entity
* @property string $extra
* @property string $detail
* @property string $entity_type
* @property int $entity_id
* @property int $user_id
* @property int $book_id
*/
class Activity extends Model
{
@ -32,20 +32,18 @@ class Activity extends Model
/**
* Get the user this activity relates to.
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}
/**
* Returns text from the language files, Looks up by using the
* activity key.
* Returns text from the language files, Looks up by using the activity key.
*/
public function getText()
public function getText(): string
{
return trans('activities.' . $this->key);
return trans('activities.' . $this->type);
}
/**
@ -53,6 +51,6 @@ class Activity extends Model
*/
public function isSimilarTo(Activity $activityB): bool
{
return [$this->key, $this->entity_type, $this->entity_id] === [$activityB->key, $activityB->entity_type, $activityB->entity_id];
return [$this->type, $this->entity_type, $this->entity_id] === [$activityB->type, $activityB->entity_type, $activityB->entity_id];
}
}

View File

@ -12,14 +12,12 @@ use Illuminate\Support\Facades\Log;
class ActivityService
{
protected $activity;
protected $user;
protected $permissionService;
public function __construct(Activity $activity, PermissionService $permissionService)
{
$this->activity = $activity;
$this->permissionService = $permissionService;
$this->user = user();
}
/**
@ -38,8 +36,8 @@ class ActivityService
protected function newActivityForUser(string $type): Activity
{
return $this->activity->newInstance()->forceFill([
'key' => strtolower($type),
'user_id' => $this->user->id,
'type' => strtolower($type),
'user_id' => user()->id,
]);
}
@ -51,9 +49,9 @@ class ActivityService
public function removeEntity(Entity $entity)
{
$entity->activity()->update([
'extra' => $entity->name,
'entity_id' => 0,
'entity_type' => '',
'detail' => $entity->name,
'entity_id' => null,
'entity_type' => null,
]);
}
@ -150,9 +148,9 @@ class ActivityService
/**
* Flashes a notification message to the session if an appropriate message is available.
*/
protected function setNotification(string $activityKey)
protected function setNotification(string $type)
{
$notificationTextKey = 'activities.' . $activityKey . '_notification';
$notificationTextKey = 'activities.' . $type . '_notification';
if (trans()->has($notificationTextKey)) {
$message = trans($notificationTextKey);
session()->flash('success', $message);