1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XenForo_DataWriter_DiscussionMessage not getting called

Discussion in 'XenForo Development Discussions' started by mgl, Feb 23, 2015.

  1. mgl

    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
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    Marcus and mgl like this.
  3. Xon

    Xon Well-Known Member

    @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;
    }
    
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    I know, I already said that:

     
  5. Marcus

    Marcus Well-Known Member

    That's a nice function and a huge help for debugging while coding, thanks.
     

Share This Page