source: extensions/History_cleanup/main.inc.php @ 7690

Last change on this file since 7690 was 6179, checked in by vdigital, 14 years ago

New: SQLite support.

File size: 1.4 KB
Line 
1<?php
2/*
3Plugin Name: History cleanup
4Version: 2.1.b
5Description: A background process which cleans your history table on regular basis
6Plugin URI: http://piwigo.org/ext/extension_view.php?eid=392
7Author: VDigital
8Author URI: http://piwigo.org/
9*/
10if ( !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?>
Note: See TracBrowser for help on using the repository browser.