Results 1 to 9 of 9

Thread: Bulk Set Initial Pref's

  1. #1
    cpscdave is offline Sugar Community Member
    Join Date
    Jun 2007
    Posts
    36

    Default Bulk Set Initial Pref's

    Hi,
    I'd like to Bulk load some user preferences, and I know I can do it with User::setPreference

    However how do I figure out what the name/val should be. I've been able to make the change and see the fields changing in the DB but of course everything is obsificated. I suppose I could just copy the DB row to other users but thats not all that elegant.

    Any insight into how to figure this out would be great.

    Specifically I need to set

    Pipeline Dashlet -> Show specific stages
    Oppertunity Dashlet -> Show Client File Name

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Bulk Set Initial Pref's

    Hey cpscdave,

    How about just doing a log dump inside of setPreferences and saving preferences for a User to see what goes through?

    function setPreference($name, $value, $nosession = 0, $category = 'global', $user = null) {
    $GLOBALS['log']->fatal("user id: $user->id category: $category name: $name value: $value ");

  3. #3
    cpscdave is offline Sugar Community Member
    Join Date
    Jun 2007
    Posts
    36

    Default Re: Bulk Set Initial Pref's

    this gets filed under "DOH! Why didnt I think of that"

    Thanks again egg! This will get me the info I need to do what I need!

  4. #4
    cpscdave is offline Sugar Community Member
    Join Date
    Jun 2007
    Posts
    36

    Default Re: Bulk Set Initial Pref's

    Hmmm cant seem to get this to work.

    I outputed all the jazz and got the values of

    dashlets, array, 0,, home

    so I outputed the array to a file and wrote this

    PHP Code:
    <?php

    require_once('modules/Users/User.php');
    global 
    $db;

    $results $db->query("SELECT id FROM users WHERE deleted = 0 and last_name = 'Robertson'");


    while(
    $row $db->fetchByAssoc($results))
     {
       
    $focus = new User();
       
    $focus->retrieve($row['id']);
       
    $dashletVal getDashletVal();
       
    print_r($dashletVal);
       
    $focus->setPreference('dashlets'$dashletVal,false,'home',$focus);
       
    $focus->savePreferecesToDB();
     }




    function 
    getDashletVal()
    {

      
    $file "/var/www/html/crm/initialSetting/pipeline_pref.txt";
      
    $fp fopen($file"r");
      
    $content fread($fpfilesize($file));
      
    $val unserialize($content);
      
    //  print_r($val);
      
    return $val;



    }

    ?>

    as far as I Can tell its pumping in the same items but its not updating the pregs.... grrrr

  5. #5
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Bulk Set Initial Pref's

    You can print the values of the array to the screen using print_r() or you can append it to a string using a function like the following:

    PHP Code:

    function debug_print_r($data)
    {
        
    ob_start();
        
    print_r($data);
        
    $result ob_get_contents();
        
    ob_end_clean();
        return 
    $result;

    Usage like echo "my array values are: ".debug_print_r($myarray);

  6. #6
    cpscdave is offline Sugar Community Member
    Join Date
    Jun 2007
    Posts
    36

    Default Re: Bulk Set Initial Pref's

    Yep did that, and they look correct to me.

    What I think is happening is the value array has the format of
    [SOME_ID] => array

    I'm wondering if that ID is unique somehow and thats what's preventing the update from working.

  7. #7
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Bulk Set Initial Pref's

    Oh sure, that's probably the id from the dashboards table. This may be where the preferences for items just as the Home page dashlets are kept. It for sure stores it for the Dashboard tab here. There's a column called "name" though that is set to Home in my db making me guess that it's for the Home page. Any ideas?

  8. #8
    SugarDev.net is offline Sugar Community Member
    Join Date
    Feb 2008
    Posts
    1,401

    Default Re: Bulk Set Initial Pref's

    Quote Originally Posted by eggsurplus View Post
    You can print the values of the array to the screen using print_r() or you can append it to a string using a function like the following:

    PHP Code:

    function debug_print_r($data)
    {
        
    ob_start();
        
    print_r($data);
        
    $result ob_get_contents();
        
    ob_end_clean();
        return 
    $result;

    Usage like echo "my array values are: ".debug_print_r($myarray);
    Simpler would be
    PHP Code:
    echo print_r($myarraytrue); 
    Developers go here
    Businesses go there (Dutch)

    Modules:
    SugarDev.net Developer Tools | Config | Dutch Language Pack
    "Nothing gets fixed unless there is a bug"

  9. #9
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: Bulk Set Initial Pref's

    Thanks SugarDev! Must be new in PHP 5.0?

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Mysql - MSSql
    By Proware in forum Help
    Replies: 15
    Last Post: 2009-10-05, 01:27 PM
  2. Replies: 7
    Last Post: 2009-02-03, 08:42 AM
  3. Replies: 3
    Last Post: 2007-02-28, 02:45 PM
  4. Importing Contacts: Where can I set a universal value?
    By leenwebb in forum Developer Help
    Replies: 3
    Last Post: 2007-01-19, 09:27 PM
  5. Upgrade from Open Source to Professional
    By Sohonet in forum General Discussion
    Replies: 1
    Last Post: 2006-06-12, 09:23 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
  •