diff --git a/migrations/107_migrate_previews.php b/migrations/107_migrate_previews.php index 15a2854217ce6df37fe6cc9ae8d1485a81891c83..03819d05a6f409578cf73bf49b2647d745b6d1cb 100644 --- a/migrations/107_migrate_previews.php +++ b/migrations/107_migrate_previews.php @@ -16,27 +16,26 @@ class MigratePreviews extends Migration while ($data = $result->fetch()) { - $new_preview = null; + $new_preview_url = null; $previews = json_decode($data['preview'], true); if (!empty($previews)) { if (!empty($previews['player'])) { - $new_preview = $previews['player']; + $new_preview_url = $previews['player']; } else if (!empty($previews['search'])) { - $new_preview = $previews['search']; + $new_preview_url = $previews['search']; } } - if (!empty($new_preview)) { - $stmt->execute([ - ':preview' => $new_preview, - ':id' => $data['id'] - ]); - } + // Since we are migrating previews to preview URL, we update the preview regardless of the value of the new preview url, whether it is empty or not! + $stmt->execute([ + ':preview' => $new_preview_url, + ':id' => $data['id'] + ]); } } public function down() { } -} \ No newline at end of file +} diff --git a/migrations/110_fix_orphaned_previews.php b/migrations/110_fix_orphaned_previews.php new file mode 100644 index 0000000000000000000000000000000000000000..fb1a90df4c93d43f979d6ed191056e87df351aba --- /dev/null +++ b/migrations/110_fix_orphaned_previews.php @@ -0,0 +1,42 @@ +<?php + +class FixOrphanedPreviews extends Migration +{ + public function description() + { + return 'Fix for previews that could not get migrated in 107.'; + } + + public function up() + { + $db = DBManager::get(); + + $stmt = $db->prepare('UPDATE oc_video SET preview = :preview WHERE id = :id'); + $result = $db->query('SELECT id, preview FROM oc_video WHERE preview IS NOT NULL'); + + + while ($data = $result->fetch()) { + $new_preview_url = null; + $previews = json_decode($data['preview'], true); + + // We want to handle the case where the preview is still a json object. + if (!empty($previews)) { + // Last chance to present the preview URL. + if (!empty($previews['player'])) { + $new_preview_url = $previews['player']; + } else if (!empty($previews['search'])) { + $new_preview_url = $previews['search']; + } + + $stmt->execute([ + ':preview' => $new_preview_url, + ':id' => $data['id'] + ]); + } + } + } + + public function down() + { + } +}