2019-06-11 02:10:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
2021-01-30 23:05:18 +00:00
|
|
|
use Illuminate\Support\Facades\Cache;
|
2020-12-13 23:08:59 +00:00
|
|
|
use Illuminate\Support\Facades\Redis;
|
2019-06-11 02:10:57 +00:00
|
|
|
use App\Status;
|
2020-12-13 23:08:59 +00:00
|
|
|
//use App\Transformer\Api\v3\StatusTransformer;
|
2019-06-11 02:10:57 +00:00
|
|
|
use App\Transformer\Api\StatusStatelessTransformer;
|
2020-12-13 23:08:59 +00:00
|
|
|
use App\Transformer\Api\StatusTransformer;
|
2019-06-11 02:10:57 +00:00
|
|
|
use League\Fractal;
|
|
|
|
use League\Fractal\Serializer\ArraySerializer;
|
|
|
|
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
|
|
|
|
|
|
|
class StatusService {
|
|
|
|
|
|
|
|
const CACHE_KEY = 'pf:services:status:';
|
|
|
|
|
2021-01-30 23:05:18 +00:00
|
|
|
public static function key($id)
|
2019-06-11 02:10:57 +00:00
|
|
|
{
|
2021-01-30 23:05:18 +00:00
|
|
|
return self::CACHE_KEY . $id;
|
2019-06-11 02:10:57 +00:00
|
|
|
}
|
|
|
|
|
2021-07-27 01:02:11 +00:00
|
|
|
public static function get($id, $publicOnly = true)
|
2019-06-11 02:10:57 +00:00
|
|
|
{
|
2021-07-27 01:02:11 +00:00
|
|
|
return Cache::remember(self::key($id), now()->addDays(7), function() use($id, $publicOnly) {
|
|
|
|
if($publicOnly) {
|
|
|
|
$status = Status::whereScope('public')->find($id);
|
|
|
|
} else {
|
|
|
|
$status = Status::whereIn('scope', ['public', 'private', 'unlisted'])->find($id);
|
|
|
|
}
|
2021-01-30 23:05:18 +00:00
|
|
|
if(!$status) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
$fractal = new Fractal\Manager();
|
|
|
|
$fractal->setSerializer(new ArraySerializer());
|
|
|
|
$resource = new Fractal\Resource\Item($status, new StatusStatelessTransformer());
|
|
|
|
return $fractal->createData($resource)->toArray();
|
|
|
|
});
|
2019-06-11 02:10:57 +00:00
|
|
|
}
|
|
|
|
|
2021-01-30 23:05:18 +00:00
|
|
|
public static function del($id)
|
2019-06-11 02:10:57 +00:00
|
|
|
{
|
2021-07-27 01:02:11 +00:00
|
|
|
Cache::forget('pf:services:sh:id:' . $id);
|
|
|
|
Cache::forget('status:transformer:media:attachments:' . $id);
|
2021-07-06 08:01:24 +00:00
|
|
|
PublicTimelineService::rem($id);
|
2021-01-30 23:05:18 +00:00
|
|
|
return Cache::forget(self::key($id));
|
2019-06-11 02:10:57 +00:00
|
|
|
}
|
2021-07-06 08:01:24 +00:00
|
|
|
}
|