1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00
Daniel Neto 2025-05-14 21:30:49 -03:00
parent f1d5628010
commit f702770262

View file

@ -1,67 +1,73 @@
<?php <?php
header('Content-Type: application/json'); header('Content-Type: application/json');
global $global, $config; global $global, $config;
if (!isset($global['systemRootPath'])) { if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php'; require_once '../videos/configuration.php';
} }
$obj = new stdClass(); $obj = new stdClass();
$obj->msg = ''; $obj->msg = '';
$obj->error = true; $obj->error = true;
if (($advancedCustom->disableVideoSwap) || ($advancedCustom->makeSwapVideosOnlyForAdmin && !Permissions::canModerateVideos())) { if (($advancedCustom->disableVideoSwap) || ($advancedCustom->makeSwapVideosOnlyForAdmin && !Permissions::canModerateVideos())) {
$obj->msg = __("Swap Disabled"); $obj->msg = __("Swap Disabled");
die(json_encode($obj)); die(json_encode($obj));
} }
if (!User::canUpload()) { if (!User::canUpload()) {
$obj->msg = __("Permission denied"); $obj->msg = __("Permission denied");
die(json_encode($obj)); die(json_encode($obj));
} }
if (empty($_POST['videos_id_1']) || empty($_POST['videos_id_2'])) { if (empty($_POST['videos_id_1']) || empty($_POST['videos_id_2'])) {
$obj->msg = __("Mou MUST select 2 videos to swap"); $obj->msg = __("Mou MUST select 2 videos to swap");
die(json_encode($obj)); die(json_encode($obj));
} }
$video1 = new Video("", "", $_POST['videos_id_1']); $video1 = new Video("", "", $_POST['videos_id_1']);
if (!$video1->userCanManageVideo()) { if (!$video1->userCanManageVideo()) {
$obj->msg = __("You can not Manage This Video 1"); $obj->msg = __("You can not Manage This Video 1");
die(json_encode($obj)); die(json_encode($obj));
} }
$video2 = new Video("", "", $_POST['videos_id_2']); $video2 = new Video("", "", $_POST['videos_id_2']);
if (!$video2->userCanManageVideo()) { if (!$video2->userCanManageVideo()) {
$obj->msg = __("You can not Manage This Video 2"); $obj->msg = __("You can not Manage This Video 2");
die(json_encode($obj)); die(json_encode($obj));
} }
$video1Filename = $video1->getFilename(); _error_log("Swap videos START: " . $video1->getId() . " with " . $video2->getId());
$video1Sites_id = $video1->getSites_id(); $video1Filename = $video1->getFilename();
$video1Duration = $video1->getDuration(); $video1Sites_id = $video1->getSites_id();
$video1Duration = $video1->getDuration();
$video2Filename = $video2->getFilename();
$video2Sites_id = $video2->getSites_id(); $video2Filename = $video2->getFilename();
$video2Duration = $video2->getDuration(); $video2Sites_id = $video2->getSites_id();
$video2Duration = $video2->getDuration();
$video1->setFilename($video2Filename, true);
$video1->setSites_id($video2Sites_id); $video1->setFilename($video2Filename, true);
$video1->setDuration($video2Duration); $video1->setSites_id($video2Sites_id);
$video1->setDuration($video2Duration);
$video2->setFilename($video1Filename, true);
$video2->setSites_id($video1Sites_id); $video2->setFilename($video1Filename, true);
$video2->setDuration($video1Duration); $video2->setSites_id($video1Sites_id);
mysqlBeginTransaction(); $video2->setDuration($video1Duration);
if (!$video1->save()) { mysqlBeginTransaction();
$obj->msg = __("Error on save video 1"); if (!$video1->save()) {
die(json_encode($obj)); $obj->msg = __("Error on swap video 1");
} _error_log($obj->msg);
if (!$video2->save()) { die(json_encode($obj));
$obj->msg = __("Error on save video 2"); }
die(json_encode($obj)); _error_log("Swap videos1 SUCCESS: " . $video1->getId());
} if (!$video2->save()) {
$video1->setVideoHigestResolution(0); $obj->msg = __("Error on swap video 2");
$video2->setVideoHigestResolution(0); _error_log($obj->msg);
mysqlCommit(); die(json_encode($obj));
$obj->error = false; }
die(json_encode($obj)); _error_log("Swap videos2 SUCCESS: " . $video2->getId());
$video1->setVideoHigestResolution(0);
$video2->setVideoHigestResolution(0);
mysqlCommit();
_error_log("Swap videos END: " . $video1->getId() . " with " . $video2->getId());
$obj->error = false;
die(json_encode($obj));