XenForo_DataWriter_DiscussionMessage not getting called

mgl

Member
Hello,

I am doing an add-on to do some processing after a message\thread is deleted. But I can't seem to get my class loaded.

Here is my code event:

HTML:
<listener event_id="load_class_datawriter" execute_order="10" callback_class="TK_dataproc_Index" callback_method="LoadProxy" active="1" hint="" description=""/>

My LoadProxy:

Code:
<?php
    /**
    *
    */
    class TK_dataproc_Index
    {
        public static function LoadProxy($class, array &$extend)
        {
            file_put_contents("d:\\xen.txt", $class);
            $proxy = array(
                'XenForo_DataWriter_DiscussionMessage'
            );

            if (in_array($class, $proxy))
            {
                $extend[] = str_replace('Index', '', __CLASS__) . $class;
            }
        }
    }
?>


But when I check the text file, the only class that gets loaded when I delete a message is XenForo_DataWriter_Forum. Am I missing something?

Thank you
 
Isn't your logging only going to log the most recent class it accessed?

There's a helper in XenForo that will help with this (or you could use the FILE_APPEND flag on the file_put_contents call).

PHP:
XenForo_Helper_File::log('xen', $class);

That would continually log entries (time stamped) to internal_data/xen.log

I suspect the class probably being called is XenForo_DataWriter_DiscussionMessage_Post; though adjusting the logging will probably confirm that.
 
@Chris D resolveDynamicClass doesn't call listeners for classes in the class hierarchy; only the leaf node. ie XenForo_Model::create("XenForo_DataWriter_DiscussionMessage_Post"), listeners only trigger for XenForo_DataWriter_DiscussionMessage_Post.

As such @mgl needs to listen for:
  • XenForo_DataWriter_DiscussionMessage_Post
  • XenForo_DataWriter_DiscussionMessage_ProfilePost
And not:
  • XenForo_DataWriter_DiscussionMessage

Also @mgl on thing to keep in mind is that in_array is an array scan + function call overhead.

IMO, this is cleaner and easier:
Code:
switch($class)
{
  case 'XenForo_DataWriter_DiscussionMessage_Post':
  case 'XenForo_DataWriter_DiscussionMessage_ProfilePost':
      $extend[] = str_replace('Index', '', __CLASS__) . $class;
      break;
}
 
@Chris D resolveDynamicClass doesn't call listeners for classes in the class hierarchy; only the leaf node. ie XenForo_Model::create("XenForo_DataWriter_DiscussionMessage_Post"), listeners only trigger for XenForo_DataWriter_DiscussionMessage_Post.
I know, I already said that:

I suspect the class probably being called is XenForo_DataWriter_DiscussionMessage_Post
 
Top Bottom