@@ -27,7 +27,7 @@ public static function convert()
2727
2828 // Try three times
2929 $ tries = 0 ;
30- while (!empty ($ playlists ) && $ tries < 3 ) {
30+ while (!empty ($ playlists ) && $ tries < 10 ) {
3131 foreach ($ playlists as $ playlist ) {
3232 $ config_id = $ playlist ->config_id ?? null ;
3333 if (empty ($ config_id )) {
@@ -43,6 +43,8 @@ public static function convert()
4343 self ::getOcPlaylistData ($ playlist , $ playlist_videos )
4444 );
4545
46+ sleep (2 );
47+
4648 if ($ oc_playlist ) {
4749 // Store oc playlist reference in Stud.IP if successfully created
4850 $ playlist ->config_id = $ config_id ;
@@ -70,7 +72,33 @@ public static function convert()
7072 $ tries ++;
7173 }
7274
73- // We need another step to make sure config id is set and it is not null before altering the table with not-null confing_id.
75+ // What is the point of letting the process continue if there are still playlists with null service_playlist_id of duplicated service_playlist_ids?
76+ $ duplicate_service_playlist_ids = $ db ->query (
77+ "SELECT service_playlist_id, COUNT(*) as count
78+ FROM oc_playlist
79+ WHERE service_playlist_id IS NOT NULL
80+ GROUP BY service_playlist_id
81+ HAVING count > 1 "
82+ )->fetchAll (\PDO ::FETCH_ASSOC );
83+
84+ if (!empty ($ playlists ) || !empty ($ duplicate_service_playlist_ids )) {
85+ $ message = "Migration failed due to invalid data records: \n" ;
86+ if (!empty ($ playlists )) {
87+ $ message .= "Playlists with null service_playlist_id: \n" ;
88+ foreach ($ playlists as $ playlist ) {
89+ $ message .= "Playlist ID: {$ playlist ->id }\n" ;
90+ }
91+ }
92+ if (!empty ($ duplicate_service_playlist_ids )) {
93+ $ message .= "Duplicate service_playlist_ids: \n" ;
94+ foreach ($ duplicate_service_playlist_ids as $ record ) {
95+ $ message .= "Service Playlist ID: {$ record ['service_playlist_id ' ]}, Count: {$ record ['count ' ]}\n" ;
96+ }
97+ }
98+ throw new \Exception ($ message );
99+ }
100+
101+ // We need another step to make sure config id is set and it is not null before altering the table with not-null config_id.
74102 $ null_config_playlists = Playlists::findBySQL ('config_id IS NULL ' );
75103
76104 while (!empty ($ null_config_playlists )) {
0 commit comments