Skip to content

Commit 6516429

Browse files
author
Marius Burkard
committed
- Changed 0000-00-00 date and datetime values to NULL (mySQL compatibility), Fixes: #3690
1 parent 7bce72d commit 6516429

File tree

11 files changed

+57
-34
lines changed

11 files changed

+57
-34
lines changed

install/sql/incremental/upd_dev_collection.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,26 @@ ALTER TABLE `client` ADD COLUMN `limit_database_user` int(11) NOT NULL DEFAULT '
227227
ALTER TABLE `client_template` ADD COLUMN `limit_database_user` int(11) NOT NULL DEFAULT '-1' after limit_database;
228228
ALTER TABLE `client` CHANGE `customer_no_template` `customer_no_template` VARCHAR(255) NULL DEFAULT 'R[CLIENTID]C[CUSTOMER_NO]';
229229

230+
ALTER TABLE `client` CHANGE `added_date` `added_date` DATE NULL DEFAULT NULL;
231+
ALTER TABLE `ftp_user` CHANGE `expires` `expires` DATETIME NULL DEFAULT NULL;
232+
ALTER TABLE `mail_user` CHANGE `autoresponder_start_date` `autoresponder_start_date` DATETIME NULL DEFAULT NULL;
233+
ALTER TABLE `mail_user` CHANGE `autoresponder_end_date` `autoresponder_end_date` DATETIME NULL DEFAULT NULL;
234+
ALTER TABLE `openvz_traffic` CHANGE `traffic_date` `traffic_date` DATE NULL DEFAULT NULL;
235+
ALTER TABLE `openvz_vm` CHANGE `active_until_date` `active_until_date` DATE NULL DEFAULT NULL;
236+
ALTER TABLE `sys_session` CHANGE `date_created` `date_created` DATETIME NULL DEFAULT NULL;
237+
ALTER TABLE `sys_session` CHANGE `last_updated` `last_updated` DATETIME NULL DEFAULT NULL;
238+
ALTER TABLE `web_domain` CHANGE `added_date` `added_date` DATE NULL DEFAULT NULL;
239+
ALTER TABLE `web_traffic` CHANGE `traffic_date` `traffic_date` DATE NULL DEFAULT NULL;
240+
241+
UPDATE `client` SET `added_date` = NULL WHERE `added_date` = '0000-00-00';
242+
UPDATE `ftp_user` SET `expires` = NULL WHERE `expires` = '0000-00-00 00:00:00';
243+
UPDATE `mail_user` SET `autoresponder_start_date` = NULL WHERE `autoresponder_start_date` = '0000-00-00 00:00:00';
244+
UPDATE `mail_user` SET `autoresponder_end_date` = NULL WHERE `autoresponder_end_date` = '0000-00-00 00:00:00';
245+
UPDATE `openvz_traffic` SET `traffic_date` = NULL WHERE `traffic_date` = '0000-00-00';
246+
UPDATE `openvz_vm` SET `active_until_date` = NULL WHERE `active_until_date` = '0000-00-00';
247+
UPDATE `sys_session` SET `date_created` = NULL WHERE `date_created` = '0000-00-00 00:00:00';
248+
UPDATE `sys_session` SET `last_updated` = NULL WHERE `last_updated` = '0000-00-00 00:00:00';
249+
UPDATE `web_domain` SET `added_date` = NULL WHERE `added_date` = '0000-00-00';
250+
UPDATE `web_traffic` SET `traffic_date` = NULL WHERE `traffic_date` = '0000-00-00';
251+
252+

