Index: /extensions/History_cleanup/main.inc.php
===================================================================
--- /extensions/History_cleanup/main.inc.php	(revision 6139)
+++ /extensions/History_cleanup/main.inc.php	(revision 6179)
@@ -2,5 +2,5 @@
 /*
 Plugin Name: History cleanup
-Version: 2.1.a 
+Version: 2.1.b
 Description: A background process which cleans your history table on regular basis
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=392
@@ -17,18 +17,26 @@
 		    : array( 'each' => 30, 'remove' => 90 ); # DAYs 
 		$latest = strtotime('-' . $w['each'] . ' days');
+		$limit = date ('Y-m-d',strtotime('-' . $w['remove'] . ' days'));
 		$previous = pwg_get_session_var('history_check', $latest);
 		if ( $previous <= $latest ) {
 			$q = '
 			DELETE FROM  ' . HISTORY_TABLE . ' 
-			 WHERE date < DATE_SUB(NOW(), INTERVAL ' . $w['remove'] . '  DAY) 
+			 WHERE date < ' . $limit . '
 			  AND summarized = "true";';
-
 			$r = pwg_query($q);  
 			if($r)
 			{
-			  if (defined('DB_ENGINE') and DB_ENGINE == 'PostgreSQL') 
-			       $q = 'VACUUM FULL '.HISTORY_TABLE;
-			  else $q = 'OPTIMIZE TABLE '.HISTORY_TABLE;
-			  $r=pwg_query($q);
+				if (!defined('DB_ENGINE') ) define('DB_ENGINE', 'MySQL');
+				switch (DB_ENGINE) {
+					case 'PostgreSQL':
+						$q = 'VACUUM FULL '.HISTORY_TABLE.';';
+						break;
+					case 'MySQL':
+						$q = 'OPTIMIZE TABLE '.HISTORY_TABLE.';';
+						break;
+					default:
+					   $q = 'VACUUM;';
+				}
+				$r=pwg_query($q);
 			}
 			pwg_set_session_var('history_check', strtotime("now"));
