first
This commit is contained in:
67
app/Http/Controllers/User/TranscriptVersionController.php
Normal file
67
app/Http/Controllers/User/TranscriptVersionController.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\TranscriptVersion;
|
||||
use App\Models\TranscriptionProject;
|
||||
use App\Services\AuditLogService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class TranscriptVersionController extends Controller
|
||||
{
|
||||
public function index(TranscriptionProject $project): View
|
||||
{
|
||||
$this->authorize('viewVersionHistory', $project);
|
||||
|
||||
$versions = $project->transcriptVersions()
|
||||
->with('editor')
|
||||
->orderByDesc('version_number')
|
||||
->paginate(20);
|
||||
|
||||
return view('user.projects.versions', compact('project', 'versions'));
|
||||
}
|
||||
|
||||
public function restore(
|
||||
TranscriptionProject $project,
|
||||
TranscriptVersion $version,
|
||||
AuditLogService $audit
|
||||
): RedirectResponse {
|
||||
$this->authorize('restoreVersion', $project);
|
||||
|
||||
// Pastikan versi ini milik projek ini
|
||||
abort_if($version->project_id !== $project->id, 404);
|
||||
|
||||
$oldText = $project->transcript_text;
|
||||
$nextVersion = ($project->transcriptVersions()->max('version_number') ?? 0) + 1;
|
||||
|
||||
TranscriptVersion::create([
|
||||
'project_id' => $project->id,
|
||||
'edited_by' => Auth::id(),
|
||||
'version_number' => $nextVersion,
|
||||
'old_text' => $oldText,
|
||||
'new_text' => $version->new_text,
|
||||
'change_summary' => "Dipulihkan dari versi {$version->version_number}",
|
||||
'created_at' => now(),
|
||||
]);
|
||||
|
||||
$project->update([
|
||||
'transcript_text' => $version->new_text,
|
||||
'transcription_status' => 'completed',
|
||||
]);
|
||||
|
||||
$audit->log('transcript_version_restored', [
|
||||
'project_id' => $project->id,
|
||||
'new_values' => [
|
||||
'restored_from_version' => $version->version_number,
|
||||
'new_version' => $nextVersion,
|
||||
],
|
||||
]);
|
||||
|
||||
return redirect()
|
||||
->route('user.projects.show', $project)
|
||||
->with('success', "Versi {$version->version_number} berjaya dipulihkan.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user