install/sql/ispconfig3.sql

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ CREATE TABLE `client` (
258258
`customer_no_template` varchar(255) DEFAULT 'R[CLIENTID]C[CUSTOMER_NO]',
259259
`customer_no_start` int(11) NOT NULL DEFAULT '1',
260260
`customer_no_counter` int(11) NOT NULL DEFAULT '0',
261-
`added_date` date NOT NULL DEFAULT '0000-00-00',
261+
`added_date` date NULL DEFAULT NULL,
262262
`added_by` varchar(255) DEFAULT NULL,
263263
`validation_status` enum('accept','review','reject') NOT NULL DEFAULT 'accept',
264264
`risk_score` int(10) unsigned NOT NULL DEFAULT '0',
@@ -638,7 +638,7 @@ CREATE TABLE `ftp_user` (
638638
`dl_ratio` int(11) NOT NULL default '-1',
639639
`ul_bandwidth` int(11) NOT NULL default '-1',
640640
`dl_bandwidth` int(11) NOT NULL default '-1',
641-
`expires` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
641+
`expires` datetime NULL DEFAULT NULL,
642642
PRIMARY KEY (`ftp_user_id`),
643643
KEY `active` (`active`),
644644
KEY `server_id` (`server_id`),
@@ -962,8 +962,8 @@ CREATE TABLE `mail_user` (
962962
`sender_cc` varchar(255) NOT NULL default '',
963963
`homedir` varchar(255) NOT NULL default '',
964964
`autoresponder` enum('n','y') NOT NULL default 'n',
965-
`autoresponder_start_date` datetime NOT NULL default '0000-00-00 00:00:00',
966-
`autoresponder_end_date` datetime NOT NULL default '0000-00-00 00:00:00',
965+
`autoresponder_start_date` datetime NULL default NULL,
966+
`autoresponder_end_date` datetime NULL default NULL,
967967
`autoresponder_subject` varchar(255) NOT NULL default 'Out of office reply',
968968
`autoresponder_text` mediumtext NULL,
969969
`move_junk` enum('n','y') NOT NULL default 'n',
@@ -1151,7 +1151,7 @@ INSERT INTO `openvz_template` (`template_id`, `sys_userid`, `sys_groupid`, `sys_
11511151

11521152
CREATE TABLE IF NOT EXISTS `openvz_traffic` (
11531153
`veid` int(11) NOT NULL DEFAULT '0',
1154-
`traffic_date` date NOT NULL DEFAULT '0000-00-00',
1154+
`traffic_date` date NULL DEFAULT NULL,
11551155
`traffic_bytes` bigint(32) unsigned NOT NULL DEFAULT '0',
11561156
PRIMARY KEY (`veid`,`traffic_date`)
11571157
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
@@ -1184,7 +1184,7 @@ CREATE TABLE IF NOT EXISTS `openvz_vm` (
11841184
`start_boot` varchar(255) NOT NULL DEFAULT 'y',
11851185
`bootorder` int(11) NOT NULL DEFAULT '1',
11861186
`active` varchar(255) NOT NULL DEFAULT 'y',
1187-
`active_until_date` date NOT NULL DEFAULT '0000-00-00',
1187+
`active_until_date` date NULL DEFAULT NULL,
11881188
`description` text,
11891189
`diskspace` int(11) NOT NULL DEFAULT '0',
11901190
`traffic` int(11) NOT NULL DEFAULT '-1',
@@ -1739,8 +1739,8 @@ CREATE TABLE `sys_remoteaction` (
17391739

17401740
CREATE TABLE `sys_session` (
17411741
`session_id` varchar(64) NOT NULL DEFAULT '',
1742-
`date_created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1743-
`last_updated` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
1742+
`date_created` datetime NULL DEFAULT NULL,
1743+
`last_updated` datetime NULL DEFAULT NULL,
17441744
`permanent` enum('n','y') NOT NULL DEFAULT 'n',
17451745
`session_data` longtext,
17461746
PRIMARY KEY (`session_id`),
@@ -1972,7 +1972,7 @@ CREATE TABLE `web_domain` (
19721972
`enable_spdy` ENUM('y','n') NULL DEFAULT 'n',
19731973
`last_quota_notification` date NULL default NULL,
19741974
`rewrite_rules` mediumtext,
1975-
`added_date` date NOT NULL DEFAULT '0000-00-00',
1975+
`added_date` date NULL DEFAULT NULL,
19761976
`added_by` varchar(255) DEFAULT NULL,
19771977
`directive_snippets_id` int(11) unsigned NOT NULL default '0',
19781978
`enable_pagespeed` ENUM('y','n') NOT NULL DEFAULT 'n',
@@ -2041,7 +2041,7 @@ CREATE TABLE IF NOT EXISTS `web_folder_user` (
20412041

20422042
CREATE TABLE `web_traffic` (
20432043
`hostname` varchar(255) NOT NULL DEFAULT '',
2044-
`traffic_date` date NOT NULL DEFAULT '0000-00-00',
2044+
`traffic_date` date NULL DEFAULT NULL,
20452045
`traffic_bytes` bigint(32) unsigned NOT NULL default '0',
20462046
PRIMARY KEY (`hostname`,`traffic_date`)
20472047
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;

install/tpl/pureftpd_mysql.conf.master

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ MYSQLCrypt crypt
5959

6060
# Query to execute in order to fetch the password
6161

62-
MYSQLGetPW SELECT password FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
62+
MYSQLGetPW SELECT password FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires IS NULL OR expires > NOW())
6363

6464

6565
# Query to execute in order to fetch the system user name or uid
6666

67-
MYSQLGetUID SELECT uid FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
67+
MYSQLGetUID SELECT uid FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires IS NULL OR expires > NOW())
6868

6969

7070
# Optional : default UID - if set this overrides MYSQLGetUID
@@ -74,7 +74,7 @@ MYSQLGetUID SELECT uid FROM ftp_user WHERE active = 'y' AND server_id = '{se
7474

7575
# Query to execute in order to fetch the system user group or gid
7676

77-
MYSQLGetGID SELECT gid FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
77+
MYSQLGetGID SELECT gid FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires IS NULL OR expires > NOW())
7878

7979

8080
# Optional : default GID - if set this overrides MYSQLGetGID
@@ -84,34 +84,34 @@ MYSQLGetGID SELECT gid FROM ftp_user WHERE active = 'y' AND server_id = '{se
8484

8585
# Query to execute in order to fetch the home directory
8686

87-
MYSQLGetDir SELECT dir FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
87+
MYSQLGetDir SELECT dir FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND username="\L" AND (expires IS NULL OR expires > NOW())
8888

8989

9090
# Optional : query to get the maximal number of files
9191
# Pure-FTPd must have been compiled with virtual quotas support.
9292

93-
MySQLGetQTAFS SELECT quota_files FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
93+
MySQLGetQTAFS SELECT quota_files FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_files != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
9494

9595

9696
# Optional : query to get the maximal disk usage (virtual quotas)
9797
# The number should be in Megabytes.
9898
# Pure-FTPd must have been compiled with virtual quotas support.
9999

100-
MySQLGetQTASZ SELECT quota_size FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_size != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
100+
MySQLGetQTASZ SELECT quota_size FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND quota_size != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
101101

102102

103103
# Optional : ratios. The server has to be compiled with ratio support.
104104

105-
MySQLGetRatioUL SELECT ul_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_ratio != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
106-
MySQLGetRatioDL SELECT dl_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_ratio != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
105+
MySQLGetRatioUL SELECT ul_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_ratio != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
106+
MySQLGetRatioDL SELECT dl_ratio FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_ratio != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
107107

108108

109109
# Optional : bandwidth throttling.
110110
# The server has to be compiled with throttling support.
111111
# Values are in KB/s .
112112

113-
MySQLGetBandwidthUL SELECT ul_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_bandwidth != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
114-
MySQLGetBandwidthDL SELECT dl_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_bandwidth != '-1' AND username="\L" AND (expires = "0000-00-00 00:00:00" OR expires > NOW())
113+
MySQLGetBandwidthUL SELECT ul_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND ul_bandwidth != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
114+
MySQLGetBandwidthDL SELECT dl_bandwidth FROM ftp_user WHERE active = 'y' AND server_id = '{server_id}' AND dl_bandwidth != '-1' AND username="\L" AND (expires IS NULL OR expires > NOW())
115115

116116
# Enable ~ expansion. NEVER ENABLE THIS BLINDLY UNLESS :
117117
# 1) You know what you are doing.

interface/lib/classes/listform.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ public function encode($record)
563563
break;
564564

565565
case 'DATE':
566-
if($record[$key] != '' && $record[$key] != '0000-00-00') {
566+
if($record[$key] != '' && !is_null($record[$key]) && $record[$key] != '0000-00-00') {
567567
$record[$key] = $record[$key];
568568
}
569569
break;

interface/lib/classes/remote.d/openvz.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function openvz_vm_add_from_template($session_id, $client_id, $ostemplate
307307
$params['vm_password'] = (isset($override_params['vm_password']))?$override_params['vm_password']:$app->auth->get_random_password(10);
308308
$params['start_boot'] = (isset($override_params['start_boot']))?$override_params['start_boot']:'y';
309309
$params['active'] = (isset($override_params['active']))?$override_params['active']:'y';
310-
$params['active_until_date'] = (isset($override_params['active_until_date']))?$override_params['active_until_date']:'0000-00-00';
310+
$params['active_until_date'] = (isset($override_params['active_until_date']))?$override_params['active_until_date']:null;
311311
$params['description'] = (isset($override_params['description']))?$override_params['description']:'';
312312

313313
//* The next params get filled with pseudo values, as the get replaced

interface/lib/classes/tform_base.inc.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected function _decode($record, $tab = '', $api = false) {
206206
break;
207207

208208
case 'DATE':
209-
if($record[$key] != '' && $record[$key] != '0000-00-00') {
209+
if($record[$key] != '' && !is_null($record[$key]) && $record[$key] != '0000-00-00') {
210210
$tmp = explode('-', $record[$key]);
211211
$new_record[$key] = date($this->dateformat, mktime(0, 0, 0, $tmp[1] , $tmp[2], $tmp[0]));
212212
}
@@ -770,7 +770,7 @@ protected function _encode($record, $tab, $dbencode = true, $api = false) {
770770
}
771771
break;
772772
case 'DATE':
773-
if($record[$key] != '' && $record[$key] != '0000-00-00') {
773+
if($record[$key] != '' && !is_null($record[$key]) && $record[$key] != '0000-00-00') {
774774
if(function_exists('date_parse_from_format')) {
775775
$date_parts = date_parse_from_format($this->dateformat, $record[$key]);
776776
$new_record[$key] = $date_parts['year'].'-'.str_pad($date_parts['month'], 2, "0", STR_PAD_LEFT).'-'.str_pad($date_parts['day'], 2, "0", STR_PAD_LEFT);
@@ -779,7 +779,7 @@ protected function _encode($record, $tab, $dbencode = true, $api = false) {
779779
$new_record[$key] = date('Y-m-d', $tmp);
780780
}
781781
} else {
782-
$new_record[$key] = '0000-00-00';
782+
$new_record[$key] = null;
783783
}
784784
break;
785785
case 'INTEGER':
@@ -802,19 +802,19 @@ protected function _encode($record, $tab, $dbencode = true, $api = false) {
802802
$new_record[$key] = date( 'Y-m-d H:i:s', mktime($_dt_hour, $_dt_minute, $_dt_second, $_dt_month, $_dt_day, $_dt_year) );
803803
}
804804
} else {*/
805-
if($record[$key] != '' && $record[$key] != '0000-00-00 00:00:00') {
805+
if($record[$key] != '' && !is_null($record[$key]) && $record[$key] != '0000-00-00 00:00:00') {
806806
//$tmp = strtotime($record[$key]);
807807
//$new_record[$key] = date($this->datetimeformat, $tmp);
808808
$parsed_date = date_parse_from_format($this->datetimeformat,$record[$key]);
809809
if($parsed_date['error_count'] > 0 || ($parsed_date['year'] == 1899 && $parsed_date['month'] == 12 && $parsed_date['day'] == 31)) {
810810
// There was an error, set the date to 0
811-
$new_record[$key] = '0000-00-00 00:00:00';
811+
$new_record[$key] = null;
812812
} else {
813813
// Date parsed successfully. Convert it to database format
814814
$new_record[$key] = date( 'Y-m-d H:i:s', mktime($parsed_date['hour'], $parsed_date['minute'], $parsed_date['second'], $parsed_date['month'], $parsed_date['day'], $parsed_date['year']) );
815815
}
816816
} else {
817-
$new_record[$key] = '0000-00-00 00:00:00';
817+
$new_record[$key] = null;
818818
}
819819
/*}*/
820820
break;

interface/lib/classes/tform_tpl_generator.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ function buildHTML($formDef, $tab) {
273273
case 'DATE':
274274
$type = 'date';
275275
$typevalue = '';
276-
$defaultValue = ($field["default"] != '')?$field["default"]:'0000-00-00';
276+
$defaultValue = ($field["default"] != '')?$field["default"]:null;
277277
break;
278278
}
279279

interface/web/tools/import_vpopmail.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ function start_import() {
231231
"cc" => '',
232232
"homedir" => '/var/vmail',
233233
"autoresponder" => 'n',
234-
"autoresponder_start_date" => '0000-00-00 00:00:00',
235-
"autoresponder_end_date" => '0000-00-00 00:00:00',
234+
"autoresponder_start_date" => null,
235+
"autoresponder_end_date" => null,
236236
"autoresponder_subject" => 'Out of office reply',
237237
"autoresponder_text" => '',
238238
"move_junk" => 'n',

server/lib/classes/cron.d/400-openvz.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function onRunJob() {
5656

5757
if ($app->dbmaster == $app->db) {
5858
//* Check which virtual machines have to be deactivated
59-
$sql = "SELECT * FROM openvz_vm WHERE active = 'y' AND active_until_date != '0000-00-00' AND active_until_date < CURDATE()";
59+
$sql = "SELECT * FROM openvz_vm WHERE active = 'y' AND active_until_date IS NOT NULL AND active_until_date < CURDATE()";
6060
$records = $app->db->queryAllRecords($sql);
6161
if(is_array($records)) {
6262
foreach($records as $rec) {

server/plugins-available/maildeliver_plugin.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function update($event_name, $data) {
138138
$tpl->setVar('move_junk', $data["new"]["move_junk"]);
139139

140140
// Check autoresponder dates
141-
if($data["new"]["autoresponder_start_date"] == '0000-00-00 00:00:00' && $data["new"]["autoresponder_end_date"] == '0000-00-00 00:00:00') {
141+
if((!$data['new']['autoresponder_start_date'] || $data["new"]["autoresponder_start_date"] == '0000-00-00 00:00:00') && (!$data['new']['autoresponder_end_date'] || $data["new"]["autoresponder_end_date"] == '0000-00-00 00:00:00')) {
142142
$tpl->setVar('autoresponder_date_limit', 0);
143143
} else {
144144
$tpl->setVar('autoresponder_date_limit', 1);

0 commit comments

Comments
 (0)