]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-274 Ввести версионность js и css файлов
authorMarina Zozirova <marina.zozirova@erp-flowers.ru>
Wed, 15 Jan 2025 08:28:21 +0000 (08:28 +0000)
committerAleksey Filippov <aleksey.filippov@erp-flowers.ru>
Wed, 15 Jan 2025 08:28:21 +0000 (08:28 +0000)
erp24/assets/CommonAsset.php
erp24/assets/FileVersionService.php [new file with mode: 0644]
erp24/assets/timetable/StartAsset.php
erp24/assets/timetable/TimetableAsset.php
erp24/forms/timetable/TabelSearchForm.php

index 0ec2b8f16961ebc24717dc3644064d17144985e4..d0f4e0d186386bb9222eedb977c3d2c8a1b92a93 100755 (executable)
@@ -23,6 +23,12 @@ class CommonAsset extends AssetBundle
 
     public function init()
     {
+        foreach (['js', 'css'] as $type) {
+            foreach ($this->$type as &$file) {
+                $file = FileVersionService::versionFile($file);
+            }
+        }
+
         $u = file_get_contents(__DIR__ . '/../inc/compress_timestamp.php');
         if (preg_match('/=\s*(?P<stamp>\d+);/', $u, $matches)) {
             array_unshift($this->css, '/min/css_' . $matches['stamp'] . '.css');
diff --git a/erp24/assets/FileVersionService.php b/erp24/assets/FileVersionService.php
new file mode 100644 (file)
index 0000000..e1619f6
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+namespace app\assets;
+
+use Yii;
+
+class FileVersionService
+{
+    /**
+     * Генерирует версию файла на основе его содержимого.
+     *
+     * @param string $file Путь к файлу
+     * @return string Путь с версией
+     */
+    public static function versionFile(string $file): string
+    {
+        $hash = md5(file_get_contents(Yii::getAlias($file)));
+        return "$file?v=$hash";
+    }
+}
index a60d79c341713bfd7294c102e18868fd96c50334..93c7e5fdf74c9c5ffe3c8a3bb1a628abd39fbc1f 100755 (executable)
@@ -2,6 +2,7 @@
 
 namespace yii_app\assets\timetable;
 
+use app\assets\FileVersionService;
 use yii\web\AssetBundle;
 
 class StartAsset extends AssetBundle
@@ -16,4 +17,15 @@ class StartAsset extends AssetBundle
         'css/timetable/start.css',
     ];
     public $jsOptions = ['defer' => true];
+
+    public function init()
+    {
+        parent::init();
+
+        foreach (['js', 'css'] as $type) {
+            foreach ($this->$type as &$file) {
+                $file = FileVersionService::versionFile($file);
+            }
+        }
+    }
 }
index d6a99a9d78fdcc7f8e6668753f720acef26378fd..972b4abb8c87df1a85a205c5564f263e3e7fd60e 100755 (executable)
@@ -2,6 +2,7 @@
 
 namespace yii_app\assets\timetable;
 
+use app\assets\FileVersionService;
 use yii\web\AssetBundle;
 
 class TimetableAsset extends AssetBundle
@@ -17,4 +18,15 @@ class TimetableAsset extends AssetBundle
         '/css/print.css',
     ];
     public $jsOptions = ['defer' => true];
+
+    public function init()
+    {
+        parent::init();
+
+        foreach (['js', 'css'] as $type) {
+            foreach ($this->$type as &$file) {
+                $file = FileVersionService::versionFile($file);
+            }
+        }
+    }
 }
index ebbd6a24b06d9b9d9448bf6eaa7d5dd9c81501c7..ad0b7f3f808f1c6c24ff681012c5bc75f89679f4 100755 (executable)
@@ -3,6 +3,7 @@ declare(strict_types = 1);
 
 namespace yii_app\forms\timetable;
 
+use yii_app\records\AdminStores;
 use yii_app\records\TimetableFactModel;
 use yii\base\Model;
 use yii\db\ActiveQuery;
@@ -51,10 +52,12 @@ class TabelSearchForm extends Model
     {
         $stores = CityStore::find()
             ->select(['name', 'id'])
-            ->andWhere(['id' => $_SESSION["store_arr_dostup"]])
+            ->andWhere(['id' => AdminStores::find()
+                                ->andWhere(['admin_id' => \Yii::$app->user->id])
+                                ->select('store_id')
+                                ->column()])
             ->andWhere(['visible' => '1'])
             ->indexBy('id')
-            ->cache(3600)
             ->column();
         natsort($stores);
         return $stores;