From cbe2709916327baff76daf3f28af41d799a0206d Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Tue, 14 Oct 2025 15:11:21 +0300 Subject: [PATCH] =?utf8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?utf8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 4 ++-- erp24/helpers/File.php | 26 ++++++++++++++++++++--- erp24/records/WriteOffsErp.php | 5 +++++ erp24/views/write_offs_erp/_form.php | 2 +- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index c2415697..475c2e3d 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -73,8 +73,8 @@ class DataController extends BaseController const OUT_DIR = // __DIR__ . "/../json"; - // "/www/api2/json"; - "/var/www/erp24/api2/json"; + "/www/api2/json"; + //"/var/www/erp24/api2/json"; // "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json"; private static function getPathJson() diff --git a/erp24/helpers/File.php b/erp24/helpers/File.php index e21a8598..8c24c950 100644 --- a/erp24/helpers/File.php +++ b/erp24/helpers/File.php @@ -114,6 +114,12 @@ class File extends FileHelper } $substr = substr($filename, 0, 2); $imagePath = self::filepath($filename, 'images'); + + // Если оригинальный файл не существует, возвращаем заглушку + if (!$imagePath) { + return 'file_not_found'; + } + $uploadDir = \Yii::getAlias('@uploads'); $uploadPathDir = 'uploads'; $resizePath = $uploadPathDir . "/images/resize/{$substr}/{$w}_{$h}_{$quality}"; @@ -122,13 +128,27 @@ class File extends FileHelper $resizedFile = "{$resizedPath}/{$filename}"; if (!file_exists($imagePath ?? '')) { - $filePath = self::src($filename); - self::ResizeImage($filePath, $w, $h, $quality); + try { + $filePath = self::src($filename); + self::ResizeImage($filePath, $w, $h, $quality); + } catch (\Exception $e) { + // Если не удалось обработать изображение, возвращаем заглушку + return 'file_processing_error'; + } } self::createDirectory($resizedPath); if (!file_exists($resizedFile) && !empty($imagePath)) { - ImageHelper::resizeImage($imagePath, $resizedFile, $w, $h, $quality); + try { + // Дополнительная проверка на возможность чтения файла + if (!is_readable($imagePath)) { + return 'file_not_readable'; + } + ImageHelper::resizeImage($imagePath, $resizedFile, $w, $h, $quality); + } catch (\Exception $e) { + // Если не удалось обработать изображение, возвращаем заглушку + return 'file_processing_error'; + } } return $resizedUrl; } diff --git a/erp24/records/WriteOffsErp.php b/erp24/records/WriteOffsErp.php index 60b07e96..8d97104b 100644 --- a/erp24/records/WriteOffsErp.php +++ b/erp24/records/WriteOffsErp.php @@ -747,6 +747,11 @@ class WriteOffsErp extends \yii\db\ActiveRecord $relaFileName = File::getRealName($image->image_id); if (!empty($modelImage->size)) { $imageThumbRow = File::getResizedImageByName($modelImage->filename, 100, 100); + // Если файл не найден на сервере или возникла ошибка обработки, показываем заглушку + if ($imageThumbRow === 'file_not_found' || $imageThumbRow === 'file_not_readable' || $imageThumbRow === 'file_processing_error') { + $imageThumbRow = 'broken_file-error'; + $relaFileName = $imageThumbRow . '_' .$relaFileName; + } } else { $imageThumbRow = 'broken_file-size_zero'; $relaFileName = $imageThumbRow . '_' .$relaFileName; diff --git a/erp24/views/write_offs_erp/_form.php b/erp24/views/write_offs_erp/_form.php index 81c66468..c0de4485 100644 --- a/erp24/views/write_offs_erp/_form.php +++ b/erp24/views/write_offs_erp/_form.php @@ -64,7 +64,7 @@ foreach ($analyticsOps as $key => $value) { $parts = explode('_', $value, 2); $value = $parts[1]; } - $processedAnalytics[$key] = $value; + $processedAnalytics[$value] = $value; } ?> -- 2.39.5