Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions app/Http/Controllers/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,29 @@ public function check()
'403 Forbidden'
);

// Get all documents
$documents = Document::all();
// Get all documents with computed metadata
$documents = Document::all()->map(function ($doc) {
$filePath = storage_path('docs/' . $doc->id);
$fileExists = file_exists($filePath);

// Add computed attributes to document object
$doc->file_exists = $fileExists;
$doc->link_count = 0;
$doc->hash_valid = false;

if ($fileExists) {
$stats = stat($filePath);
if ($stats !== false) {
$doc->link_count = $stats['nlink'] ?? 0;
}
$computedHash = hash_file('sha256', $filePath);
$doc->hash_valid = $computedHash !== false && $doc->hash !== null && hash_equals($doc->hash, $computedHash);
}
Comment thread
dbarzin marked this conversation as resolved.

return $doc;
});

// show view
// Show view with pre-computed metadata
return view('/documents/check')
->with('documents', $documents);
}
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/de/cruds.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@
'control' => 'Kontrolle',
'size' => 'Größe',
'hash' => 'Hashwert',
'links' => 'Links',
'status' => 'Überprüfen',
],
'model' => [
'control' => 'Vorlage Kontrollblatt',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/cruds.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
'control' => 'Control',
'size' => 'Size',
'hash' => 'Hash',
'links' => 'Links',
'status' => 'Check status',
],
'model' => [
'control' => 'Control sheet template',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/fr/cruds.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
'control' => 'Contrôle',
'size' => 'Taille',
'hash' => 'Hash',
'links' => 'Liens',
'status' => 'Vérification',
],
'model' => [
'control' => 'Modèle de fiche de contrôle',
Expand Down
38 changes: 22 additions & 16 deletions resources/views/documents/check.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,43 @@
<th>{{ trans('cruds.document.fields.name') }}</th>
<th>{{ trans('cruds.document.fields.size') }}</th>
<th>{{ trans('cruds.document.fields.hash') }}</th>
<th>{{ trans('cruds.document.fields.links') }}</th>
<th>{{ trans('cruds.document.fields.status') }}</th>
</tr>
</thead>

@foreach ($documents as $doc)
<tr>
<td>
{{ $doc->id }}
</td>
<td>{{ $doc->id }}</td>
<td class="text-center">
<a href="/bob/show/{{ $doc->control_id }}">{{ $doc->control_id }}</a>
</td>
<td>
<a href="/doc/show/{{ $doc->id }}">{{ substr($doc->filename,0,32) }}</a>
<a href="/doc/show/{{ $doc->id }}">{{ substr($doc->filename, 0, 32) }}</a>
</td>
<td>
{{ \Illuminate\Support\Number::fileSize($doc->size) }}
</td>
<td>
{{ $doc->hash }}
<br>
<td>{{ \Illuminate\Support\Number::fileSize($doc->size) }}</td>
<td><small>{{ $doc->hash }}</small></td>
<td class="text-center">
@if ($doc->file_exists)
@if ($doc->link_count > 1)
<span class="badge bg-blue">{{ $doc->link_count }}</span>
@else
{{ $doc->link_count }}
@endif
@else
-
@endif
</td>
<td>
<b>
@if (file_exists(storage_path('docs/').$doc->id))
@if ($doc->hash == hash_file("sha256", storage_path('docs/').$doc->id))
<font color="green">OK</font>
@if ($doc->file_exists)
@if ($doc->hash_valid)
<span style="color: green;">OK</span>
@else
<font color="red">HASH FAILS</font>
<span style="color: red">HASH FAILS</span>
@endif
@else
<font color="red">MISSING</font>
<span style="color: red">MISSING</span>
@endif
</b>
</td>
Expand All @@ -50,4 +56,4 @@
</table>
</div>

@endsection
@endsection