İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
<?php function addRowInTableTpCreator($search, $selectDocument, $fullFolder, $lineNumber, $documentDate, $rowNo)
|
||||
{
|
||||
Log::debug("➡️ addRowInTableTpCreator called with parameters:");
|
||||
Log::debug("📄 Has search results: " . (isset($search[0]) ? "Yes" : "No"));
|
||||
Log::debug("📑 Document title: " . $selectDocument['title2']);
|
||||
Log::debug("📁 Folder: " . $fullFolder);
|
||||
Log::debug("🔢 Line number: " . $lineNumber);
|
||||
Log::debug("📅 Document date: " . $documentDate);
|
||||
Log::debug("🔢 Row number: " . $rowNo);
|
||||
|
||||
$constructor = Cache::get("rc_contractor");
|
||||
$firstPage = Cache::get("rc_firstPage");
|
||||
$lastPage = Cache::get("rc_lastPage");
|
||||
/*
|
||||
Log::info("firstPage $firstPage");
|
||||
Log::info("lastPage $lastPage");
|
||||
*/
|
||||
|
||||
$rowTitle = $selectDocument['title2'];
|
||||
|
||||
if(isset($selectDocument['title3'])) {
|
||||
$rowTitle = $selectDocument['title3'];
|
||||
$selectDocument['title2'] = $selectDocument['title3'];
|
||||
}
|
||||
|
||||
if(isset($selectDocument['title4'])) {
|
||||
$rowTitle = $selectDocument['title4'];
|
||||
}
|
||||
|
||||
|
||||
if(isset($search[0])) {
|
||||
|
||||
$order = $selectDocument['order'] + 1;
|
||||
@mkdir($fullFolder, 0777, true);
|
||||
Log::info("creating folder $fullFolder");
|
||||
|
||||
$addInLineNumber = ['по сварке трубопроводов(ЖСР)'];
|
||||
if(in_array($selectDocument['title2'], $addInLineNumber)) {
|
||||
$fileName = "$order - {$selectDocument['title2']} - $lineNumber.pdf";
|
||||
$fullPath = "$fullFolder"."$fileName";
|
||||
Log::debug("🔖 Special case file name with line number: " . $fileName);
|
||||
} else {
|
||||
$fileName = "$order - {$selectDocument['title2']}.pdf";
|
||||
$fullPath = "$fullFolder"."$fileName";
|
||||
Log::debug("🔖 Standard file name: " . $fileName);
|
||||
}
|
||||
|
||||
$documentDate = df($documentDate);
|
||||
$output = null;
|
||||
$returnValue = null;
|
||||
$allPath = "{$search[0]}";
|
||||
/*
|
||||
$command = "pdftk '$allPath' dump_data | grep NumberOfPages";
|
||||
// dump($command);
|
||||
// dump($allPath);
|
||||
putenv('LANG=ru_RU.UTF-8');
|
||||
|
||||
$output = shell_exec($command);
|
||||
|
||||
|
||||
try {
|
||||
$pageCount = (int) trim(explode(" ", $output)[1]);
|
||||
} catch (\Throwable $th) {
|
||||
$pageCount = 1;
|
||||
}
|
||||
|
||||
if($firstPage == 0) {
|
||||
$firstPage = 1;
|
||||
} else {
|
||||
$firstPage = $lastPage + 1;
|
||||
}
|
||||
|
||||
// Son sayfa numarasını hesapla
|
||||
$lastPage = $firstPage + $pageCount - 1;
|
||||
|
||||
Cache::put("rc_lastPage", $lastPage);
|
||||
Cache::put("rc_firstPage", $firstPage);
|
||||
|
||||
// Sayfa aralığını oluştur
|
||||
$pageIndex = ($firstPage == $lastPage) ? $firstPage : "$firstPage - $lastPage";
|
||||
|
||||
|
||||
|
||||
|
||||
$tableRow = "
|
||||
<tr class='bordered'>
|
||||
<td >$rowNo</td>
|
||||
<td width='50%' colspan='2'>$rowTitle</td>
|
||||
<td>$lineNumber</td>
|
||||
<td>$documentDate</td>
|
||||
<td>$constructor</td>
|
||||
<td>$pageCount</td>
|
||||
<td>$pageIndex</td>
|
||||
</tr>
|
||||
|
||||
";
|
||||
*/
|
||||
|
||||
$search[0] = str_replace("storage/documents/", "", $search[0]);
|
||||
$fullFolder = str_replace("storage/documents/", "", $fullFolder);
|
||||
$fullPath = $fullFolder . basename($fileName);
|
||||
Log::debug("🛠️ File path processing:");
|
||||
Log::debug("📄 Original source path: storage/documents/" . $search[0]);
|
||||
Log::debug("📁 Original folder path: storage/documents/" . $fullFolder);
|
||||
Log::debug("📄 Target filename: " . basename($fileName));
|
||||
Log::debug("📄 Final target path: " . $fullPath);
|
||||
/*
|
||||
Log::info("fullPath: " . $fullPath);
|
||||
Log::info("search: " . $search[0]);
|
||||
Log::info("fullFolder: " . $fullFolder);
|
||||
*/
|
||||
|
||||
try {
|
||||
if(Storage::exists($fullPath)) {
|
||||
$currentContent = md5(Storage::get($fullPath));
|
||||
$newContent = md5(Storage::get($search[0]));
|
||||
|
||||
Log::debug("📁 Checking file: " . $fullPath);
|
||||
Log::debug("🔑 Current content MD5: " . $currentContent);
|
||||
Log::debug("🔑 New content MD5: " . $newContent);
|
||||
|
||||
if ($currentContent !== $newContent) {
|
||||
$log = "🔃✅".$search[0] . " old file deleted and new file copied" . "\n";
|
||||
Log::debug("📝 " . $log);
|
||||
Storage::delete($fullPath);
|
||||
Storage::copy($search[0], $fullPath);
|
||||
|
||||
} else {
|
||||
$log = "🟰" . $search[0] . " already same file, not copied" . "\n";
|
||||
Log::debug("📝 " . $log);
|
||||
}
|
||||
} else {
|
||||
$log = "✅".$search[0] . " file copied" . "\n";
|
||||
Log::debug("📝 " . $log);
|
||||
Storage::copy($search[0], $fullPath);
|
||||
}
|
||||
|
||||
echo($log);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
$log = "❌" . $search[0] . " error ---> \n " . $th->getMessage() . "\n";
|
||||
echo($log);
|
||||
Log::debug("❌ Error copying file: " . $search[0]);
|
||||
Log::debug("❌ Error message: " . $th->getMessage());
|
||||
Log::debug("❌ Error trace: " . $th->getTraceAsString());
|
||||
}
|
||||
|
||||
|
||||
Storage::append($fullFolder . 'log.txt', $log);
|
||||
Log::debug("📜 Appended to log file: " . $fullFolder . 'log.txt');
|
||||
Log::debug("📜 Log entry: " . $log);
|
||||
|
||||
$return = null; //= $tableRow;
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
$log = "❓$rowTitle - $lineNumber not found " . "\n";
|
||||
echo($log);
|
||||
Log::debug("❓ Document not found: " . $rowTitle . " - " . $lineNumber);
|
||||
Log::debug("❓ Search path likely was: storage/documents/{$selectDocument['path']}/*{$lineNumber}*.pdf");
|
||||
$fullFolder = str_replace("storage/documents/", "", $fullFolder);
|
||||
Storage::append($fullFolder . 'log.txt', $log);
|
||||
Log::debug("📜 Appended to log file: " . $fullFolder . 'log.txt');
|
||||
$return = null;
|
||||
}
|
||||
|
||||
return $return;
|
||||
} ?>
|
||||
Reference in New Issue
Block a user