We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 25551 ☆ A M B ☆
    • 1,231 Posts
    Hello,

    I'm trying to tie my forum in to the IDs of modx but using the modUser object doesn't seem to want to change the ID or internalKey.

    I'm using several systems and databases and all need to relate up to the same ID throughout. One system is SMF, I want to match up the users from SMF to MODx and an online voice communication service. I need this stop gap till Discuss comes out then my life will be easier from there.

    I've tried the following and it doesn't allow you to change IDs.

    $first_name = 'test';
    $userID = 22;
    $user = $modx->newObject('modUser', array ('username'=>$first_name, 'id'=>$userID));
    $userProfile = $modx->newObject('modUserProfile');
    $userProfile->set('fullname',$first_name);
    $userProfile->set('email',$email);
    $userProfile->set('id',$userID);
    $userProfile->set('internalKey',$userID);


    Any advice would be great.
      Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
      AugmentBLU - MODX Partner

      BLUcart - MODX Revolution E-Commerce & Shopping Cart
      • 22303 MODX Staff
      • 10,725 Posts
      I recommend using the external_key field to relate the MODX user to an external user object id. The MODX database object IDs are controlled by the database, which automatically assigns each record a new id. Though you can work around this by using fromArray()'s setPrimaryKeys parameter, this is not recommended.
        • 25551 ☆ A M B ☆
        • 1,231 Posts
        Thanks for your reply.

        The issue is I am building a ton of CMPs and user areas based on the MODx permissions. It's in preparation for Discuss coming out. I want to match the IDs from SMF to MODx so when Discuss does arrive then I don't need to change too much.

        Do you have an example of how to force the ID/internalKey?

        Thanks
          Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
          AugmentBLU - MODX Partner

          BLUcart - MODX Revolution E-Commerce & Shopping Cart
          • 25551 ☆ A M B ☆
          • 1,231 Posts
          I'm getting error trying to do this.

          $test = $modx->newObject('modUser'); 
          $test->fromArray('id' => 22);
          $test = $modx->newObject('modUser')->fromArray();
          $test->save();


          Call to a member function save() on a non-object

          Any ideas?

          Thanks
            Ross Sivills - MD AugmentBLU Edinburgh, Scotland UK
            AugmentBLU - MODX Partner

            BLUcart - MODX Revolution E-Commerce & Shopping Cart
            • 28215
            • 4,149 Posts
            splittingred Reply #5, 15 years ago
            Your code should be:
            $test = $modx->newObject('modUser'); 
            $test->set('id',22);
            $test->save();
            
              shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com