Skip to content

Commit 636bb56

Browse files
authored
Merge pull request #564 from dbarzin/dev
add link count
2 parents 4891b3b + fdaae24 commit 636bb56

File tree

5 files changed

+50
-19
lines changed

5 files changed

+50
-19
lines changed

app/Http/Controllers/DocumentController.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,29 @@ public function check()
270270
'403 Forbidden'
271271
);
272272

273-
// Get all documents
274-
$documents = Document::all();
273+
// Get all documents with computed metadata
274+
$documents = Document::all()->map(function ($doc) {
275+
$filePath = storage_path('docs/' . $doc->id);
276+
$fileExists = file_exists($filePath);
277+
278+
// Add computed attributes to document object
279+
$doc->file_exists = $fileExists;
280+
$doc->link_count = 0;
281+
$doc->hash_valid = false;
282+
283+
if ($fileExists) {
284+
$stats = stat($filePath);
285+
if ($stats !== false) {
286+
$doc->link_count = $stats['nlink'] ?? 0;
287+
}
288+
$computedHash = hash_file('sha256', $filePath);
289+
$doc->hash_valid = $computedHash !== false && $doc->hash !== null && hash_equals($doc->hash, $computedHash);
290+
}
291+
292+
return $doc;
293+
});
275294

276-
// show view
295+
// Show view with pre-computed metadata
277296
return view('/documents/check')
278297
->with('documents', $documents);
279298
}

resources/lang/de/cruds.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@
178178
'control' => 'Kontrolle',
179179
'size' => 'Größe',
180180
'hash' => 'Hashwert',
181+
'links' => 'Links',
182+
'status' => 'Überprüfen',
181183
],
182184
'model' => [
183185
'control' => 'Vorlage Kontrollblatt',

resources/lang/en/cruds.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@
180180
'control' => 'Control',
181181
'size' => 'Size',
182182
'hash' => 'Hash',
183+
'links' => 'Links',
184+
'status' => 'Check status',
183185
],
184186
'model' => [
185187
'control' => 'Control sheet template',

resources/lang/fr/cruds.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@
179179
'control' => 'Contrôle',
180180
'size' => 'Taille',
181181
'hash' => 'Hash',
182+
'links' => 'Liens',
183+
'status' => 'Vérification',
182184
],
183185
'model' => [
184186
'control' => 'Modèle de fiche de contrôle',

resources/views/documents/check.blade.php

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,43 @@
1111
<th>{{ trans('cruds.document.fields.name') }}</th>
1212
<th>{{ trans('cruds.document.fields.size') }}</th>
1313
<th>{{ trans('cruds.document.fields.hash') }}</th>
14+
<th>{{ trans('cruds.document.fields.links') }}</th>
15+
<th>{{ trans('cruds.document.fields.status') }}</th>
1416
</tr>
1517
</thead>
1618

1719
@foreach ($documents as $doc)
1820
<tr>
19-
<td>
20-
{{ $doc->id }}
21-
</td>
21+
<td>{{ $doc->id }}</td>
2222
<td class="text-center">
2323
<a href="/bob/show/{{ $doc->control_id }}">{{ $doc->control_id }}</a>
2424
</td>
2525
<td>
26-
<a href="/doc/show/{{ $doc->id }}">{{ substr($doc->filename,0,32) }}</a>
26+
<a href="/doc/show/{{ $doc->id }}">{{ substr($doc->filename, 0, 32) }}</a>
2727
</td>
28-
<td>
29-
{{ \Illuminate\Support\Number::fileSize($doc->size) }}
30-
</td>
31-
<td>
32-
{{ $doc->hash }}
33-
<br>
28+
<td>{{ \Illuminate\Support\Number::fileSize($doc->size) }}</td>
29+
<td><small>{{ $doc->hash }}</small></td>
30+
<td class="text-center">
31+
@if ($doc->file_exists)
32+
@if ($doc->link_count > 1)
33+
<span class="badge bg-blue">{{ $doc->link_count }}</span>
34+
@else
35+
{{ $doc->link_count }}
36+
@endif
37+
@else
38+
-
39+
@endif
3440
</td>
3541
<td>
3642
<b>
37-
@if (file_exists(storage_path('docs/').$doc->id))
38-
@if ($doc->hash == hash_file("sha256", storage_path('docs/').$doc->id))
39-
<font color="green">OK</font>
43+
@if ($doc->file_exists)
44+
@if ($doc->hash_valid)
45+
<span style="color: green;">OK</span>
4046
@else
41-
<font color="red">HASH FAILS</font>
47+
<span style="color: red">HASH FAILS</span>
4248
@endif
4349
@else
44-
<font color="red">MISSING</font>
50+
<span style="color: red">MISSING</span>
4551
@endif
4652
</b>
4753
</td>
@@ -50,4 +56,4 @@
5056
</table>
5157
</div>
5258

53-
@endsection
59+
@endsection

0 commit comments

Comments
 (0)