diff --git a/src/controllers/ReuploadController.php b/src/controllers/ReuploadController.php index cfe6eb1..8853dca 100644 --- a/src/controllers/ReuploadController.php +++ b/src/controllers/ReuploadController.php @@ -16,12 +16,6 @@ class ReuploadController extends Controller public function actionReupload(): int { - $fields = \Craft::$app->getFields()->getFieldsByType(CloudflareVideoStreamField::class); - $fieldsCount = is_array($fields) ? count($fields) : 0; - - $this->stdout("Found {$fieldsCount} fields", Console::FG_GREEN); - $this->stdout(PHP_EOL); - $volumes = \Craft::$app->getVolumes()->getAllVolumes(); $volumeCount = is_array($volumes) ? count($volumes) : 0; @@ -32,27 +26,31 @@ public function actionReupload(): int foreach ($volumes as $volume) { $this->stdout("Volume: {$volume->name}"); $this->stdout(PHP_EOL); - foreach ($fields as $field) { - $this->stdout(" Field: {$field->handle}"); - $this->stdout(PHP_EOL); - $entries = Asset::find()->volumeId($volume->id)->all(); + $assets = Asset::find()->volumeId($volume->id)->all(); - /** @var Asset $asset */ - foreach ($entries as $asset) { - if (isset($asset->videoStream)) { - $uploadJob = new UploadVideoJob([ - 'fieldHandle' => $field->handle, - 'elementId' => $asset->id, - 'videoUrl' => $asset->getUrl(), - 'videoName' => $asset->filename, - 'videoPath' => Folder::getAssetFolderPath($asset), - 'videoTitle' => $asset->title, - ]); - \Craft::$app->getQueue()->push($uploadJob); - ++$uploadCount; - } + /** @var Asset $asset */ + foreach ($assets as $asset) { + + $field = CloudflareVideoStreamField::findStreamingFieldForAsset($asset); + if (!$field) { + continue; } + + $this->stdout( + " Asset {$asset->id} - {$asset->filename} with field `{$field->handle}` will be reuploaded" + ); + + $uploadJob = new UploadVideoJob([ + 'fieldHandle' => $field->handle, + 'elementId' => $asset->id, + 'videoUrl' => $asset->getUrl(), + 'videoName' => $asset->filename, + 'videoPath' => Folder::getAssetFolderPath($asset), + 'videoTitle' => $asset->title, + ]); + \Craft::$app->getQueue()->push($uploadJob); + ++$uploadCount; } }