diff --git a/objects/Object.php b/objects/Object.php index dec8e46af9..d02c6fc3fa 100644 --- a/objects/Object.php +++ b/objects/Object.php @@ -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() { diff --git a/objects/configurationClearCache.json.php b/objects/configurationClearCache.json.php index 8fcacf0bce..672665289e 100644 --- a/objects/configurationClearCache.json.php +++ b/objects/configurationClearCache.json.php @@ -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)); diff --git a/objects/functions.php b/objects/functions.php index f7ac9f3f09..2600159c19 100644 --- a/objects/functions.php +++ b/objects/functions.php @@ -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); } diff --git a/objects/uploadPoster.php b/objects/uploadPoster.php index 85338c5f91..7e3e372513 100644 --- a/objects/uploadPoster.php +++ b/objects/uploadPoster.php @@ -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; diff --git a/objects/videoAddNew.json.php b/objects/videoAddNew.json.php index b065f0c2e0..da2e236d2c 100644 --- a/objects/videoAddNew.json.php +++ b/objects/videoAddNew.json.php @@ -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); diff --git a/view/js/script.js b/view/js/script.js index c452398c0d..56625c0d6d 100644 --- a/view/js/script.js +++ b/view/js/script.js @@ -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(); } -}); \ No newline at end of file +}); + +function socketClearSessionCache(json){ + console.log('socketClearSessionCache', json); + clearCache(false, 0, 1); +} \ No newline at end of file