From 54317fcfff06047ebd2926be7e2de2ec9c3fdb29 Mon Sep 17 00:00:00 2001 From: DanieL Date: Thu, 9 Jun 2022 14:47:33 -0300 Subject: [PATCH] https://github.com/WWBN/AVideo/issues/6720 --- install/removeRepeatedPlaylists2.php | 36 +++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/install/removeRepeatedPlaylists2.php b/install/removeRepeatedPlaylists2.php index c7743221f1..d0b0adc23f 100644 --- a/install/removeRepeatedPlaylists2.php +++ b/install/removeRepeatedPlaylists2.php @@ -8,7 +8,6 @@ if (!isCommandLineInterface()) { return die('Command Line only'); } -$users_ids = []; $sql = " select count(*) as total, users_id from playlists where status = 'favorite' group by users_id"; $res = sqlDAL::readSql($sql); $fullData = sqlDAL::fetchAllAssoc($res); @@ -42,3 +41,38 @@ if ($res != false) { } else { die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); } + + +$sql = " select count(*) as total, users_id from playlists where status = 'watch_later' group by users_id"; +$res = sqlDAL::readSql($sql); +$fullData = sqlDAL::fetchAllAssoc($res); +sqlDAL::close($res); +$rows = []; +if ($res != false) { + foreach ($fullData as $key => $row) { + if ($row['total'] > 1) { + echo "Process user_id = {$row['users_id']} total={$row['total']} watch_later\n"; + ob_flush(); + $sql2 = "SELECT * FROM playlists WHERE users_id = {$row['users_id']} AND status = 'watch_later' ORDER BY modified "; + $res2 = sqlDAL::readSql($sql2); + $fullData2 = sqlDAL::fetchAllAssoc($res2); + sqlDAL::close($res2); + $rows2 = []; + if ($res2 != false) { + $totalRows = count($fullData2); + foreach ($fullData2 as $key2 => $row2) { + if ($key2 !== $totalRows-1) { + $sql3 = "DELETE FROM playlists "; + echo $sql3. " = {$row2['id']}; users_id = {{$row2['users_id']}}".PHP_EOL; + $sql3 .= " WHERE id = ?"; + sqlDAL::writeSql($sql3, "i", [$row2['id']]); + } + } + } else { + die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); + } + } + } +} else { + die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error); +} \ No newline at end of file