mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 17:59:55 +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();
|
||||
}
|
||||
$cachefile = self::getCacheFileName($name);
|
||||
//var_dump($cachefile);//exit;
|
||||
self::setLastUsedCacheFile($cachefile);
|
||||
//_error_log('getCache: cachefile '.$cachefile);
|
||||
if (!empty($_getCache[$name])) {
|
||||
|
@ -680,6 +681,7 @@ abstract class ObjectYPT implements ObjectInterface {
|
|||
public static function deleteAllSessionCache() {
|
||||
_session_start();
|
||||
unset($_SESSION['user']['sessionCache']);
|
||||
return empty($_SESSION['user']['sessionCache']);
|
||||
}
|
||||
|
||||
public function tableExists() {
|
||||
|
|
|
@ -4,19 +4,20 @@ global $global, $config;
|
|||
if(!isset($global['systemRootPath'])){
|
||||
require_once '../videos/configuration.php';
|
||||
}
|
||||
require_once $global['systemRootPath'] . 'objects/user.php';
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
$obj->msg = "";
|
||||
|
||||
if (!Permissions::canClearCache()) {
|
||||
$obj->msg = __("Permission denied");
|
||||
die(json_encode($obj));
|
||||
}
|
||||
_session_start();
|
||||
$obj->clearCache = false;
|
||||
$obj->deleteALLCache = false;
|
||||
$obj->deleteAllSessionCache = false;
|
||||
$_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;
|
||||
die(json_encode($obj));
|
||||
|
|
|
@ -3939,13 +3939,20 @@ function clearCache($firstPageOnly = false) {
|
|||
file_put_contents($lockFile, time());
|
||||
|
||||
$dir = getVideosDir() . "cache" . DIRECTORY_SEPARATOR;
|
||||
$tmpDir = ObjectYPT::getCacheDir('firstPage');
|
||||
$parts = explode('firstpage', $tmpDir);
|
||||
|
||||
if ($firstPageOnly || !empty($_GET['FirstPage'])) {
|
||||
$tmpDir = $parts[0].'firstpage'.DIRECTORY_SEPARATOR;
|
||||
//var_dump($tmpDir);exit;
|
||||
$dir .= "firstPage" . DIRECTORY_SEPARATOR;
|
||||
}else{
|
||||
$tmpDir = $parts[0];
|
||||
}
|
||||
|
||||
//_error_log('clearCache 1: '.$dir);
|
||||
rrmdir($dir);
|
||||
|
||||
rrmdir($tmpDir);
|
||||
ObjectYPT::deleteCache("getEncoderURL");
|
||||
unlink($lockFile);
|
||||
$end = microtime(true) - $start;
|
||||
|
@ -3953,6 +3960,10 @@ function clearCache($firstPageOnly = false) {
|
|||
return true;
|
||||
}
|
||||
|
||||
function clearAllUsersSessionCache(){
|
||||
sendSocketMessageToAll(time(), 'socketClearSessionCache');
|
||||
}
|
||||
|
||||
function clearFirstPageCache() {
|
||||
return clearCache(true);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,7 @@ if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
|
|||
// delete thumbs from poster
|
||||
Video::deleteThumbs($video->getFilename());
|
||||
}
|
||||
$obj->clearFirstPageCache = clearFirstPageCache();
|
||||
$obj->error = false;
|
||||
echo "{}";
|
||||
exit;
|
||||
|
|
|
@ -135,14 +135,20 @@ if(User::isAdmin()){
|
|||
}
|
||||
|
||||
AVideoPlugin::saveVideosAddNew($_POST, $resp);
|
||||
|
||||
TimeLogEnd(__FILE__, __LINE__);
|
||||
$obj = new stdClass();
|
||||
|
||||
$obj->status = !empty($resp);
|
||||
$obj->msg = $msg;
|
||||
$obj->info = json_encode($info);
|
||||
$obj->infoObj = json_encode($infoObj);
|
||||
$obj->videos_id = intval($resp);
|
||||
$obj->video = Video::getVideoLight($obj->videos_id);
|
||||
if($obj->video['status'] == Video::$statusActive){
|
||||
$obj->clearFirstPageCache = clearFirstPageCache();
|
||||
//clearAllUsersSessionCache();
|
||||
}
|
||||
|
||||
TimeLogEnd(__FILE__, __LINE__);
|
||||
echo json_encode($obj);
|
||||
|
|
|
@ -1492,33 +1492,11 @@ $(document).ready(function () {
|
|||
});
|
||||
$('#clearCache, .clearCacheButton').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
modal.showPleaseWait();
|
||||
$.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();
|
||||
}
|
||||
});
|
||||
clearCache(true, 0, 0);
|
||||
});
|
||||
$('.clearCacheFirstPageButton').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
modal.showPleaseWait();
|
||||
$.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();
|
||||
}
|
||||
});
|
||||
clearCache(true, 1, 0);
|
||||
});
|
||||
$('#generateSiteMap, .generateSiteMapButton').on('click', function (ev) {
|
||||
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) {
|
||||
var pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
|
||||
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
|
||||
|
@ -1926,4 +1923,9 @@ document.addEventListener('visibilitychange', function () {
|
|||
if (document.visibilityState === 'hidden') {
|
||||
_addViewAsync();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function socketClearSessionCache(json){
|
||||
console.log('socketClearSessionCache', json);
|
||||
clearCache(false, 0, 1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue