XF 2.2 Extending registration

stromb0li

Well-known member
I am trying to run a set of actions upon registration. Looking through some existing posts, it appears RegistrationComplete is the proper class to extend after the account is approved / validated, but I cannot seem to get the action to trigger upon successful registration.

class_extensions.xml
XML:
<?xml version="1.0" encoding="utf-8"?>
<class_extensions>
    <extension from_class="XF\Service\User\RegistrationComplete" to_class="Notes\XF\Service\User\RegistrationComplete" execute_order="10" active="1"/>
</class_extensions>

Notes\XF\Service\User\RegistrationComplete.php
PHP:
<?php
namespace Notes\XF\Service\User;
class RegistrationComplete extends XFCP_RegistrationComplete
{
    public function actionIndex()
    {        
        throw new Exception("Weee! You found me!");
    }
}
 
It's a service rather than a controller, so there is no actionIndex method. Each service is a bit different, so I'd recommend having a look at the class to see what it does (this one is pretty simple). You can use your IDE or editor to find references to the class to find out where it's used and how.
 
I followed this tutorial here to setup VSCode, but when I am extending XFCP_RegistrationComplete, it says Notes\XF\Service\User\XFCP_RegistrationComplete is undefined.

I opened the class itself and see triggerCompletionActions, but that doesn't seem to execute as well?
 
Last edited:
For VSCode I would recommend generating stubs by running the php cmd.php xf-dev:generate-phpstorm-meta CLI command and following the quick-start instructions for the Intelephense extension. When you create a class extension it should also generate the /_output/extension_hint.php file to allow resolution of proxied classes.

I opened the class itself and see triggerCompletionActions, but that doesn't seem to execute as well?
It is executed when a user receives the valid state either immediately after registration, after confirming their email address, or after being approved from the approval queue.
 
It is executed when a user receives the valid state either immediately after registration, after confirming their email address, or after being approved from the approval queue.
I flipped a user to from registered to unregistered group and requires approval so it moves to the approval queue, but I don't see the function execute, after approving the user.
 
Last edited:
I can't reproduce this. If I modify the method to throw an exception, it is logged in the server error log when approving the user. Note that the approval queue is processed in the background using the job queue, which suppresses errors from being shown in the UI.
 
I can't reproduce this. If I modify the method to throw an exception, it is logged in the server error log when approving the user. Note that the approval queue is processed in the background using the job queue, which suppresses errors from being shown in the UI.
Strange, I was using the admin portal server error logs as my case to catch this as well but don't see any. Your two changes are only these?

class_extensions.xml
XML:
<?xml version="1.0" encoding="utf-8"?>
<class_extensions>
    <extension from_class="XF\Service\User\RegistrationComplete" to_class="Notes\XF\Service\User\RegistrationComplete" execute_order="10" active="1"/>
</class_extensions>

Notes\XF\Service\User\RegistrationComplete.php
PHP:
<?php
namespace Notes\XF\Service\User;
class RegistrationComplete extends XFCP_RegistrationComplete
{
    public function triggerCompletionActions()
    {      
        throw new Exception("Weee! You found me!");
    }
}

Cheers!
 
Yeah. You'll need to prefix Exception with \ to indicate it is not in the local namespace, but you should get an error either way:

screenshot-m7y8A6.webp
 
Yeah. You'll need to prefix Exception with \ to indicate it is not in the local namespace, but you should get an error either way:

View attachment 290488
What version of PHP are you running? Wondering if this is handled differently on my version? I haven't made it to 8.x yet.

Also to simulate this, I'm using an existing user, switching their user state to Awaiting for approval, and then approving them. Is it a one-time deal for registration completion after first approval or will triggerCompletionActions execute any time approval happens from approval-queue?
 
I tested on PHP 8.2 but to the best of my knowledge it shouldn't be handled any differently in prior versions. The method should be executed any time a user is approved from the queue. It might be worth trying to register a new account to narrow down whether the extension isn't working at all or if it's something unique to the approval queue.
 
Edit; I finally got it! Looks like upgrading to 8.2.8 helped! Not sure why, but I'll call it good if 8.2.8 is officially supported by XenForo :p
 
Last edited:
Back
Top Bottom