We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19388
    • 297 Posts
    Hi people,
    I’ve developed an small plugin that should be triggered when a web change its password ( OnWebChangePassword ). The problem is my plugin is not being triggered when a web user change its password ( nor from the manager nor from WebChangePwd snippet ). I have other plugins developed with other events such as OnWebSaveUser that works fine, but not this one...
    I SMFConnect, I’ve testet disabling its OnWebChangePassword, but the problem persists.

    To make a test, I use only:

    $e = $modx->Event;
    $modx->logEvent(0,1,'error', 'error');
    echo 'evento:'.$e->name;
    exit;


    With this code, an error should be shown, another should be logged, and then a blank page should be shown ( exit; ). But nothing happens.
    Any ideas?
    Thanks in advance for your help

    EDIT: I’ve used the "test code plugin" for login and logout events and it works fine, but not for OnWebChangePassword event
      • 19388
      • 297 Posts
      I’ve tested it on some Evo versions ( 1.0.1 - 1.0.4 ) and I have allways the same result: nothing for the event OnWebChangePassword. Other events such as
      OnWebSaveUser, OnWebLogout, OnWebLogin works fine, but not this one. Could it be a MODx bug? I’m doing something wrong? I’m using now a simple "test plugin":

      print_r("plugin triggered!");
      echo '<script type="text/javascript">alert("plugin triggered!");</script>';
      exit;

      • That is interesting. Just tested in the Manager, and indeed the OnWebChangePassword is not being invoked. Now the big question is, why not?

        In the database there is a space following the name ’OnWebChangePassword ’ in the name field of system_eventnames. So when the invokeEvent function checks for the existence of the event ’OnWebChangePassword’ (no trailing space) it doesn’t find it and returns false.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 19388
          • 297 Posts
          It is strange because the event is invoked using invokeEvent function. Unfortunately I can take a deeper look at the problem because i’m on holidays now and I have no computer nor internet access ( now on the mobile ). But I have another "big" question. How is posible nobody reported it before?!?! There are plugins that uses this event, for example smf bridge, wich has a function to sync password between modx and smf when it is changed in modx. Recently I asked about why password sync was not working and a user told me there was no solution... But the work was done, the code is written! ( I thought the problem was it was not implemented ) the problem was this bug.
          • A stupid typo in the database.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 4310
              • 2,310 Posts
              Nice spot Susan smiley
              Not easy to see a trailing space.
              Are you’re going to JIRA it?
              • Yeah, I was just thinking I should do that. As soon as I recover; that was a rather intensive couple of hours of step-by-step troubleshooting trying to figure out why that one wasn’t working. I ended up looking at a print_r of the list of known events and the plugins associated with them, thinking about the Jewish joke of "Why is this knight not like every other knight?", when I spotted that stupid space.
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                  • 4310
                  • 2,310 Posts
                  I was looking in the file system, trying to follow the invokeEvent trail, never thought to check the DB embarrassed
                  • Actually, I tracked it to the second check in invokeEvent(); I checked the database almost the first thing and didn’t notice the space then.
                            if (!isset ($this->pluginEvent[$evtName]))
                                return false;
                    

                    so I inserted
                    echo "<pre>";
                    print_r($this->pluginEvent);
                    echo "</pre>";

                    and there, in all its glory, was the OnWebChangePassword event with the plugin I’d created, testEvent! Yet if I became specific and tried
                    print_r($this->pluginEvent[’OnWebChangePassword’] I got nothing. So I stared at the full pluginEvent display for a while, thinking spelling? typo? I even enlarged the font to see it all better. Then I noticed the space, and the rest was obvious.
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 19388
                      • 297 Posts
                      Oh! Fucking space! I was checking the code these days but it’s harder for me because I don’t know the core so well. I took a look to document parses class and the change password and invokeEvents functions but didnt noticed something... I was suposing that could be something related to database, but this "hell" because a whitespace... Congratulations for the work people! It’s great to see the best devel team working together smiley MODx forever! laugh