mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-04 02:09:22 +02:00
Making sure clear the first page cache when it is requested
This commit is contained in:
parent
add1d4083a
commit
930b51e496
6 changed files with 58 additions and 35 deletions
|
@ -374,6 +374,7 @@ abstract class ObjectYPT implements ObjectInterface {
|
||||||
$getCachesProcessed = array();
|
$getCachesProcessed = array();
|
||||||
}
|
}
|
||||||
$cachefile = self::getCacheFileName($name);
|
$cachefile = self::getCacheFileName($name);
|
||||||
|
//var_dump($cachefile);//exit;
|
||||||
self::setLastUsedCacheFile($cachefile);
|
self::setLastUsedCacheFile($cachefile);
|
||||||
//_error_log('getCache: cachefile '.$cachefile);
|
//_error_log('getCache: cachefile '.$cachefile);
|
||||||
if (!empty($_getCache[$name])) {
|
if (!empty($_getCache[$name])) {
|
||||||
|
@ -680,6 +681,7 @@ abstract class ObjectYPT implements ObjectInterface {
|
||||||
public static function deleteAllSessionCache() {
|
public static function deleteAllSessionCache() {
|
||||||
_session_start();
|
_session_start();
|
||||||
unset($_SESSION['user']['sessionCache']);
|
unset($_SESSION['user']['sessionCache']);
|
||||||
|
return empty($_SESSION['user']['sessionCache']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tableExists() {
|
public function tableExists() {
|
||||||
|
|
|
@ -4,19 +4,20 @@ global $global, $config;
|
||||||
if(!isset($global['systemRootPath'])){
|
if(!isset($global['systemRootPath'])){
|
||||||
require_once '../videos/configuration.php';
|
require_once '../videos/configuration.php';
|
||||||
}
|
}
|
||||||
require_once $global['systemRootPath'] . 'objects/user.php';
|
|
||||||
|
|
||||||
$obj = new stdClass();
|
$obj = new stdClass();
|
||||||
$obj->error = true;
|
$obj->error = true;
|
||||||
$obj->msg = "";
|
$obj->msg = "";
|
||||||
|
$obj->clearCache = false;
|
||||||
if (!Permissions::canClearCache()) {
|
$obj->deleteALLCache = false;
|
||||||
$obj->msg = __("Permission denied");
|
$obj->deleteAllSessionCache = false;
|
||||||
die(json_encode($obj));
|
|
||||||
}
|
|
||||||
_session_start();
|
|
||||||
$_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1;
|
$_SESSION['user']['sessionCache']['getAllCategoriesClearCache'] = 1;
|
||||||
$obj->clearCache = clearCache();
|
|
||||||
$obj->deleteALLCache = ObjectYPT::deleteALLCache();
|
if (!Permissions::canClearCache() || !empty($_REQUEST['sessionOnly'])) {
|
||||||
|
$obj->deleteAllSessionCache = ObjectYPT::deleteAllSessionCache();
|
||||||
|
}else{
|
||||||
|
$obj->clearCache = clearCache();
|
||||||
|
$obj->deleteALLCache = ObjectYPT::deleteALLCache();
|
||||||
|
}
|
||||||
$obj->error = false;
|
$obj->error = false;
|
||||||
die(json_encode($obj));
|
die(json_encode($obj));
|
||||||
|
|
|
@ -3939,13 +3939,20 @@ function clearCache($firstPageOnly = false) {
|
||||||
file_put_contents($lockFile, time());
|
file_put_contents($lockFile, time());
|
||||||
|
|
||||||
$dir = getVideosDir() . "cache" . DIRECTORY_SEPARATOR;
|
$dir = getVideosDir() . "cache" . DIRECTORY_SEPARATOR;
|
||||||
|
$tmpDir = ObjectYPT::getCacheDir('firstPage');
|
||||||
|
$parts = explode('firstpage', $tmpDir);
|
||||||
|
|
||||||
if ($firstPageOnly || !empty($_GET['FirstPage'])) {
|
if ($firstPageOnly || !empty($_GET['FirstPage'])) {
|
||||||
|
$tmpDir = $parts[0].'firstpage'.DIRECTORY_SEPARATOR;
|
||||||
|
//var_dump($tmpDir);exit;
|
||||||
$dir .= "firstPage" . DIRECTORY_SEPARATOR;
|
$dir .= "firstPage" . DIRECTORY_SEPARATOR;
|
||||||
|
}else{
|
||||||
|
$tmpDir = $parts[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
//_error_log('clearCache 1: '.$dir);
|
//_error_log('clearCache 1: '.$dir);
|
||||||
rrmdir($dir);
|
rrmdir($dir);
|
||||||
|
rrmdir($tmpDir);
|
||||||
ObjectYPT::deleteCache("getEncoderURL");
|
ObjectYPT::deleteCache("getEncoderURL");
|
||||||
unlink($lockFile);
|
unlink($lockFile);
|
||||||
$end = microtime(true) - $start;
|
$end = microtime(true) - $start;
|
||||||
|
@ -3953,6 +3960,10 @@ function clearCache($firstPageOnly = false) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearAllUsersSessionCache(){
|
||||||
|
sendSocketMessageToAll(time(), 'socketClearSessionCache');
|
||||||
|
}
|
||||||
|
|
||||||
function clearFirstPageCache() {
|
function clearFirstPageCache() {
|
||||||
return clearCache(true);
|
return clearCache(true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
|
||||||
// delete thumbs from poster
|
// delete thumbs from poster
|
||||||
Video::deleteThumbs($video->getFilename());
|
Video::deleteThumbs($video->getFilename());
|
||||||
}
|
}
|
||||||
|
$obj->clearFirstPageCache = clearFirstPageCache();
|
||||||
$obj->error = false;
|
$obj->error = false;
|
||||||
echo "{}";
|
echo "{}";
|
||||||
exit;
|
exit;
|
||||||
|
|
|
@ -135,14 +135,20 @@ if(User::isAdmin()){
|
||||||
}
|
}
|
||||||
|
|
||||||
AVideoPlugin::saveVideosAddNew($_POST, $resp);
|
AVideoPlugin::saveVideosAddNew($_POST, $resp);
|
||||||
|
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
$obj = new stdClass();
|
$obj = new stdClass();
|
||||||
|
|
||||||
$obj->status = !empty($resp);
|
$obj->status = !empty($resp);
|
||||||
$obj->msg = $msg;
|
$obj->msg = $msg;
|
||||||
$obj->info = json_encode($info);
|
$obj->info = json_encode($info);
|
||||||
$obj->infoObj = json_encode($infoObj);
|
$obj->infoObj = json_encode($infoObj);
|
||||||
$obj->videos_id = intval($resp);
|
$obj->videos_id = intval($resp);
|
||||||
$obj->video = Video::getVideoLight($obj->videos_id);
|
$obj->video = Video::getVideoLight($obj->videos_id);
|
||||||
|
if($obj->video['status'] == Video::$statusActive){
|
||||||
|
$obj->clearFirstPageCache = clearFirstPageCache();
|
||||||
|
//clearAllUsersSessionCache();
|
||||||
|
}
|
||||||
|
|
||||||
TimeLogEnd(__FILE__, __LINE__);
|
TimeLogEnd(__FILE__, __LINE__);
|
||||||
echo json_encode($obj);
|
echo json_encode($obj);
|
||||||
|
|
|
@ -1492,33 +1492,11 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
$('#clearCache, .clearCacheButton').on('click', function (ev) {
|
$('#clearCache, .clearCacheButton').on('click', function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
modal.showPleaseWait();
|
clearCache(true, 0, 0);
|
||||||
$.ajax({
|
|
||||||
url: webSiteRootURL + 'objects/configurationClearCache.json.php',
|
|
||||||
success: function (response) {
|
|
||||||
if (!response.error) {
|
|
||||||
avideoToastSuccess("Your cache has been cleared!");
|
|
||||||
} else {
|
|
||||||
avideoAlert("Sorry!", "Your cache has NOT been cleared!", "error");
|
|
||||||
}
|
|
||||||
modal.hidePleaseWait();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
$('.clearCacheFirstPageButton').on('click', function (ev) {
|
$('.clearCacheFirstPageButton').on('click', function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
modal.showPleaseWait();
|
clearCache(true, 1, 0);
|
||||||
$.ajax({
|
|
||||||
url: webSiteRootURL + 'objects/configurationClearCache.json.php?FirstPage=1',
|
|
||||||
success: function (response) {
|
|
||||||
if (!response.error) {
|
|
||||||
avideoToastSuccess("Your First Page cache has been cleared!");
|
|
||||||
} else {
|
|
||||||
avideoAlert("Sorry!", "Your First Page cache has NOT been cleared!", "error");
|
|
||||||
}
|
|
||||||
modal.hidePleaseWait();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
$('#generateSiteMap, .generateSiteMapButton').on('click', function (ev) {
|
$('#generateSiteMap, .generateSiteMapButton').on('click', function (ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
@ -1595,6 +1573,25 @@ $(document).ready(function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function clearCache(showPleaseWait, FirstPage, sessionOnly){
|
||||||
|
if(showPleaseWait){
|
||||||
|
modal.showPleaseWait();
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: webSiteRootURL + 'objects/configurationClearCache.json.php?FirstPage='+FirstPage+'&sessionOnly='+sessionOnly,
|
||||||
|
success: function (response) {
|
||||||
|
if(showPleaseWait){
|
||||||
|
if (!response.error) {
|
||||||
|
avideoToastSuccess("Your First Page cache has been cleared!");
|
||||||
|
} else {
|
||||||
|
avideoAlert("Sorry!", "Your First Page cache has NOT been cleared!", "error");
|
||||||
|
}
|
||||||
|
modal.hidePleaseWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function validURL(str) {
|
function validURL(str) {
|
||||||
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
||||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
||||||
|
@ -1927,3 +1924,8 @@ document.addEventListener('visibilitychange', function () {
|
||||||
_addViewAsync();
|
_addViewAsync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function socketClearSessionCache(json){
|
||||||
|
console.log('socketClearSessionCache', json);
|
||||||
|
clearCache(false, 0, 1);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue