fix: enforce unique national ID validation and fix sync updated_at corruption

This commit is contained in:
SajjadMahmoody
2026-04-28 23:31:19 +03:30
parent dc524f1fb6
commit 721ee30948
9 changed files with 77 additions and 186 deletions
+54 -7
View File
@@ -39,17 +39,64 @@
return response()->json($result);
})->name('sync.run');
Route::get('/admin/backup/download', function () {
$zipPath = session('backup_tmp_path');
$zipName = session('backup_tmp_name', 'matab-backup.zip');
Route::get('/backup/download', function () {
set_time_limit(0);
ini_set('memory_limit', '256M');
if (! $zipPath || ! file_exists($zipPath)) {
abort(404, 'Backup file not found.');
$dbPath = database_path('database.sqlite');
if (! file_exists($dbPath)) {
abort(404, 'Database not found.');
}
session()->forget(['backup_tmp_path', 'backup_tmp_name']);
$zipFilename = 'matab-backup-' . now()->format('Y-m-d_H-i-s') . '.zip';
$zipPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $zipFilename;
return response()->download($zipPath, $zipName, [
$zip = new \ZipArchive();
if ($zip->open($zipPath, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) !== true) {
abort(500, 'Could not create zip archive.');
}
$noCompressExts = [
'jpg', 'jpeg', 'png', 'gif', 'webp',
'mp4', 'mov', 'avi', 'mkv', 'webm',
'mp3', 'wav', 'ogg', 'opus', 'm4a',
'zip', 'gz', 'rar', '7z',
];
$addFile = function (string $realPath, string $zipEntry) use ($zip, $noCompressExts): void {
$zip->addFile($realPath, $zipEntry);
$index = $zip->locateName($zipEntry);
$ext = strtolower(pathinfo($realPath, PATHINFO_EXTENSION));
if (in_array($ext, $noCompressExts, true)) {
$zip->setCompressionIndex($index, \ZipArchive::CM_STORE);
} else {
$zip->setCompressionIndex($index, \ZipArchive::CM_DEFLATE, 1);
}
};
$addFile($dbPath, 'database/database.sqlite');
$publicPath = storage_path('app/public');
foreach (['files', 'initials'] as $folder) {
$folderPath = $publicPath . '/' . $folder;
if (! is_dir($folderPath)) {
continue;
}
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($folderPath, \RecursiveDirectoryIterator::SKIP_DOTS),
\RecursiveIteratorIterator::LEAVES_ONLY
);
foreach ($iterator as $file) {
if ($file->isFile()) {
$relativePath = str_replace('\\', '/', substr($file->getPathname(), strlen($folderPath) + 1));
$addFile($file->getPathname(), $folder . '/' . $relativePath);
}
}
}
$zip->close();
return response()->download($zipPath, $zipFilename, [
'Content-Type' => 'application/zip',
])->deleteFileAfterSend(true);
})->name('backup.download');