Announcement

Collapse
No announcement yet.

How to use the "Programming with a Data Manager" feature of vBulletin 5?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use the "Programming with a Data Manager" feature of vBulletin 5?

    Can someone provide an example that actually works and can be tested for clarity of how to use the Data Manager API. The examples that are in the manual are sniplets that are missing elements that will actually allow them to run without error. Is there an example of some type of simple “hello world!” type of code that can actually be tested to see how it works.

    The steps provided at https://www.vbulletin.com/docs/html/...er_programming says it’s assumed that we are within the vBulletin environment already. Does this mean that special includes are already attached to the top of the file? Or does it means that we are running the script from the route directory, the api directory, the includes directory, or the core/includes directory.

    I have tried to run the script from all the above directories and get the following error:

    PHP Code:
    PHP Fatal error:  Uncaught ErrorCall to undefined function datamanager_init() in /home/web/forum3/www/myinsertuser.php:6
    Stack trace
    :
    #0 {main}
      
    thrown in /home/web/forum3/www/myinsertuser.php on line 6 
    I have also tried a number of the snippets that are included in the manual.

    This is a particular code that I have tried to get to run (insert a user):
    (An example from: https://www.vbulletin.com/docs/html/...er_programming)


    PHP Code:
    // init user datamanager class
    $userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);

    // check for matching email addresses
    if ($vbulletin->GPC['email'] != $vbulletin->GPC['emailconfirm'])
    {
        
    $userdata->error('emailmismatch');
    }
    // set email
    $userdata->set('email'$vbulletin->GPC['email']);

    $userdata->set('username'$vbulletin->GPC['username']);

    // check referrer
    if ($vbulletin->GPC['referrername'] AND !$vbulletin->userinfo['userid'])
    {
        
    $userdata->set('referrerid'$vbulletin->GPC['referrername']);
    }

    // Set specified options
    if (!empty($vbulletin->GPC['options']))
    {
        foreach (
    $vbulletin->GPC['options'] AS $optionname => $onoff)
        {
            
    $userdata->set_bitfield('options'$optionname$onoff);
        }
    }

    // ... additional data setting ...

    $userdata->pre_save();

    // check for errors
    if (!empty($userdata->errors))
    {
        
    $errorlist '';
        foreach (
    $userdata->errors AS $index => $error)
        {
            
    $errorlist .= "<li>$error</li>";
        }
        
        
    // ... additional code; $errorlist is outputted to the user
    }
    else
    {
        
    // save the data
        
    $vbulletin->userinfo['userid']
            = 
    $userid
            
    $userdata->save();
            
        
    // ... additional processing code

    -- L. James

    --
    L. D. James
    ljames@apollo3.com
    www.apollo3.com/~ljames
    Last edited by apollothethird; Tue 16th Aug '16, 3:29pm.

  • #2
    That is a vBulletin 4 documentation page. Where did you see this linked as from vBulletin 5?
    Translations provided by Google.

    Wayne Luke
    The Rabid Badger - a vBulletin Cloud customization and demonstration site.
    vBulletin 5 Documentation - Updated every Friday. Report issues here.
    vBulletin 5 API - Full / Mobile
    I am not currently available for vB Messenger Chats.

    Comment


    • #3
      https://www.vbulletin.com/docs/html/...er_programming

      I've been working with the information on this page for many hours. If I could get an example that actually works, I'll be have an understanding of how it works.

      The top left corner of the page I linked says "5.2.3".

      There's lots of confusion as to where to the code that is in the examples of the linked page (https://www.vbulletin.com/docs/html/...er_programming). Since all the example are just a few lines from code that might work, when get errors I don't know if the errors are there the script is in the wrong directory, or the script has class files that should be called.

      Thanks in advance if you could either post something that actually works and can be tested, or if you can point me to a link where there is a working example.

      Thanks also, for responding to my post as well as any suggestions you can provide.

      -- L. James

      --
      L. D. James
      ljames@apollo3.com
      www.apollo3.com/~ljmaes

      Comment


      • #4
        By the way, what I'm trying to do is manually insert a user into my forum via a script.

        This is an example of what I had working on my site for the past decade:

        PHP Code:
        <?php

        require_once('./global.php');

        $newuser =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
        $newuser->set('username''phpNukeUser');
        $newuser->set('email''foo@bar.com');
        $newuser->set('password''verysecret');
        $newuser->set('usergroupid'2);

        #If there are errors (eMail not set, eMail banned, Username taken, etc.) you can check for errors using
        if (count($newuser->errors))
        {
           for(
        $i=0$i<count($newuser->errors); $i++)
           {
                print 
        "ERROR{$i}:{$newuser->errors[$i]}\n";
           }
        }
        else
        {
                
        $newuser->save();
        }

        print 
        "Finished\n";

        ?>
        I was running VB3.8 up until a couple of weeks ago. Now I'm trying to add this functionality to my current installation of VB5.

        I see lots of questions on this matter over the internet. But so far I can't find a something that works.

        -- L. James

        --
        L. D. James
        ljames@apollo3.com
        www.apollo3.com/~ljames
        Last edited by apollothethird; Tue 16th Aug '16, 3:30pm.

        Comment


        • #5
          What you are trying to do does not work in vBulletin 5. You would need to use the API and I don't have public documentation for that at this time.
          Translations provided by Google.

          Wayne Luke
          The Rabid Badger - a vBulletin Cloud customization and demonstration site.
          vBulletin 5 Documentation - Updated every Friday. Report issues here.
          vBulletin 5 API - Full / Mobile
          I am not currently available for vB Messenger Chats.

          Comment


          • #6
            Are you saying the use of the API to achieve this is classified?

            By the way, I realize it will be some type of api involved. I'm just trying to figure out how to get access to it.

            Thanks again for the input as well as any help.

            -- L. James

            --
            L. D. James
            ljaems@apollo3.com
            www.apollo3.com/~ljames

            Comment


            • #7
              It isn't classified. I don't have access to the documentation at the moment because of a software issue unrelated to vBulletin.
              Translations provided by Google.

              Wayne Luke
              The Rabid Badger - a vBulletin Cloud customization and demonstration site.
              vBulletin 5 Documentation - Updated every Friday. Report issues here.
              vBulletin 5 API - Full / Mobile
              I am not currently available for vB Messenger Chats.

              Comment


              • #8
                The Data Manager works in vB5, at least in the older 5.x versions I tried before. Haven't tried it again in newer versions but I supposed that should still work.

                What you should do is include /core/global.php, initialize data manager then set the user properties as you are doing right now. But after calling save(), you have to set the user password using the login library.

                PHP Code:
                ...
                $newuserid $newuser->save();

                //set password
                $loginlib vB_Library::instance('login');
                $loginlib->setPassword($newuserid$password,
                    array(
                'passwordhistorylength' => 0),
                    array(
                'passwordhistory' => true)
                ); 

                GIPHY for vB5 AutoLinker Auto-Create Flag Report Topic Social Icons in Postbit Clear Cache Cron DragDrop Upload Topic AJAX AutoUpdate Custom Avatars Selector Stop Links in Posts...and more!

                Comment


                • #9
                  Originally posted by Wayne Luke View Post
                  It isn't classified. I don't have access to the documentation at the moment because of a software issue unrelated to vBulletin.
                  Thanks!

                  -- L. James

                  --
                  L. D. James
                  ljames@apollo3.com
                  www.apollo3.com/~ljames

                  Comment


                  • #10
                    Originally posted by Glenn Vergara View Post
                    The Data Manager works in vB5, at least in the older 5.x versions I tried before. Haven't tried it again in newer versions but I supposed that should still work.

                    What you should do is include /core/global.php, initialize data manager then set the user properties as you are doing right now. But after calling save(), you have to set the user password using the login library.

                    PHP Code:
                    ...
                    $newuserid $newuser->save();

                    //set password
                    $loginlib vB_Library::instance('login');
                    $loginlib->setPassword($newuserid$password,
                    array(
                    'passwordhistorylength' => 0),
                    array(
                    'passwordhistory' => true)
                    ); 
                    Thanks! This is great. I'll try to put it all together and let you know how I make out.

                    -- L. James

                    --
                    L .D. James
                    ljames@apollo3.com
                    www.apollo3.com/~ljames

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X