From e237e1e706043d527f69e7888d67fb05be5e847d Mon Sep 17 00:00:00 2001 From: Afterster Date: Sat, 27 Dec 2014 11:19:42 +0100 Subject: [PATCH] Add an action to clean expired shared objects (fix #618) --- images/icon_clean.png | Bin 0 -> 859 bytes lib/class/share.class.php | 6 ++++++ share.php | 12 ++++++++++++ templates/show_shares.inc.php | 8 ++++++++ 4 files changed, 26 insertions(+) create mode 100644 images/icon_clean.png diff --git a/images/icon_clean.png b/images/icon_clean.png new file mode 100644 index 0000000000000000000000000000000000000000..cf039f40bbfeb27808da2baf71534720dcff09e3 GIT binary patch literal 859 zcmV-h1El*9LGQR;QS<&hkkZ651oG9iF3!18b?~u<0#c4wwkTdq+#@cQlwffJxmc2t81z2 zN-hs;g-YfK6}uiV=fa)z{J8b|^lSZ5r}5d|`~LHJzrLTn_xS)!Pzj58piCFTwLP9t zu~S5rY~zPl>~gocnI(gyWmXee0jwth6mKP=Cf6S-(kO5Bp}@gMg%JbSGbQI#d!>-L z#ByRl0L1}CvJ2E?OIfu?K%`e`qvQ0dAH$@l=F8ym__S%WfukIGZ_ONjP%l&0ge?<;0m5boPg?XUbCo0e!^T7MLv+2@A zmw08m5K0pTuu{tX-y9Lfgm!WvsPdzru_DO#Wm9NreIaFN$hO6z1gC2CVIk{ErZenc zX9tAY7;`vd?$dZdcjGE(QAfk+)U7w}Dw0vx9)p8VmtuoLRIWPW#V*fugaCKK)a)za z!mDNq4B8c-e-Z^f%|R)3<%x88P6p=0?#Hsd@mN(TOR3DC4^;(xkh*jJ2~EI;)*43` ze6|?g^h7g&kc=NAY4i_cJihM>$BsJzSg>aeeLgExQe7MXwIzITb7B7lwA{9bflfIL zYa@QYtG^mje||Tn;g`V}G?6DMC}@su=EGPrvJlMC0@I z%&$SH(>P#%TQK%%yy=j+X7ik9@XXE4fMWtUo@EP3TO3$+HXPf1$&M#*e(8 zj@j7T?19=w2|lj%F`DyW2GefK==T-z82uT=irGl9hzER002ovPDHLkV1ff)o{j(j literal 0 HcmV?d00001 diff --git a/lib/class/share.class.php b/lib/class/share.class.php index a5bfb453..fc3b2760 100644 --- a/lib/class/share.class.php +++ b/lib/class/share.class.php @@ -74,6 +74,12 @@ class Share extends database_object return Dba::write($sql, $params); } + public static function gc() + { + $sql = "DELETE FROM `share` WHERE (`expire_days` > 0 AND (`creation_date` + (`expire_days` * 86400)) < " . time() . ") OR (`max_counter` > 0 AND `counter` >= `max_counter`)"; + Dba::write($sql); + } + public static function delete_shares($object_type, $object_id) { $sql = "DELETE FROM `share` WHERE `object_type` = ? AND `object_id` = ?"; diff --git a/share.php b/share.php index 07129f76..8d783e49 100644 --- a/share.php +++ b/share.php @@ -108,6 +108,18 @@ switch ($action) { } UI::show_footer(); exit; + case 'clean': + if (AmpConfig::get('demo_mode')) { + UI::access_denied(); + exit; + } + + UI::show_header(); + Share::gc(); + $next_url = AmpConfig::get('web_path') . '/stats.php?action=share'; + show_confirmation(T_('Shared Objects cleaned'), T_('Expired shared objects have been cleaned.'), $next_url); + UI::show_footer(); + exit; case 'external_share': if (AmpConfig::get('demo_mode')) { UI::access_denied(); diff --git a/templates/show_shares.inc.php b/templates/show_shares.inc.php index b2e4123f..599f8a6b 100644 --- a/templates/show_shares.inc.php +++ b/templates/show_shares.inc.php @@ -21,5 +21,13 @@ */ ?> + +