Lack of interest Validation when creating new Code Event Listener

  • Thread starter Thread starter ragtek
  • Start date Start date
This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.
R

ragtek

Guest
ATM it only checks if the class & method exists.

I've made a stupid mistake and insterted the extended class & method instead of the code listener callback names.


I used
PHP:
class Ragtek_C1002_Model_UserIgnore extends
 
    XenForo_Model_UserIgnore
{
    public function ignoreUsers($userId, $ignoredUserIds)
    {
 
        return parent::ignoreUsers($userId, $ignoredUserIds);
    }
}
instead of

PHP:
class Ragtek_C1002_StaticMethods{
 
    public static function listener($class, &$extend){
        if ($class == 'XenForo_Model_UserIgnore'){
            $extend[] = 'Ragtek_C1002_Model_UserIgnore';
        }
    }

this was valid and after it was saved, my board stopped working and i got a exception on loading every page.......


i added now a validation to check if the method is static to the preSave method in the event listener dw


PHP:
protected function _preSave()
{
if ($this->isChanged('callback_class') || $this->isChanged('callback_method'))
{
$class = $this->get('callback_class');
$method = $this->get('callback_method');
           
 
 
 
if (!XenForo_Application::autoload($class) || !method_exists($class, $method))
{
$this->error(new XenForo_Phrase('please_enter_valid_callback_method'), 'callback_method');
}
            //ragtek change
            $ref =  new ReflectionMethod($class, $method);
            if (!$ref->isStatic()){
                $this->error('no static method');
            }
            //ragtek change end
}
}
and now it's throwing an error before it gets saved, instead of saving it and stopping the board:)

it's no big deal for us developers,but it's not necessary to disable the event listener system and delete the listener if it also checks if the callback is static:)
 
Upvote 1
This suggestion has been closed. Votes are no longer accepted.
Top Bottom