Logic Hook on the Users Module not working

Hi

I want to execute a query in after before logic hook like $result=$db->query("UPDATE users SET description='test' WHERE id='27283e5a-8f34-b846-367a-561fbbb4cb54'");

There was no Users module in the custom folder so I have create a 'Users' folder at the path

<base-path>/custom/modules/ and create a logic hook  using the files

AT <base-path>/custom/modules/Users/logic_hooks.php

$hook_array['before_save'][] = Array(

        //Processing index. For sorting the array.

        1,

        'before_save example',

        'custom/modules/Users/logic_hooks_class.php',

        'logic_hooks_class',

        'before_save_method'

    );

At <base-path>/custom/modules/Users/logic_hooks_class.php

function before_save_method($bean, $event, $arguments)

        {

         $db         = DBManagerFactory::getInstance();       

  $result     = $db->query("UPDATE users SET description='test' WHERE id='27283e5a-8f34-b846-367a-561fbbb4cb54'");

        }

Shijin Krishna

I have saved a user in the Users module but the description field is not getting updated.

  • Hi Anand,

    Did you run Quick Repair and Rebuild after adding these files? Navigate to

    Admin > Repair > Quick Repair and Rebuild

    Now try creating a new user or editing any existing one.

  • Hi Shijin Krishna

        Thank You for your reply.I have done a quick repair and rebuild.But the description field was not updating.

  • Hi,

    try to use after_save

  • Modify AT <base-path>/custom/modules/Users/logic_hooks.php as below.

    $hook_version = 1;

    $hook_array = array();

    $hook_array['before_save'] = array();

    $hook_array['before_save'][] = Array(

            //Processing index. For sorting the array.

            1,

            'before_save example',

            'custom/modules/Users/logic_hooks_class.php',

            'logic_hooks_class',

            'before_save_method'

        );

    and At <base-path>/custom/modules/Users/logic_hooks_class.php as below

    class logic_hooks_class{

         function before_save_method($bean, $event, $arguments){

              $bean->description = 'Test'; //this will update the user which u have created currently.

          }

    }