Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define timestamp columns explicitly #1019

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public_html/lists/admin/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
'statistics' => !empty($_POST['statistics']),
'settings' => !empty($_POST['settings']),
);
Sql_Query(sprintf('update %s set modified=now(), modifiedby = "%s", privileges = "%s" where id = %d',
Sql_Query(sprintf('update %s set modifiedby = "%s", privileges = "%s" where id = %d',
$GLOBALS['tables']['admin'], adminName($_SESSION['logindetails']['id']), sql_escape(serialize($privs)),
$id));

Expand Down
2 changes: 1 addition & 1 deletion public_html/lists/admin/inc/userlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function addNewUser($email, $password = '')
$blacklist = isBlackListed($email);
$passwordEnc = encryptPass($password);
Sql_Query(sprintf('insert into %s set email = "%s", blacklisted = "%d",
entered = now(),modified = now(),password = "%s",
entered = now(),password = "%s",
passwordchanged = now(),disabled = 0,
uniqid = "%s",htmlemail = 1, uuid = "%s"
', $GLOBALS['tables']['user'], sql_escape($email), $blacklist, $passwordEnc, getUniqid(), (string) uuid::generate(4)));
Expand Down
4 changes: 2 additions & 2 deletions public_html/lists/admin/initialise.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ function output($message)
$_SESSION['firstinstall'] = 1;
$adminemail = $_REQUEST['adminemail'];
$adminpass = $_REQUEST['adminpassword'];
Sql_Query(sprintf('insert into %s (loginname,namelc,email,created,modified,password,passwordchanged,superuser,disabled)
values("%s","%s","%s",now(),now(),"%s",now(),%d,0)',
Sql_Query(sprintf('insert into %s (loginname,namelc,email,created,password,passwordchanged,superuser,disabled)
values("%s","%s","%s",now(),"%s",now(),%d,0)',
$tables['admin'], 'admin', 'admin', sql_escape($adminemail), encryptPass($adminpass), 1));

//# let's add them as a subscriber as well
Expand Down
4 changes: 2 additions & 2 deletions public_html/lists/admin/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@
$idToDuplicate = sprintf('%d', $_GET['duplicate']);
$action_result .= $GLOBALS['I18N']->get('Copying')." $idToDuplicate ..";
Sql_Query(sprintf('insert into %s (uuid, subject, fromfield, tofield, replyto, message, textmessage, footer, entered,
modified, embargo, repeatuntil, repeatinterval, requeueinterval, status, htmlformatted, sendformat, template, rsstemplate, owner)
embargo, repeatuntil, repeatinterval, requeueinterval, status, htmlformatted, sendformat, template, rsstemplate, owner)
select "%s", subject, fromfield, tofield, replyto, message, textmessage, footer, now(),
now(), now(), now(), repeatinterval, requeueinterval, "draft", htmlformatted,
now(), now(), repeatinterval, requeueinterval, "draft", htmlformatted,
sendformat, template, rsstemplate, "%d" from %s
where id = %d',
$GLOBALS['tables']['message'], (string) Uuid::generate(4), $_SESSION['logindetails']['id'],$GLOBALS['tables']['message'],
Expand Down
18 changes: 9 additions & 9 deletions public_html/lists/admin/structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
'optedin' => array('tinyint default 0', 'sysexp:Did this subscriber manually confirm'),
'bouncecount' => array('integer default 0', 'sysexp:Number of bounces'),
'entered' => array('datetime', 'sysexp:Entered'),
'modified' => array('timestamp', 'sysexp:Last Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'sysexp:Last Modified'),
'uniqid' => array('varchar(255)', 'sysexp:Unique ID'),
'uuid' => array('varchar(36) default ""', 'sys:UUID'),
'htmlemail' => array('tinyint default 0', 'Send this subscriber HTML emails'),
Expand Down Expand Up @@ -89,7 +89,7 @@
'listorder' => array('integer', 'Order of listing'),
'prefix' => array('varchar(10)', 'Subject prefix'),
'rssfeed' => array('varchar(255)', 'Rss Feed'),
'modified' => array('timestamp', 'Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'Modified'),
'active' => array('tinyint', 'Active'),
'owner' => array('integer', 'Admin who is owner of this list'),
'category' => array('varchar(255) default ""', 'List category'),
Expand All @@ -108,7 +108,7 @@
'userid' => array('integer not null', 'Subscriber ID'),
'listid' => array('integer not null', 'List ID'),
'entered' => array('datetime', 'Entered'),
'modified' => array('timestamp', 'Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'Modified'),
'primary key' => array('(userid,listid)', 'Primary Key'),
'index_1' => array('userenteredidx (userid,entered)', ''),
'index_2' => array('userlistenteredidx (userid,listid,entered)', ''),
Expand All @@ -126,7 +126,7 @@
'textmessage' => array('longtext', 'Text version of Message'),
'footer' => array('text', 'Footer for a message'),
'entered' => array('datetime', 'Entered'),
'modified' => array('timestamp', 'Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'Modified'),
'embargo' => array('datetime', 'Time to send message'),
'repeatinterval' => array('integer default 0', 'Number of seconds to repeat the message'),
'repeatuntil' => array('datetime', 'Final time to stop repetition'),
Expand Down Expand Up @@ -163,7 +163,7 @@
'messageid' => array('integer not null', 'Message ID'),
'listid' => array('integer not null', 'List ID'),
'entered' => array('datetime', 'Entered'),
'modified' => array('timestamp', 'Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'Modified'),
'unique_1' => array('(messageid,listid)', ''),
'index_1' => array('listmessageidx (listid,messageid)', ''),
),
Expand Down Expand Up @@ -223,7 +223,7 @@
'sendprocess' => array( // keep track of running send processes to avoid to many running concurrently
'id' => array('integer not null primary key auto_increment', 'ID'),
'started' => array('datetime', 'Start Time'),
'modified' => array('timestamp', 'Modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'Modified'),
'alive' => array('integer default 1', 'Is this process still alive?'),
'ipaddress' => array('varchar(50)', 'IP Address of who started it'),
'page' => array('varchar(100)', 'The page that this process runs in'),
Expand Down Expand Up @@ -261,7 +261,7 @@
'user' => array('integer not null', 'subscriber ID'),
'message' => array('integer not null', 'Message ID'),
'bounce' => array('integer not null', 'Bounce ID'),
'time' => array('timestamp', 'When did it bounce'),
'time' => array('timestamp not null default current_timestamp on update current_timestamp', 'When did it bounce'),
'index_1' => array('umbindex (user,message,bounce)', 'index'),
'index_2' => array('useridx (user)', 'index'),
'index_3' => array('msgidx (message)', 'index'),
Expand All @@ -273,7 +273,7 @@
'message' => array('integer not null', 'Message ID'),
'forward' => array('varchar(255)', 'Forward email'),
'status' => array('varchar(255)', 'Status of forward'),
'time' => array('timestamp', 'When was it forwarded'),
'time' => array('timestamp not null default current_timestamp on update current_timestamp', 'When was it forwarded'),
'index_1' => array('usermessageidx (user,message)', 'index'),
'index_2' => array('useridx (user)', 'index'),
'index_3' => array('messageidx (message)', 'index'),
Expand All @@ -290,7 +290,7 @@
'namelc' => array('varchar(255)', 'sys:Normalised loginname'),
'email' => array('varchar(255) not null', 'Email'),
'created' => array('datetime', 'sys:Time Created'),
'modified' => array('timestamp', 'sys:Time modified'),
'modified' => array('timestamp not null default current_timestamp on update current_timestamp', 'sys:Time modified'),
'modifiedby' => array('varchar(66)', 'sys:Modified by'),
'password' => array('varchar(255)', 'sys:Password'),
'passwordchanged' => array('date', 'sys:Last time password was changed'),
Expand Down
28 changes: 28 additions & 0 deletions public_html/lists/admin/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,34 @@ function output($message)
Sql_Query("alter table {$GLOBALS['tables']['admin']} modify modifiedby varchar(66) default ''");
}

if (version_compare($dbversion, '3.6.15', '<')) {
// Ensure timestamp field does not have null values then give explicit defaults
Sql_Query(sprintf('update %s set modified = created where modified is null', $GLOBALS['tables']['admin']));
Sql_Query(sprintf('update %s set modified = entered where modified is null', $GLOBALS['tables']['list']));
Sql_Query(sprintf('update %s set modified = entered where modified is null', $GLOBALS['tables']['listmessage']));
Sql_Query(sprintf('update %s set modified = entered where modified is null', $GLOBALS['tables']['listuser']));
Sql_Query(sprintf('update %s set modified = entered where modified is null', $GLOBALS['tables']['message']));
Sql_Query(sprintf('update %s set modified = started where modified is null', $GLOBALS['tables']['sendprocess']));
Sql_Query(sprintf('update %s set modified = entered where modified is null', $GLOBALS['tables']['user']));
Sql_Query(sprintf('update %s set time = current_timestamp where time is null', $GLOBALS['tables']['user_message_bounce']));
Sql_Query(sprintf('update %s set time = current_timestamp where time is null', $GLOBALS['tables']['user_message_forward']));

foreach (['admin', 'list', 'listmessage' , 'listuser', 'message', 'sendprocess', 'user'] as $t) {
Sql_Query(sprintf(
'alter table %s modify modified timestamp not null default current_timestamp on update current_timestamp',
$GLOBALS['tables'][$t]
));
}
Sql_Query(sprintf(
'alter table %s modify time timestamp not null default current_timestamp on update current_timestamp',
$GLOBALS['tables']['user_message_bounce']
));
Sql_Query(sprintf(
'alter table %s modify time timestamp not null default current_timestamp on update current_timestamp',
$GLOBALS['tables']['user_message_forward']
));
}

//# longblobs are better at mixing character encoding. We don't know the encoding of anything we may want to store in cache
//# before converting, it's quickest to clear the cache
clearPageCache();
Expand Down
8 changes: 4 additions & 4 deletions public_html/lists/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,8 @@ function forwardPage($id)
sendAdminCopy(s('Message Forwarded'),
s('%s has forwarded message %d to %s', $userdata['email'], $mid, $email),
$messagelists);
Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
values(%d,%d,"%s","sent",now())',
Sql_Query(sprintf('insert into %s (user,message,forward,status)
values(%d,%d,"%s","sent")',
$tables['user_message_forward'], $userdata['id'], $mid, $email));
if ($iCountFriends) {
++$nFriends;
Expand All @@ -1156,8 +1156,8 @@ function forwardPage($id)
sendAdminCopy(s('Message Forwarded'),
s('%s tried forwarding message %d to %s but failed', $userdata['email'], $mid, $email),
$messagelists);
Sql_Query(sprintf('insert into %s (user,message,forward,status,time)
values(%d,%d,"%s","failed",now())',
Sql_Query(sprintf('insert into %s (user,message,forward,status)
values(%d,%d,"%s","failed")',
$tables['user_message_forward'], $userdata['id'], $mid, $email));
$ok = false;
}
Expand Down
Loading