]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
fix(ERP-236): filter video conversion to files younger than 30 days
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 24 Feb 2026 14:24:56 +0000 (17:24 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Tue, 24 Feb 2026 14:24:56 +0000 (17:24 +0300)
Files older than 1 month are cleaned by write-offs-attachments anyway.
Added --days option (default 30, 0=all).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
erp24/commands/ConvertVideoController.php

index 2724ce07d4a7a8817368ddf4964f201364295be9..023a2bacaa313806af6940b4523667f1e2ead40c 100644 (file)
@@ -12,8 +12,12 @@ use yii_app\records\Files;
 /**
  * Массовая конвертация MOV → MP4 для существующих файлов.
  *
+ * По умолчанию конвертирует только файлы младше 1 месяца (старые удаляются через write-offs-attachments).
+ *
  * Запуск:
- *   php yii convert-video/run              — конвертация всех MOV
+ *   php yii convert-video/run              — конвертация MOV младше 1 месяца
+ *   php yii convert-video/run --days=7     — только за последние 7 дней
+ *   php yii convert-video/run --days=0     — все файлы без фильтра по дате
  *   php yii convert-video/run --limit=50   — конвертация первых 50
  *   php yii convert-video/run --dry-run    — только показать что будет конвертировано
  *   php yii convert-video/status           — статистика MOV/MP4
@@ -32,12 +36,16 @@ class ConvertVideoController extends Controller
     /** @var int Пауза между файлами в секундах (снижает нагрузку) */
     public int $sleep = 2;
 
+    /** @var int Конвертировать файлы за последние N дней (0 = все, по умолчанию 30) */
+    public int $days = 30;
+
     public function options($actionID): array
     {
         return array_merge(parent::options($actionID), [
             'limit',
             'dryRun',
             'sleep',
+            'days',
         ]);
     }
 
@@ -47,6 +55,7 @@ class ConvertVideoController extends Controller
             'l' => 'limit',
             'n' => 'dryRun',
             's' => 'sleep',
+            'd' => 'days',
         ];
     }
 
@@ -55,11 +64,28 @@ class ConvertVideoController extends Controller
      */
     public function actionStatus(): int
     {
-        $movCount = Files::find()->where(['like', 'url', '.mov'])->count();
-        $mp4Count = Files::find()->where(['like', 'url', '.mp4'])->count();
-        $aviCount = Files::find()->where(['like', 'url', '.avi'])->count();
+        $borderDate = $this->days > 0 ? date('Y-m-d H:i:s', strtotime("-{$this->days} days")) : null;
+
+        $movQuery = Files::find()->where(['like', 'url', '.mov']);
+        $mp4Query = Files::find()->where(['like', 'url', '.mp4']);
+        $aviQuery = Files::find()->where(['like', 'url', '.avi']);
+
+        if ($borderDate) {
+            $movQuery->andWhere(['>=', 'created_at', $borderDate]);
+            $mp4Query->andWhere(['>=', 'created_at', $borderDate]);
+            $aviQuery->andWhere(['>=', 'created_at', $borderDate]);
+        }
+
+        $movCount = $movQuery->count();
+        $mp4Count = $mp4Query->count();
+        $aviCount = $aviQuery->count();
 
         $this->stdout("=== Статистика видеофайлов ===\n");
+        if ($borderDate) {
+            $this->stdout("Фильтр: за последние {$this->days} дней (с {$borderDate})\n");
+        } else {
+            $this->stdout("Фильтр: все файлы\n");
+        }
         $this->stdout("MOV: {$movCount}\n");
         $this->stdout("MP4: {$mp4Count}\n");
         $this->stdout("AVI: {$aviCount}\n");
@@ -80,10 +106,18 @@ class ConvertVideoController extends Controller
             return ExitCode::UNSPECIFIED_ERROR;
         }
 
+        $borderDate = $this->days > 0 ? date('Y-m-d H:i:s', strtotime("-{$this->days} days")) : null;
+
         $query = Files::find()
-            ->where(['like', 'url', '.mov'])
-            ->orWhere(['like', 'url', '.avi'])
-            ->orderBy(['id' => SORT_ASC]);
+            ->andWhere(['or', ['like', 'url', '.mov'], ['like', 'url', '.avi']])
+            ->orderBy(['id' => SORT_DESC]);
+
+        if ($borderDate) {
+            $query->andWhere(['>=', 'created_at', $borderDate]);
+            $this->stdout("Фильтр: за последние {$this->days} дней (с {$borderDate})\n");
+        } else {
+            $this->stdout("Фильтр: все файлы\n");
+        }
 
         if ($this->limit > 0) {
             $query->limit($this->limit);