Files
citrus-cms/resources/views/cron/pdf-db-document-procedure-sync.blade.php
2026-04-28 21:15:09 +03:00

83 lines
1.7 KiB
PHP

<?php
$table = "document_procedures";
$mainPath = "004_QA/0018_Procedure";
$nullDownload = db($table);
if(isset($fileName)) {
$nullDownload = $nullDownload->where("document_no", $fileName);
$commitSize = 1;
}
$nullDownload = $nullDownload->get();
//dump($nullDownload->count());
DB::beginTransaction();
if(!isset($commitSize)) {
$commitSize = 1000;
}
$say = 0;
$k = 0;
Log::debug("📄$table PDF Link to DB Start " . simdi());
try {
foreach($nullDownload AS $ne) {
$data = "{$ne->document_no}";
$data = str_replace("/", "*", $data);
$data = str_replace(" ", "*", $data);
if(trim($data) != "") {
$path = "storage/documents/$mainPath/*$data*.pdf";
$searchPDF = glob($path);
$updateData = [];
$updateData['download'] = null;
if(isset($searchPDF[0])) {
$updateData['download'] = $searchPDF[0];
}
// //dump($updateData);
db($table)
->where("id", $ne->id)
->update($updateData);
$k++;
if($say == $commitSize) {
//dump("commmit");
DB::commit();
DB::beginTransaction();
$say = 0;
}
$say++;
}
}
DB::commit();
Log::debug("$table update PDF link for $k rows");
//dump("$table update PDF link for $k rows");
} catch (\Throwable $th) {
DB::rollback();
Log::error("not update PDF links " . $th->getMessage());
////dump($th->getMessage());
}
Log::debug("📄$table PDF Link to DB Finish " . simdi());
?>