Marcel
Active member
I've written an addon to add the ability to archive threads.
It adds two colunns/options to the xf_forum table for the Forum Editor so we can set each one to archive to on a per-forum basis.
Here is my DataWriter Code
The problem is the conditional. The code works fine without it, it presents the forum options which I set OK.
As soon as I then archive a thread...the forum options are removed.
I'm assuming because when it's rebuilding the discussion after the move, it's also using the Forum DataWriter, and running through the _PreSave code again...and because there's no forum options in the $POST, it's assuming I've set them as Disabled / 0.
So I put in the conditional, using the discussion from digitalpoint and Mike/Kier here
This works, but the conditional throws an error with TapaTalk, and tbh I'd rather work around it at my end.
It adds two colunns/options to the xf_forum table for the Forum Editor so we can set each one to archive to on a per-forum basis.
Here is my DataWriter Code
PHP:
<?php
class MaB_Arch_DataWriter_Forum extends XFCP_MaB_Arch_DataWriter_Forum
{
protected function _getFields()
{
$fields = parent::_getFields();
$fields['xf_forum']['mab_arch_archive_enabled'] = array(
'type' => self::TYPE_UINT, 'default' => 0
);
$fields['xf_forum']['mab_arch_archive_forumid'] = array(
'type' => self::TYPE_UINT, 'default' => 0
);
return $fields;
}
protected function _preSave()
{
$parent = parent::_preSave();
// only run this conditional if we are editing a forum
if ($GLOBALS['fc']->route()->getControllerName() === 'XenForo_ControllerAdmin_Forum')
{
// is the 'enabled' checkbox ticked?
if(isset($_POST['mab_arch_archive_enabled']))
{
// if so store the entered archive forum id into a variable and pass it
// to the datawriter and set the enabled flag to 1
$mab_arch_archive_forumid = $_POST['mab_arch_archive_forumid'];
$this->set('mab_arch_archive_enabled', 1);
$this->set('mab_arch_archive_forumid', $mab_arch_archive_forumid);
}
else
{
// if not then ignore what was typed in and just set the archive forum id to 0
$this->set('mab_arch_archive_enabled', 0);
$this->set('mab_arch_archive_forumid', NULL);
}}
return $parent;
}
}
The problem is the conditional. The code works fine without it, it presents the forum options which I set OK.
As soon as I then archive a thread...the forum options are removed.
I'm assuming because when it's rebuilding the discussion after the move, it's also using the Forum DataWriter, and running through the _PreSave code again...and because there's no forum options in the $POST, it's assuming I've set them as Disabled / 0.
So I put in the conditional, using the discussion from digitalpoint and Mike/Kier here
This works, but the conditional throws an error with TapaTalk, and tbh I'd rather work around it at my end.