1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

add a tool to fix playlists

This commit is contained in:
daniel 2020-05-08 14:52:46 -03:00
parent 862d80b3e4
commit a65fe237e3

View file

@ -0,0 +1,70 @@
<?php
//streamer config
require_once '../videos/configuration.php';
if (!isCommandLineInterface()) {
return die('Command Line only');
}
$users_ids = array();
$sql = "SELECT distinct(users_id) as users_id FROM playlists ";
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $key => $row) {
$users_ids[] = $row['users_id'];
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
foreach ($users_ids as $user_id) {
echo "Process user_id = {$user_id}\n";
ob_flush();
$sql = "SELECT * FROM playlists WHERE users_id = {$user_id} AND status = 'favorite' ORDER BY created ";
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $key => $row) {
if ($key === 0) {
continue;
}
$sql = "DELETE FROM playlists ";
$sql .= " WHERE id = ?";
echo $sql." = {$row['id']}\n";
ob_flush();
sqlDAL::writeSql($sql, "i", array($row['id']));
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
$sql = "SELECT * FROM playlists WHERE users_id = {$user_id} AND status = 'watch_later' ORDER BY created ";
$res = sqlDAL::readSql($sql);
$fullData = sqlDAL::fetchAllAssoc($res);
sqlDAL::close($res);
$rows = array();
if ($res != false) {
foreach ($fullData as $key => $row) {
if ($key === 0) {
continue;
}
$sql = "DELETE FROM playlists ";
$sql .= " WHERE id = ?";
echo $sql." = {$row['id']}\n";
ob_flush();
sqlDAL::writeSql($sql, "i", array($row['id']));
}
} else {
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
}
}