/**
* Массовая конвертация 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
/** @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',
]);
}
'l' => 'limit',
'n' => 'dryRun',
's' => 'sleep',
+ 'd' => 'days',
];
}
*/
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");
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);