2019-07-01 04:38:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Observers;
|
|
|
|
|
2022-12-27 11:16:34 +00:00
|
|
|
use DB;
|
2019-07-01 04:38:26 +00:00
|
|
|
use App\StatusHashtag;
|
|
|
|
use App\Services\StatusHashtagService;
|
|
|
|
|
|
|
|
class StatusHashtagObserver
|
|
|
|
{
|
2022-09-27 05:58:15 +00:00
|
|
|
/**
|
|
|
|
* Handle events after all transactions are committed.
|
|
|
|
*
|
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
public $afterCommit = true;
|
|
|
|
|
2019-07-01 04:38:26 +00:00
|
|
|
/**
|
|
|
|
* Handle the notification "created" event.
|
|
|
|
*
|
|
|
|
* @param \App\Notification $notification
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function created(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
2022-12-27 11:16:34 +00:00
|
|
|
DB::table('hashtags')->where('id', $hashtag->hashtag_id)->increment('cached_count');
|
2019-07-01 04:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "updated" event.
|
|
|
|
*
|
|
|
|
* @param \App\Notification $notification
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function updated(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "deleted" event.
|
|
|
|
*
|
|
|
|
* @param \App\Notification $notification
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function deleted(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id);
|
2022-12-27 11:16:34 +00:00
|
|
|
DB::table('hashtags')->where('id', $hashtag->hashtag_id)->decrement('cached_count');
|
2019-07-01 04:38:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "restored" event.
|
|
|
|
*
|
|
|
|
* @param \App\Notification $notification
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function restored(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::set($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the notification "force deleted" event.
|
|
|
|
*
|
|
|
|
* @param \App\Notification $notification
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function forceDeleted(StatusHashtag $hashtag)
|
|
|
|
{
|
|
|
|
StatusHashtagService::del($hashtag->hashtag_id, $hashtag->status_id);
|
|
|
|
}
|
|
|
|
}
|