From a286b281e6e45832aea000c684b7fd4f5dda17f3 Mon Sep 17 00:00:00 2001 From: Rybkin A Date: Tue, 1 Dec 2026 15:36:33 +0400 Subject: [PATCH] =?UTF-8?q?#133221=20www=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=BE=20web?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- File.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/File.php b/File.php index 8ee2125..dbed6cb 100644 --- a/File.php +++ b/File.php @@ -87,6 +87,28 @@ class File extends \yii\db\ActiveRecord } } + /** + * Веб-рут приложения: во всех Yii-приложениях Кувалды каталог называется www/ + * (базовый образ nginx раздаёт root /app/www), историческое имя web/ поддержано + * для старых установок. Алиас @webroot не используется: его ставит только + * yii\web\Application, а файлы пишут и консольные процессы (потребители очередей, + * cron, file/move, fileresize). + * @return string + */ + public static function getWebRoot() + { + $app = rtrim(Yii::getAlias('@app'), '/'); + foreach (['www', 'web'] as $name) + { + if (is_dir($app . '/' . $name)) + { + return $app . '/' . $name; + } + } + + return $app . '/www'; + } + /** * Папка с файлом * @param boolian $full @@ -99,13 +121,13 @@ class File extends \yii\db\ActiveRecord // $full = $full && !Yii::$app->has('s3'); if($full) { - $output = Yii::getAlias('@app/web'); + $output = self::getWebRoot(); } $output .= '/data/' . $dir . '/' . $this->module . '/' . wordwrap(mb_substr($this->md5, 0, 6), 2, '/', true) . '/'; if(Yii::$app->has('s3') && $full && $resize) { //если работаем с облаком не плодим папки миниатюр - $output = Yii::getAlias('@app/web/data/file_cache/'); + $output = self::getWebRoot() . '/data/file_cache/'; } if ($full && !file_exists($output)) { @@ -125,7 +147,7 @@ class File extends \yii\db\ActiveRecord */ public function getDirCache() { - $dir = Yii::getAlias('@app/web/data/file_cache/'); + $dir = self::getWebRoot() . '/data/file_cache/'; if (!file_exists($dir)) { mkdir($dir, 0755, true);