Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

beforeControllerAction event not called for custom controller

  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209592 by jackrabbithanna
I've got a custom route and controller
Route definied in routes.php
$route+>/<_sid:\d+>/*'] = "custompath/version/<action>/sid/<_sid>";

Then I got a LS plugin, and subscribe to the beforeControllerAction event.
I know this works because I can get some diag output for surveys or admin pages

The controller provides HTML output, so I know that works.

class VersionController extends LSYii_Controller {

But for some reason, the plugin event subscriber never fires when I load the page for this controller.

Any ideas what I could be doing wrong?

Most recent stable version of LS 3.x

Thanks in advance!
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #209594 by DenisChenu
No real idea …
Maybe start without rewrite ?

Can you set your param to GET for testing purpose ?


Without real route : you want something like this

index.php?r=myowncontroller/myfunction&sid=123 for example ?

I don't know exactly but seems your APP didn't extend LSYii_Application
github.com/LimeSurvey/LimeSurvey/blob/bd...Application.php#L332

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209628 by jackrabbithanna
I appreciate your time on this. Forgive my ignorance.

I was thinking that adding a controller would automatically integrate similar to what is in Core.

Is there an example of adding a "real route" ?
If not using routes.php, as I documented, then where can I define them?

That may help me understand the difference and what I am doing wrong.

This Limesurvey installation is tightly integrated to a Drupal system, which also has CiviCRM

The purpose of this route is to display a saved version of somebody's responses to a survey, sort of a printable version, but draws in information from the user's Drupal user session and CiviCRM contact information. For every page load of a survey, or one of several custom routes, I need to check to make sure the user has a valid Drupal user session, and if valid, add data drawn from these systems into the $_SESSION

This was accomplished by hacking LSYii_Controller.php previously, trying to move this custom to a plugin. This way for both the standard survey form, and custom controllers could do this same thing.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #209637 by DenisChenu
I don't have idea on the good way to add a controller …


last time i need to do : i add a controller in application/controller directory …

I need to update then"welcome/survey list" page before twig.

I add HomeController.php
Code:
class HomeController extends LSYii_Controller
{
}


and in config 'defaultController' => 'home'

But after with route : it's just when url rewriting is activated.

Then : depend on the way you add the controller.
You must check www.yiiframework.com/doc/api/1.1
It's out of LimeSurvey here. (in my opinion)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209640 by jackrabbithanna
Somehow the admin controller does work though. Going to admin paths invoke the beforeControllerAction event .. It uses separate controllers from what I can see.

class AdminController extends LSYii_Controller

"/admin" paths are configured in routes.php as well

I feel like one piece away from putting the puzzle together.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #209641 by DenisChenu
No, in actionClass

github.com/LimeSurvey/LimeSurvey/blob/b4...nController.php#L315

www.yiiframework.com/doc/api/1.1/CUrlManager

I really think (but maybe i'm false) «routes» are only used with urlRewriting.

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209645 by jackrabbithanna
Dude I restarted my computer and the plugin started to fire the event subscriber from the custom controller. I really don't understand, but perhaps PHP needed a reboot. Strange. Sorry to waste time.
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #209657 by DenisChenu

jackrabbithanna wrote: Dude I restarted my computer and the plugin started to fire the event subscriber from the custom controller. I really don't understand, but perhaps PHP needed a reboot. Strange. Sorry to waste time.

:S :side:

Some PHP configuration need reboot, but for dev : you must really diable all cache …

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.
  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209725 by jackrabbithanna
AFAIK no caches involved.

Today I go back to this task, and the plugin event is not firing for this custom controller, yet it does for others, but I cannot think of a reason why.

I try restarting computer, no help.

I don't think it would be easy for you to diagnose from afar.
All I know is sometimes plugin event fires, sometimes not.
The topic has been locked.
  • jackrabbithanna
  • jackrabbithanna's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 3 months ago #209726 by jackrabbithanna
This ended up being because the custom controller overrides the run() method. Durp.
The following user(s) said Thank You: DenisChenu
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #209729 by DenisChenu

jackrabbithanna wrote: This ended up being because the custom controller overrides the run() method. Durp.

Then with a parent::run() it's OK ?

Clear enough :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose