|
Revision 6179, 1.4 KB
(checked in by vdigital, 3 years ago)
|
|
New: SQLite support.
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | /* |
|---|
| 3 | Plugin Name: History cleanup |
|---|
| 4 | Version: 2.1.b |
|---|
| 5 | Description: A background process which cleans your history table on regular basis |
|---|
| 6 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=392 |
|---|
| 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 | $limit = date ('Y-m-d',strtotime('-' . $w['remove'] . ' days')); |
|---|
| 20 | $previous = pwg_get_session_var('history_check', $latest); |
|---|
| 21 | if ( $previous <= $latest ) { |
|---|
| 22 | $q = ' |
|---|
| 23 | DELETE FROM ' . HISTORY_TABLE . ' |
|---|
| 24 | WHERE date < ' . $limit . ' |
|---|
| 25 | AND summarized = "true";'; |
|---|
| 26 | $r = pwg_query($q); |
|---|
| 27 | if($r) |
|---|
| 28 | { |
|---|
| 29 | if (!defined('DB_ENGINE') ) define('DB_ENGINE', 'MySQL'); |
|---|
| 30 | switch (DB_ENGINE) { |
|---|
| 31 | case 'PostgreSQL': |
|---|
| 32 | $q = 'VACUUM FULL '.HISTORY_TABLE.';'; |
|---|
| 33 | break; |
|---|
| 34 | case 'MySQL': |
|---|
| 35 | $q = 'OPTIMIZE TABLE '.HISTORY_TABLE.';'; |
|---|
| 36 | break; |
|---|
| 37 | default: |
|---|
| 38 | $q = 'VACUUM;'; |
|---|
| 39 | } |
|---|
| 40 | $r=pwg_query($q); |
|---|
| 41 | } |
|---|
| 42 | pwg_set_session_var('history_check', strtotime("now")); |
|---|
| 43 | return $r; |
|---|
| 44 | } |
|---|
| 45 | return false; |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | ?> |
|---|