XF 2.2 delete from x with thread_id when thread is deleted

Robert9

Well-known member
I have a table x; it has a field thread_id

if thread 212 is deleted (or merged?!), I want to delete the column in x where thread_id is 212

i found entity_post_delete, but no entity_thread_delete


i found a listener with something like:

Code:
    public static function threadEntityPostDelete(\XF\Mvc\Entity\Entity $entity)
    {
        $entity->db()->delete('xf_r9_example', 'thread_id = ?', $entity->thread_id);
    }

Do we have another example to delete something?
resource and thread is one; i will check it.
 
1.
protected function _postDelete() in entity thread can have a new line to
$db->delete('xf_my_table', 'thread_id = ?', $this->thread_id);
 
Code:
class Thread extends XFCP_Thread
{
    protected function _postDelete()
    {
        parent::_postDelete();

        $this->db()->query('DELETE FROM xf_r9_example WHERE thread_id  = ?', $this->thread_id);
    }
}
 
But i still fight with soft delete and undelete;
result should be:

$this->db()->query('UPDATE xf_r9_example SET thread_state = 'visible' WHERE thread_id = ?', $this->thread_id);
$this->db()->query('UPDATE xf_r9_example SET thread_state = 'deleted' WHERE thread_id = ?', $this->thread_id);
 
Top Bottom