Results 1 to 7 of 7

Thread: set user default role fail

  1. #1
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default set user default role fail

    Hi

    http://www.sugarcrm.com/forums/showthread.php?t=38806

    I did the above changes but I got following error in php error log:

    Call to a member function add() on a non-object in

    and on suger Log I got folowing error-

    Error fetching relationship from cache acl_roles_users

    I did all repair options

    I am using 5.2o version.

    also the user list sub panel not pop up in Role module!!!

    Please help me.

    Regards,
    Pravin

  2. #2
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: set user default role fail

    As the solution of andopes works fine, I suppose there is a little typo error in your code.
    Just post the code of your solution here and perhaps we can find the problem together.
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  3. #3
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: set user default role fail

    Here is my code- Same as the andopes gives.

    logic hook-
    PHP Code:
    <?php
    // Do not store anything in this file that is not part of the array or the hook version.  This file will    
    // be automatically rebuilt in the future. 
    $hook_version 1
    $hook_array = Array(); 
    // position, file, function 
    $hook_array['before_save'] = Array(); 
    $hook_array['before_save'][] = Array(2'addInProfile''custom/modules/Users/UserLogicHook.php','UserLogicHook''addInProfile'); 
    ?>
    UserLogicHook.php
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    UserLogicHook {
        function 
    addInProfile(&$focus$event$arguments) {
            
    $role_name "test100";

            
    $query "SELECT id FROM users WHERE id = '{$focus->id}'";
            
    $result $focus->db->query($querytrue);

            if(
    $focus->db->getRowCount($result) == 0) {
                
    $query "SELECT id FROM acl_roles WHERE name = '$role_name'";
                
    $result $focus->db->query($querytrue);

                if(
    $focus->db->getRowCount($result) == 1) {
                    
    $row $focus->db->fetchByAssoc($result);
                    
    $focus->load_relationship('aclroles');
                    
    $focus->aclroles->add($row['id']); //this line gives error
            
    $bean->new_with_id=true;
            
                    require_once(
    'modules/ACL/install_actions.php');
                } else {
                    
    sugar_die("Role test100 does not exist! Contact the system administrator");
                }
            }
        }
    }
    ?>


    This solution works fine on other version. I tries it on sugar 6. I think I am having problem In my code or some relation ship issue because in role management the users list is not displayed.it may have some relationship issue!!
    Reply soon please

    Regards,
    Pravin

  4. #4
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: set user default role fail

    I copied your code to my custom/modules/Users directory and it works fine

    I tested it in 6.0.0 and in 6.1.0, both version work.

    Are alle filenames and directorynames with correct upper and lower cases?
    custom/modules/Users/logic_hooks.php
    custom/modules/Users/UserLogicHook.php

    Did you try to set the log level to debug and did you look to the sugarcrm.log file to check it for any errors?
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  5. #5
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: set user default role fail

    yes. I also tested in all versions and going well. I am using 5.2o version.

    And I also checked the php error logs and got following error.
    Call to a member function add() on a non-object in ........{sugarpath}

    and in suger Log I got following log-

    Error fetching relationship from cache acl_roles_users


    I guess it an problem of relationship..


    Thanks
    PRavin

  6. #6
    kuske's Avatar
    kuske is offline Sugar Community Member
    Join Date
    Oct 2007
    Location
    Germany
    Posts
    2,597

    Default Re: set user default role fail

    It seems that your installation is defective.
    This method add must exist even in 5.2.0

    But you can solve your problem if you create the ACL record by yourself.
    Just use the following hook code:

    PHP Code:
    <?php 
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); 
    class 
    UserLogicHook 
        function 
    addInProfile(&$focus$event$arguments) { 
            
    $role_name "test100"
            
    $query "SELECT id FROM users WHERE id = '{$focus->id}'"
            
    $result $focus->db->query($querytrue); 
            if(
    $focus->db->getRowCount($result) == 0) { 
               
                
    $query "INSERT INTO acl_roles_users ".
                         
    "(id,role_id,user_id,date_modified,deleted) ".
                         
    "VALUES ".
                         
    "( uuid(),".
                         
    "  (SELECT id FROM acl_roles WHERE name = '".$role_name."'),".
                         
    "  '".$focus->id."',".
                         
    "  now(),".
                         
    "  0 ".
                         
    ")";
                
    $focus->db->query($querytrue); 
            } 
        } 

    ?>
    Harald Kuske
    Pre-Sales Engineer Central Europe

    SUGARCRM Deutschland GmbH
    Erika-Mann-Str. 53, 80636 Munich, Germany
    Email: hkuske@sugarcrm.com
    Home: http://www.sugarcrm.com


  7. #7
    pravin.agham is offline Senior Member
    Join Date
    Sep 2010
    Posts
    64

    Default Re: set user default role fail

    Thanks!! It works.

    and yes I guess my installation having problem.But how could I overcome my problem.Its already been lots of development did insight.

    Why I not able to seen the User list under role management.(Role detail view).

    I got relationship error log in sugarcrm

    "Mon Dec 6 17:52:18 2010 [3343][1][FATAL] Missing relationship definition acl_roles_users. skipping users subpanel "


    Can you guess??

    Thanks for the solution!!

    Regards,
    Pravin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 2010-11-24, 10:54 AM
  2. User/role default home
    By YohN in forum Developer Help
    Replies: 4
    Last Post: 2010-01-06, 11:41 AM
  3. Replies: 7
    Last Post: 2009-12-09, 09:16 AM
  4. Replies: 5
    Last Post: 2008-09-22, 12:11 PM
  5. When setting up new user, assign a default role.
    By rickcrites2 in forum Feature Requests
    Replies: 2
    Last Post: 2006-09-04, 03:55 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •