Jump to content

Edit History

Bruno G

Bruno G


added --no-debug option

I call some methods of my modules from cron with the implementation of Symfony Commands.

It works perfectly, but sometimes, when I create a user for instance, and a module like PSrecaptcha has a hook with this kind of context call, it triggers a notice which stops the execution of my script.

/**
     * HookActionObjectCustomerAddBefore
     * Magic Hook
     */
    public function hookActionObjectCustomerAddBefore()
    {
        if (!$this->isModuleActive() || Configuration::get('RECAPTCHA_REGISTRATIONFORM') == '0') {
            return;
        }

        if ($this->context->controller->controller_type == 'front') {
            if (!$this->verifyRecaptcha()) {
                $params['create_account'] = 1;
                $params['captchaErrorMsg'] = $this->l('Invalid captcha challenge, please retry.');
                Tools::redirect($this->context->link->getPageLink(
                    'authentication',
                    true,
                    null,
                    $params,
                    true
                ));
            }
        }
    }

The following notice is triggered obviously... :

 Notice: Trying to get property 'controller_type' of non-object

Of course, since this is called in command line there is no context.

Do you have an elegant way to solve this, for example :

  • Modifying the Psrecaptcha code and checks if context exists before the call to the context (is it safe anymore ?). The problem with this solution is that I'm not responsible of the code of every module that hooks themselves everywhere and call Context : I can't modify them all.
  • Find a way to continue the execution of the command even if it triggers a notice like with " --no-debug" option, but will it hide all errors ?
  • Find a way to bypass all context calling or bypass all hooks when the script is launched from command line.

I work with PS 1.7.6.3

Thank you

Bruno G

Bruno G

I call some methods of my modules from cron with the implementation of Symfony Commands.

It works perfectly, but sometimes, when I create a user for instance, and a module like PSrecaptcha has a hook with this kind of context call, it triggers a notice which stops the execution of my script.

/**
     * HookActionObjectCustomerAddBefore
     * Magic Hook
     */
    public function hookActionObjectCustomerAddBefore()
    {
        if (!$this->isModuleActive() || Configuration::get('RECAPTCHA_REGISTRATIONFORM') == '0') {
            return;
        }

        if ($this->context->controller->controller_type == 'front') {
            if (!$this->verifyRecaptcha()) {
                $params['create_account'] = 1;
                $params['captchaErrorMsg'] = $this->l('Invalid captcha challenge, please retry.');
                Tools::redirect($this->context->link->getPageLink(
                    'authentication',
                    true,
                    null,
                    $params,
                    true
                ));
            }
        }
    }

The following notice is triggered obviously... :

 Notice: Trying to get property 'controller_type' of non-object

Of course, since this is called in command line there is no context.

Do you have an elegant way to solve this, for example :

  • Modifying the Psrecaptcha code and checks if context exists before the call to the context (is it safe anymore ?). The problem with this solution is that I'm not responsible of the code of every module that hooks themselves everywhere and call Context : I can't modify them all.
  • Find a way to continue the execution of the command even if it triggers a notice.
  • Find a way to bypass all context calling or bypass all hooks when the script is launched from command line.

I work with PS 1.7.6.3

Thank you

×
×
  • Create New...