mirror of
https://github.com/flarum/core.git
synced 2025-08-11 19:04:29 +02:00
Database changes (#15)
* Implement database changes * Split foreign keys into their own migration * Use whereColumn * Rename flag.time * Rename forum.flagCount * Rename forum.newFlagCount
This commit is contained in:
committed by
Franz Liedke
parent
f218f14160
commit
ec60fed381
@@ -41,12 +41,12 @@ class ListFlagsController extends AbstractListController
|
||||
{
|
||||
$actor = $request->getAttribute('actor');
|
||||
|
||||
$actor->flags_read_time = time();
|
||||
$actor->read_flags_at = time();
|
||||
$actor->save();
|
||||
|
||||
return Flag::whereVisibleTo($actor)
|
||||
->with($this->extractInclude($request))
|
||||
->latest('flags.time')
|
||||
->latest('flags.created_at')
|
||||
->groupBy('post_id')
|
||||
->get();
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ class FlagSerializer extends AbstractSerializer
|
||||
'type' => $flag->type,
|
||||
'reason' => $flag->reason,
|
||||
'reasonDetail' => $flag->reason_detail,
|
||||
'time' => $this->formatDate($flag->time),
|
||||
'createdAt' => $this->formatDate($flag->created_at),
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -65,7 +65,7 @@ class CreateFlagHandler
|
||||
$flag->type = 'user';
|
||||
$flag->reason = array_get($data, 'attributes.reason');
|
||||
$flag->reason_detail = array_get($data, 'attributes.reasonDetail');
|
||||
$flag->time = time();
|
||||
$flag->created_at = time();
|
||||
|
||||
$flag->save();
|
||||
|
||||
|
@@ -23,12 +23,7 @@ class Flag extends AbstractModel
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $table = 'flags';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $dates = ['time'];
|
||||
protected $dates = ['created_at'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
|
@@ -51,7 +51,7 @@ class AddFlagsApi
|
||||
public function configureModelDates(ConfigureModelDates $event)
|
||||
{
|
||||
if ($event->isModel(User::class)) {
|
||||
$event->dates[] = 'flags_read_time';
|
||||
$event->dates[] = 'read_flags_at';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,14 +64,14 @@ class AddFlagsApi
|
||||
$event->attributes['canViewFlags'] = $event->actor->hasPermissionLike('discussion.viewFlags');
|
||||
|
||||
if ($event->attributes['canViewFlags']) {
|
||||
$event->attributes['flagsCount'] = (int) $this->getFlagsCount($event->actor);
|
||||
$event->attributes['flagCount'] = (int) $this->getFlagCount($event->actor);
|
||||
}
|
||||
|
||||
$event->attributes['guidelinesUrl'] = $this->settings->get('flarum-flags.guidelines_url');
|
||||
}
|
||||
|
||||
if ($event->isSerializer(CurrentUserSerializer::class)) {
|
||||
$event->attributes['newFlagsCount'] = (int) $this->getNewFlagsCount($event->model);
|
||||
$event->attributes['newFlagCount'] = (int) $this->getNewFlagCount($event->model);
|
||||
}
|
||||
|
||||
if ($event->isSerializer(PostSerializer::class)) {
|
||||
@@ -83,7 +83,7 @@ class AddFlagsApi
|
||||
* @param User $actor
|
||||
* @return int
|
||||
*/
|
||||
protected function getFlagsCount(User $actor)
|
||||
protected function getFlagCount(User $actor)
|
||||
{
|
||||
return Flag::whereVisibleTo($actor)->distinct()->count('flags.post_id');
|
||||
}
|
||||
@@ -92,12 +92,12 @@ class AddFlagsApi
|
||||
* @param User $actor
|
||||
* @return int
|
||||
*/
|
||||
protected function getNewFlagsCount(User $actor)
|
||||
protected function getNewFlagCount(User $actor)
|
||||
{
|
||||
$query = Flag::whereVisibleTo($actor);
|
||||
|
||||
if ($time = $actor->flags_read_time) {
|
||||
$query->where('flags.time', '>', $time);
|
||||
if ($time = $actor->read_flags_at) {
|
||||
$query->where('flags.created_at', '>', $time);
|
||||
}
|
||||
|
||||
return $query->distinct()->count('flags.post_id');
|
||||
|
Reference in New Issue
Block a user