Last change
on this file since 6138 was
6138,
checked in by vdigital, 14 years ago
|
NEW: A background process which cleans your history table on regular basis.
|
File size:
1.3 KB
|
Rev | Line | |
---|
[6138] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | Plugin Name: History cleanup |
---|
| 4 | Version: 2.1.a |
---|
| 5 | Description: A background process which cleans your history table on regular basis |
---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=289 |
---|
| 7 | Author: VDigital |
---|
| 8 | Author URI: http://piwigo.org/ |
---|
| 9 | */ |
---|
| 10 | if ( !function_exists( 'history_cleanup' ) ) { |
---|
| 11 | if (!defined('IN_ADMIN') or !IN_ADMIN or (defined('DB_ENGINE') and DB_ENGINE == 'SQLite')) return false; |
---|
| 12 | add_event_handler('loc_begin_page_tail', 'history_cleanup' ); |
---|
| 13 | function history_cleanup() |
---|
| 14 | { |
---|
| 15 | global $conf; |
---|
| 16 | $w = (isset($conf['history_cleanup'])) ? $conf['history_cleanup'] |
---|
| 17 | : array( 'each' => 30, 'remove' => 90 ); # DAYs |
---|
| 18 | $latest = strtotime('-' . $w['each'] . ' days'); |
---|
| 19 | $previous = pwg_get_session_var('history_check', $latest); |
---|
| 20 | if ( $previous <= $latest ) { |
---|
| 21 | $q = ' |
---|
| 22 | DELETE FROM ' . HISTORY_TABLE . ' |
---|
| 23 | WHERE date < DATE_SUB(NOW(), INTERVAL ' . $w['remove'] . ' DAY) |
---|
| 24 | AND summarized = "true";'; |
---|
| 25 | |
---|
| 26 | $r = pwg_query($q); |
---|
| 27 | if($r) |
---|
| 28 | { |
---|
| 29 | if (defined('DB_ENGINE') and DB_ENGINE == 'PostgreSQL') |
---|
| 30 | $q = 'VACUUM FULL '.HISTORY_TABLE; |
---|
| 31 | else $q = 'OPTIMIZE TABLE '.HISTORY_TABLE; |
---|
| 32 | $r=pwg_query($q); |
---|
| 33 | } |
---|
| 34 | pwg_set_session_var('history_check', strtotime("now")); |
---|
| 35 | return $r; |
---|
| 36 | } |
---|
| 37 | return false; |
---|
| 38 | } |
---|
| 39 | } |
---|
| 40 | ?> |
---|
Note: See
TracBrowser
for help on using the repository browser.