38
app/Console/Commands/CalculateAllHashes.php
Normal file
38
app/Console/Commands/CalculateAllHashes.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Helpers\HashesHelpers;
|
||||
use App\Models\EntryHash;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Signature('hashes:calculate')]
|
||||
#[Description('Recalculate all hashes for EntryHashes')]
|
||||
class CalculateAllHashes extends Command
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
EntryHash::where('verified', '=', 'TBD')->cursor()->each(function ($entryHash) {
|
||||
if( ( $hash = HashesHelpers::findHashes( $entryHash->hash_sha1 ) ) !== null ){
|
||||
$entryHash->filename = $hash->filename;
|
||||
$entryHash->hash_crc32 = $hash->crc32;
|
||||
$entryHash->hash_sha1 = $hash->sha1;
|
||||
$entryHash->verified = HashesHelpers::getReferenceName( $hash->dat_reference_id );
|
||||
$entryHash->save();
|
||||
} else {
|
||||
if( !$entryHash->hash_crc32 || !$entryHash->hash_sha1 )
|
||||
$entryHash->delete();
|
||||
else {
|
||||
if (!$entryHash->filename)
|
||||
$entryHash->filename = "Unknown";
|
||||
$entryHash->verified = 'No';
|
||||
$entryHash->save();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$this->info('Hashes calculated');
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,9 @@ class StoreEntryRequest extends FormRequest
|
||||
$rules['new-game-genre'] = 'required_with:new-game-title|integer|nullable|exists:genres,id';
|
||||
}
|
||||
|
||||
if( section_must_be( ['translations', 'romhacks'], $section ) ){
|
||||
$bypassHashes = $isEdit && $this->user()->can('moderate', $this->route('entry') ) && ($this->input('bypass_hashes') !== null);
|
||||
|
||||
if( section_must_be( ['translations', 'romhacks'], $section ) && !$bypassHashes ){
|
||||
$rules['hashes'] = 'array|required|min:1';
|
||||
$rules['hashes.*.filename'] = 'required|string|max:512';
|
||||
$rules['hashes.*.hash_crc32'] = 'required|string|max:512';
|
||||
|
||||
@@ -34,7 +34,8 @@ class HashesUpload extends Component
|
||||
public function mount( array $oldHashes = [] ): void
|
||||
{
|
||||
foreach ($oldHashes as $hash) {
|
||||
$this->addHash( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] );
|
||||
if( isset( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] ) )
|
||||
$this->addHash( $hash['filename'], $hash['hash_crc32'], $hash['hash_sha1'], $hash['verified'] );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -234,6 +234,9 @@
|
||||
@if( section_must_be(['romhacks', 'homebrew'], $section ) )
|
||||
<label><input class="form-checkbox" type="checkbox" name="nsfw-entry" value="1" {{ old('nsfw-entry', $entry->nsfw ) ? 'checked' : '' }}>NSFW</label>
|
||||
@endif
|
||||
@if( section_must_be( ['romhacks', 'translations'], $section ) )
|
||||
<label><input class="form-checkbox" type="checkbox" name="bypass_hashes" value="1">Bypass hashes requirements</label>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
|
||||
Reference in New Issue
Block a user