mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 19:42:38 +02:00
This commit is contained in:
parent
99075df495
commit
e5afdee3c2
6 changed files with 100 additions and 0 deletions
|
@ -432,4 +432,33 @@ class VideoStatistic extends ObjectYPT {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static function getTotalStatisticsRecords() {
|
||||
global $global;
|
||||
$sql2 = "SELECT count(s.id) as total FROM videos_statistics s ";
|
||||
$res2 = sqlDAL::readSql($sql2);
|
||||
$result2 = sqlDAL::fetchAssoc($res2);
|
||||
sqlDAL::close($res2);
|
||||
$result = 0;
|
||||
if (!empty($result2)) {
|
||||
return intval($result2['total']);
|
||||
}
|
||||
ObjectYPT::setCache($cacheName, $result);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function deleteOldStatistics($days) {
|
||||
global $global;
|
||||
$days = intval($days);
|
||||
if (!empty($days)) {
|
||||
$sql = "DELETE FROM " . static::getTableName() . " ";
|
||||
$sql .= " WHERE created < DATE_SUB(NOW(), INTERVAL ? DAY) ";
|
||||
$global['lastQuery'] = $sql;
|
||||
//_error_log("Delete Query: ".$sql);
|
||||
return sqlDAL::writeSql($sql, "i", array($days));
|
||||
}
|
||||
_error_log("Id for table " . static::getTableName() . " not defined for deletion", AVideoLog::$ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class Cache extends PluginAbstract {
|
|||
$obj->cacheDir = $global['systemRootPath'] . 'videos/cache/';
|
||||
$obj->logPageLoadTime = false;
|
||||
$obj->stopBotsFromNonCachedPages = false;
|
||||
$obj->deleteStatisticsDaysOld = 180; // 6 months
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
@ -254,6 +255,20 @@ class Cache extends PluginAbstract {
|
|||
_error_log("Page generated in {$total_time} seconds. {$type} ({$_SERVER['REQUEST_URI']}) FROM: {$_SERVER['REMOTE_ADDR']} Browser: {$_SERVER['HTTP_USER_AGENT']}");
|
||||
}
|
||||
|
||||
public function getPluginMenu() {
|
||||
global $global;
|
||||
$fileAPIName = $global['systemRootPath'] . 'plugin/Cache/pluginMenu.html';
|
||||
$content = file_get_contents($fileAPIName);
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function getFooterCode() {
|
||||
global $global;
|
||||
if(preg_match('/managerPlugins.php$/', $_SERVER["SCRIPT_FILENAME"])){
|
||||
return "<script src=\"{$global['webSiteRootURL']}plugin/Cache/pluginMenu.js\"></script>";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function sanitize_output($buffer) {
|
||||
|
|
31
plugin/Cache/deleteStatistics.json.php
Normal file
31
plugin/Cache/deleteStatistics.json.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
require_once '../../videos/configuration.php';
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
$obj->msg = "";
|
||||
$obj->result = "";
|
||||
|
||||
if (!User::isAdmin()) {
|
||||
$obj->msg = "You cant do this";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
require_once $global['systemRootPath'] . 'objects/video_statistic.php';
|
||||
|
||||
$objC = AVideoPlugin::getDataObject('Cache');
|
||||
|
||||
$days = $objC->deleteStatisticsDaysOld;
|
||||
if(empty($days)){
|
||||
$days = 180;
|
||||
}
|
||||
$obj->before = VideoStatistic::getTotalStatisticsRecords();
|
||||
$obj->result = VideoStatistic::deleteOldStatistics($days);
|
||||
$obj->after = VideoStatistic::getTotalStatisticsRecords();
|
||||
$obj->error = empty($obj->result);
|
||||
|
||||
$obj->msg = "you had ". number_format($obj->before, 0)." statistics records and removed ". number_format($obj->before-$obj->after, 0)." now you have ". number_format($obj->after, 0);
|
||||
|
||||
echo json_encode($obj);
|
1
plugin/Cache/pluginMenu.html
Normal file
1
plugin/Cache/pluginMenu.html
Normal file
|
@ -0,0 +1 @@
|
|||
<button class="btn btn-primary btn-sm btn-xs btn-block" onclick="deleteOldStatistics();"><i class="fas fa-trash"></i> Delete Old Statistics</button>
|
10
plugin/Cache/pluginMenu.js
Normal file
10
plugin/Cache/pluginMenu.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
function deleteOldStatistics() {
|
||||
modal.showPleaseWait();
|
||||
$.ajax({
|
||||
url: webSiteRootURL + 'plugin/Cache/deleteStatistics.json.php',
|
||||
success: function (response) {
|
||||
avideoResponse(response);
|
||||
modal.hidePleaseWait();
|
||||
}
|
||||
});
|
||||
}
|
|
@ -1107,6 +1107,20 @@ function avideoModalIframeRemove() {
|
|||
}
|
||||
}
|
||||
|
||||
function avideoResponse(response) {
|
||||
if(response.error){
|
||||
if(!response.msg){
|
||||
response.msg = 'Error';
|
||||
}
|
||||
avideoAlertError(response.msg);
|
||||
}else{
|
||||
if(!response.msg){
|
||||
response.msg = 'Success';
|
||||
}
|
||||
avideoToastSuccess(response.msg);
|
||||
}
|
||||
}
|
||||
|
||||
function avideoAlertText(msg) {
|
||||
avideoAlert("", msg, '');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue