No offence but the code is kinda hard to follow so it was a pain debugging.
Anyway, I'm using the following code as a fix.
It uses $updateDate
to see if date changed and if so, it updates the dateline by itself outside of the $update
scope.
Perhaps you have a better solution in mind as I didn't want to spend any more time debugging.
Diff check the following with the current hook_editpost_end
function in the repo.
// Hook: editpost_end/datahandler_post_update
function hook_editpost_end(&$dh)
{
global $fid, $ougc_adminpostedit, $mybb;
$ougc_adminpostedit = '';
if(!is_moderator($fid, 'caneditposts') || !is_member($mybb->settings['ougc_adminpostedit_groups']))
{
return;
}
global $lang, $templates, $pid, $db;
$this->load_language();
$post = get_post($pid);
$p = array(
'dateline' => $post['dateline'],
'uid' => $post['uid'],
'username' => $post['username'],
'ipaddress' => my_inet_ntop($db->unescape_binary($post['ipaddress'])),
'silent' => ''
);
$timestamp = (int)$p['dateline'];
$search_username = htmlspecialchars_uni(trim($p['username']));
if($mybb->request_method == 'post')
{
$input = $mybb->get_input('ougc_adminpostedit', 2);
$timestamp = (int)$input['timestamp'];
$search_username = htmlspecialchars_uni(trim($input['username']));
$post_update_data = array();
if($p['dateline'] != $input['timestamp'] && TIME_NOW >= $input['timestamp'])
{
$p['dateline'] = $post_update_data['dateline'] = (int)$input['timestamp'];
$updateDate = true;
}
if($p['username'] != $input['username'])
{
if($user = get_user_by_username($input['username'], array('fields' => array('username'))))
{
$p['uid'] = $post_update_data['uid'] = (int)$user['uid'];
$p['username'] = $user['username'];
$post_update_data['username'] = $db->escape_string($p['username']);
$update = true;
}
}
if($p['ipaddress'] != $input['ipaddress'])
{
if(preg_match('#^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$#', $input['ipaddress']))
{
$ipaddress = array_map('intval', explode('.', $input['ipaddress']));
if(!($ipaddress[0] > 255 || $ipaddress[1] > 255 || $ipaddress[2] > 255 || $ipaddress[3] > 255))
{
$p['ipaddress'] = implode('.', $ipaddress);
$post_update_data['ipaddress'] = $db->escape_binary(my_inet_pton($p['ipaddress']));
}
}
}
if($input['silent'])
{
$p['silent'] = ' checked="checked"';
}
if($dh instanceof PostDataHandler)
{
$dh->post_update_data = array_merge($dh->post_update_data, $post_update_data);
$thread = get_thread($dh->data['tid']);
if(isset($update))
{
global $plugins;
$forum = get_forum($dh->data['fid']);
$user = get_user($dh->post_update_data['uid']);
$update_query = array();
if($thread['dateline'] > $user['lastpost'])
{
$update_query['lastpost'] = "'{$thread['dateline']}'";
}
if($forum['usepostcounts'])
{
$update_query['postnum'] = 'postnum+1';
}
if($forum['usethreadcounts'])
{
$update_query['threadnum'] = 'threadnum+1';
}
if(!empty($update_query))
{
$db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
}
$user = get_user($dh->data['uid']);
$update_query = array();
if($thread['dateline'] < $user['lastpost'])
{
$update_query['lastpost'] = "'{$thread['dateline']}'";
}
if($forum['usepostcounts'])
{
$update_query['postnum'] = 'postnum-1';
}
if($forum['usethreadcounts'])
{
$update_query['threadnum'] = 'threadnum-1';
}
if(!empty($update_query))
{
$db->update_query('users', $update_query, "uid='{$user['uid']}'", 1, true);
}
if($thread['firstpost'] == $post['pid'])
{
$thread_update = array(
'uid' => $dh->post_update_data['uid'],
'username' => $dh->post_update_data['username']
);
$db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
}
$plugins->add_hook('datahandler_post_update_end', array($this, 'hook_datahandler_post_update_end'));
}
if(isset($updateDate))
{
if($thread['firstpost'] == $post['pid'])
{
$thread_update = array(
'dateline' => $dh->post_update_data['dateline']
);
$db->update_query('threads', $thread_update, "tid='{$thread['tid']}'");
}
}
return;
}
}
$ougc_adminpostedit = eval($templates->render('ougcadminpostedit'));
}