ringfinger/backend/scripts/repair.php

32 lines
786 B
PHP
Raw Normal View History

<?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;