Debugging of fingerprint deletion and QR code repair script added
This commit is contained in:
parent
f2957ab4ad
commit
0334c7022d
3
Makefile
3
Makefile
|
@ -1,3 +1,6 @@
|
|||
repair:
|
||||
php backend/scripts/repair.php
|
||||
|
||||
setup:
|
||||
php backend/scripts/setup.php
|
||||
|
||||
|
|
|
@ -24,8 +24,15 @@ final class FingerprintDeleteController extends AbstractController
|
|||
}
|
||||
|
||||
try {
|
||||
$fingerprint = new Fingerprint($this->fingerprintId);
|
||||
$db = new MySqlDatabase();
|
||||
$db->startTransaction();
|
||||
|
||||
$fingerprint = new Fingerprint($this->fingerprintId, $db);
|
||||
$qrCode = new QrCode($fingerprint->getFingerprintId(), $fingerprint->getFingerprint());
|
||||
$fingerprint->Delete();
|
||||
$qrCode->delete();
|
||||
|
||||
$db->commit();
|
||||
|
||||
$this->response = new ApiJsonResponse();
|
||||
} catch (Throwable $e) {
|
||||
|
|
|
@ -24,11 +24,7 @@ final class QrCode
|
|||
|
||||
$returnCode = 0;
|
||||
|
||||
$path = substr(Setting::PATH_QR_CODES, -1) === '/'
|
||||
? Setting::PATH_QR_CODES
|
||||
: Setting::PATH_QR_CODES . '/';
|
||||
|
||||
$filename = $path . $this->fingerprintId . '.svg';
|
||||
$filename = $this->getFilePath();
|
||||
|
||||
passthru(
|
||||
sprintf('mv %s %s', $this->temporaryFilename, $filename),
|
||||
|
@ -42,6 +38,19 @@ final class QrCode
|
|||
}
|
||||
}
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
$filepath = $this->getFilePath();
|
||||
|
||||
if (!is_file($filepath)) {
|
||||
throw new QrCodeException(sprintf('Qr code file %s not found!', $filepath));
|
||||
}
|
||||
|
||||
if (!unlink($filepath)) {
|
||||
throw new QrCodeException('Couldn\'t delete %s!', $filepath);
|
||||
}
|
||||
}
|
||||
|
||||
public function generate(): bool
|
||||
{
|
||||
$returnCode = 0;
|
||||
|
@ -58,10 +67,24 @@ final class QrCode
|
|||
return !(bool)$returnCode;
|
||||
}
|
||||
|
||||
public function hasFile(): bool
|
||||
{
|
||||
return is_file($this->getFilePath());
|
||||
}
|
||||
|
||||
private function generateTemporaryFilename(): string
|
||||
{
|
||||
$hash = hash('md5', (new DateTime())->format('U') . $this->fingerprint);
|
||||
|
||||
return sprintf('%s.svg', $hash);
|
||||
}
|
||||
|
||||
private function getFilePath(): string
|
||||
{
|
||||
$path = substr(Setting::PATH_QR_CODES, -1) === '/'
|
||||
? Setting::PATH_QR_CODES
|
||||
: Setting::PATH_QR_CODES . '/';
|
||||
|
||||
return $path . $this->fingerprintId . '.svg';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
require 'backend/classes/core/Autoloader.php';
|
||||
|
||||
$autoloader = new Autoloader();
|
||||
|
||||
echo 'Checking for missing qr codes...' . PHP_EOL;
|
||||
|
||||
$db = new MySqlDatabase();
|
||||
|
||||
$countForMissing = 0;
|
||||
|
||||
foreach ($db->Select(Fingerprint::class, [Fingerprint::FIELD_ID]) as $record) {
|
||||
$fingerprint = new Fingerprint((int)$record[Fingerprint::FIELD_ID], $db);
|
||||
|
||||
$qrCode = new QrCode($fingerprint->getFingerprintId(), $fingerprint->getFingerprint());
|
||||
|
||||
if (!$qrCode->hasFile()) {
|
||||
$countForMissing++;
|
||||
|
||||
$qrCode->generate();
|
||||
$qrCode->save();
|
||||
|
||||
echo sprintf("\t=> Missing QR code for fingerprint %d generated.\n", $fingerprint->getFingerprintId());
|
||||
}
|
||||
}
|
||||
|
||||
echo $countForMissing === 0
|
||||
? 'No missing QR codes found.' . PHP_EOL
|
||||
: sprintf('%d missing QR code(s) fixed.', $countForMissing) . PHP_EOL;
|
||||
|
Loading…
Reference in New Issue