if (empty($modelMatrixErpMediaRow->id)) {
unset($modelMatrixErpMediaRow->id);
}
- $modelMatrixErpMediaRow->save();
+ if ($modelMatrixErpMediaRow->save()) {
+ Yii::error("MatrixErpMedia saved: id={$modelMatrixErpMediaRow->id}, foto_order={$modelMatrixErpMediaRow->foto_order}", __METHOD__);
+ } else {
+ Yii::error("Failed to save MatrixErpMedia: " . json_encode($modelMatrixErpMediaRow->getErrors()), __METHOD__);
+ }
+ } else {
+ Yii::error("MatrixErpMedia validation failed: " . json_encode($modelMatrixErpMediaRow->getErrors()), __METHOD__);
}
}
if ($firstMedia && $firstMedia->file) {
$file = $firstMedia->file;
+ $fullFilePath = \Yii::getAlias('@yii_app') . FileService::padWithSlash($file->url);
+ Yii::error("First media file: " . json_encode([
+ 'file_id' => $file->id,
+ 'file_type' => $file->file_type,
+ 'url' => $file->url,
+ 'full_path' => $fullFilePath,
+ 'file_exists' => file_exists($fullFilePath)
+ ]), __METHOD__);
// Проверяем, что файл существует и это изображение
- if ($file->file_type === 'image' && file_exists($file->url)) {
- Yii::info("Processing main image update for file: {$file->url}", __METHOD__);
+ if ($file->file_type === 'image' && file_exists($fullFilePath)) {
+ Yii::error("Processing main image update for file: {$fullFilePath}", __METHOD__);
// Сохраняем старую картинку для возможного удаления
$oldImageId = $modelEdit->image_id;
$displayName = !empty($firstMedia->name) ? $firstMedia->name : pathinfo($originalName, PATHINFO_FILENAME);
$image->original_name = $displayName . $ext;
$image->filename = $file_name;
- $image->type = mime_content_type($file->url) ?: 'image/jpeg';
+ $image->type = mime_content_type($fullFilePath) ?: 'image/jpeg';
// Получаем размеры изображения
- $imageInfo = getimagesize($file->url);
+ $imageInfo = getimagesize($fullFilePath);
if ($imageInfo) {
$image->width = $imageInfo[0];
$image->height = $imageInfo[1];
}
- $image->size = filesize($file->url);
+ $image->size = filesize($fullFilePath);
$image->created_at = time();
$image->updated_at = time();
if ($image->save()) {
// Копируем файл в директорию images
- $sourcePath = $file->url;
+ $sourcePath = $fullFilePath;
$destDir = \Yii::getAlias('@uploads/images/' . substr($image->filename, 0, 2));
$destPath = $destDir . '/' . $image->filename;
$image->delete();
}
}
+ } else {
+ Yii::error("File check failed: file_type='{$file->file_type}', file_exists=" . (file_exists($file->url) ? 'true' : 'false') . ", url='{$file->url}'", __METHOD__);
}
+ } else {
+ Yii::error("First media has no file or file is null", __METHOD__);
}
}