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

How to extend _updateModeratorLogThreadEdit to add another case

Discussion in 'XenForo Development Discussions' started by arms, Mar 25, 2014.

  1. arms

    arms Active Member

    I'm now closing off all the nice to haves on my extra prefix addon (suffix)

    One is to include any changes in the mod log.

    atm changes are recorded as:

    Code:
    Thread edited (suffix_id)
    So I want to add the suffix_id case

    PHP:
    case 'suffix_id':
                            if (
    $oldValue)
                            {
                                
    $phrase = new XenForo_Phrase('thread_suffix_' $oldValue);
                                
    $oldValue $phrase->render();
                            }
                            else
                            {
                                
    $oldValue '-';
                            }
                            
    XenForo_Model_Log::logModeratorAction(
                                
    'thread'$thread'suffix', array('old' => $oldValue)
                            );
                            break;


    But as far as i can see extending _updateModeratorLogThreadEdit will mean that I will run my case as well as all cases in the parent which gives me duplicates:

    upload_2014-3-25_10-41-35.png

    Anyone got any advice?

    PHP:
    protected function _updateModeratorLogThreadEdit(array $threadXenForo_DataWriter_Discussion_Thread $dw, array $skip = array())
        {
            
    $newData $dw->getMergedNewData();
            if (
    $newData)
            {
                
    $oldData $dw->getMergedExistingData();
                
    $basicLog = array();

                foreach (
    $newData AS $key => $value)
                {
                    
    $oldValue = (isset($oldData[$key]) ? $oldData[$key] : '-');
                    switch (
    $key)
                    {
                        case 
    'sticky':
                            
    XenForo_Model_Log::logModeratorAction('thread'$thread, ($value 'stick' 'unstick'));
                            break;

                        case 
    'discussion_open':
                            
    XenForo_Model_Log::logModeratorAction('thread'$thread, ($value 'unlock' 'lock'));
                            break;

                        case 
    'discussion_state':
                            if (
    $value == 'visible' && $oldValue == 'moderated')
                            {
                                
    XenForo_Model_Log::logModeratorAction('thread'$thread'approve');
                            }
                            else if (
    $value == 'visible' && $oldValue == 'deleted')
                            {
                                
    XenForo_Model_Log::logModeratorAction('thread'$thread'undelete');
                            }
                            else if (
    $value == 'deleted')
                            {
                                
    XenForo_Model_Log::logModeratorAction(
                                    
    'thread'$thread'delete_soft', array('reason' => '')
                                );
                            }
                            else if (
    $value == 'moderated')
                            {
                                
    XenForo_Model_Log::logModeratorAction('thread'$thread'unapprove');
                            }
                            break;

                        case 
    'title':
                            
    XenForo_Model_Log::logModeratorAction(
                                
    'thread'$thread'title', array('old' => $oldValue)
                            );
                            break;

                        case 
    'prefix_id':
                            if (
    $oldValue)
                            {
                                
    $phrase = new XenForo_Phrase('thread_prefix_' $oldValue);
                                
    $oldValue $phrase->render();
                            }
                            else
                            {
                                
    $oldValue '-';
                            }
                            
    XenForo_Model_Log::logModeratorAction(
                                
    'thread'$thread'prefix', array('old' => $oldValue)
                            );
                            break;

                        default:
                            if (!
    in_array($key$skip))
                            {
                                
    $basicLog[$key] = $oldValue;
                            }
                    }
                }

                if (
    $basicLog)
                {
                    
    XenForo_Model_Log::logModeratorAction('thread'$thread'edit'$basicLog);
                }
            }
        }
     
  2. Nobita.Kun

    Nobita.Kun Well-Known Member

    I think the varibale $skip can help for you.
    PHP:
    protected function _updateModeratorLogThreadEdit(array $threadXenForo_DataWriter_Discussion_Thread $dw, array $skip = array())
    {
        if (isset(
    $skip['your_index_key']))
        {
            
    // running your code
        
    }
        else
        {
            return 
    parent::_updateModeratorLogThreadEdit($thread$dw$skip);
        }
    }
     
    arms likes this.
  3. arms

    arms Active Member

    Thank you very much. Why didn't I read the info for the parameters :oops:

    Added the $skip[]='suffix_id';
     

Share This Page