xf_phantom
Well-known member
Wouldn't it make sense to move the content of XenForo_EditHistoryHandler_Post::revertToVersion to a new abstract method in the XenForo_EditHistoryHandler_Abstract and have only the the datawriter as variable?
I'm asking because this method can be used for ALL content types which are using the XenForo_DataWriter_DiscussionMessage_Abstract class.
The only difference is the message datawriter name.
Just to be sure you know what i mean:
or another (probably better solution) =>
A new abstract XenForo_EditHistoryHandler_Message class (like the DiscussionMessage Datawriter) which
includes a new abstract method getMessageDataWriter and which also implements already
This would reduce the necessary code
I'm asking because this method can be used for ALL content types which are using the XenForo_DataWriter_DiscussionMessage_Abstract class.
The only difference is the message datawriter name.
Just to be sure you know what i mean:
PHP:
public function revertToVersion(array $content, $revertCount, array $history, array $previous = null)
{
$dw = XenForo_DataWriter::create('XenForo_DataWriter_DiscussionMessage_Post', XenForo_DataWriter::ERROR_SILENT);
$dw->setExistingData($content);
$dw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_EDIT_DATE_DELAY, -1);
$dw->setOption(XenForo_DataWriter_DiscussionMessage::OPTION_IS_AUTOMATED, true);
$dw->set('message', $history['old_text']);
$dw->set('edit_count', $dw->get('edit_count') + 1);
if ($dw->get('edit_count'))
{
if (!$previous || $previous['edit_user_id'] != $content['user_id'])
{
// if previous is a mod edit, don't show as it may have been hidden
$dw->set('last_edit_date', 0);
}
else if ($previous && $previous['edit_user_id'] == $content['user_id'])
{
$dw->set('last_edit_date', $previous['edit_date']);
$dw->set('last_edit_user_id', $previous['edit_user_id']);
}
}
return $dw->save();
}
or another (probably better solution) =>
A new abstract XenForo_EditHistoryHandler_Message class (like the DiscussionMessage Datawriter) which
includes a new abstract method getMessageDataWriter and which also implements already
- revertToVersion (as i said, only the dw is dynamic)
- getText (it's "always" the message key if XenForo_DataWriter_DiscussionMessage is being used
- formatHistory
This would reduce the necessary code
Upvote
0