Skip to content

Commit

Permalink
(fix) Use field from field layout instead
Browse files Browse the repository at this point in the history
The output of the command was confusing because it was check for _all_
fields in _all_ volumes. Turns out there is a better way to do it.
  • Loading branch information
nitriques committed Oct 18, 2024
1 parent bebcde9 commit 1c994b2
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/controllers/ReuploadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}

Expand Down

0 comments on commit 1c994b2

Please sign in to comment.