Repository navigation
Expand file tree
/
Copy pathDeleteCommitContent.php
More file actions
49 lines (37 loc) · 1.84 KB
/
Copy pathDeleteCommitContent.php
File metadata and controls
49 lines (37 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
declare(strict_types=1);
namespace App\Actions;
use App\Models\Commit;
use App\Models\Headline;
use App\Models\LinkPreview;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
final readonly class DeleteCommitContent
{
/**
* Only a commit whose undo window has closed loses its content, so one restored in time, or deleted again since, keeps it.
* The row stays as a tombstone with its author, for its replies, quotes and reports, but its body, mentions, embedding,
* link preview, poll and images are erased for good. So are the previews of links to it, which hold its body as their
* title and description, and fall off whatever linked to it.
*/
public function handle(Commit $commit): void
{
$imagePaths = DB::transaction(function () use ($commit): array {
$commit = Commit::withTrashed()->lockForUpdate()->find($commit->id);
if (! $commit instanceof Commit || ! $commit->trashed() || $commit->isRestorable()) {
return [];
}
$imagePaths = $commit->images()->pluck('path')->all();
$commit->images()->delete();
$commit->poll()->delete();
LinkPreview::query()->where('url', 'like', "%/commits/{$commit->id}%")->delete();
DB::table('commit_topics')->where('commit_id', $commit->id)->delete();
Headline::query()->whereIn('id', DB::table('commit_headline')->select('headline_id')->where('commit_id', $commit->id))
->update(['summary' => null, 'summary_created_at' => null]);
$commit->headlines()->detach();
$commit->update(['body' => '', 'mentions' => null, 'embedding' => null, 'link_preview_id' => null, 'headlines_classified_at' => null]);
return $imagePaths;
});
Storage::disk()->delete($imagePaths);
}
}