Commit dff12087 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

fix(video-clips): check if created video exists before recreating it and failing

update seed scripts to prevent sql error when reloading install page
parent 2385b1a2
Loading
Loading
Loading
Loading
Loading
+18 −12
Original line number Diff line number Diff line
@@ -296,19 +296,25 @@ class AuthSeeder extends Seeder
            }
        }

        if ($this->db->table('auth_groups')->countAll() < count($dataPermissions)) {
            $this->db
                ->table('auth_permissions')
                ->ignore(true)
                ->insertBatch($dataPermissions);
        }
        if ($this->db->table('auth_groups')->countAll() < count($dataGroups)) {
            $this->db
                ->table('auth_groups')
                ->ignore(true)
                ->insertBatch($dataGroups);
        }
        if ($this->db->table('auth_groups_permissions')->countAll() < count($dataGroupsPermissions)) {
            $this->db
                ->table('auth_groups_permissions')
                ->ignore(true)
                ->insertBatch($dataGroupsPermissions);
        }
    }

    /**
     * @param array<string, string|int>[] $dataGroups
+6 −4
Original line number Diff line number Diff line
@@ -791,9 +791,11 @@ class CategorySeeder extends Seeder
            ],
        ];

        foreach ($data as $categoryLine) {
            $this->db
                ->table('categories')
                ->ignore(true)
            ->insertBatch($data);
                ->insert($categoryLine);
        }
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -763,9 +763,11 @@ class LanguageSeeder extends Seeder
            ],
        ];

        foreach ($data as $languageLine) {
            $this->db
                ->table('languages')
                ->ignore(true)
            ->insertBatch($data);
                ->insert($languageLine);
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -69,6 +69,11 @@ class VideoClip extends BaseClip
            return $this;
        }

        if ($this->attributes['media_id'] !== null) {
            // media is already set, do nothing
            return $this;
        }

        helper('media');
        $file = new File(media_path($filePath));

+21 −0
Original line number Diff line number Diff line
@@ -144,6 +144,27 @@ class ClipModel extends Model
        return (int) $result[0]['running_count'];
    }

    public function doesVideoClipExist(VideoClip $videoClip): int | false
    {
        $result = $this->select('id')
            ->where([
                'podcast_id' => $videoClip->podcast_id,
                'episode_id' => $videoClip->episode_id,
                'start_time' => $videoClip->start_time,
                'duration' => $videoClip->duration,
            ])
            ->where('JSON_EXTRACT(`metadata`, "$.format")', $videoClip->format)
            ->where('JSON_EXTRACT(`metadata`, "$.theme.name")', $videoClip->theme['name'])
            ->get()
            ->getResultArray();

        if ($result === []) {
            return false;
        }

        return (int) $result[0]['id'];
    }

    public function deleteVideoClip(int $podcastId, int $episodeId, int $clipId): BaseResult | bool
    {
        $this->clearVideoClipCache($clipId);
Loading