We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32347
    • 143 Posts
    Hello,

    I need some help to get started with moving a non Modx PHP website to Modx Revolution. website: http://www.leelogic.com/

    There are 1030 users. The site is a directory for professional organizers. I just do not know where to start, I am not as skilled with modx when it comes to working xpdo and the snippet, so I thought this would be a good place to learn, but I am not sure how to get started.

    Thanks for any help
      • 3749
      • 24,544 Posts
      This may help: https://bobsguides.com/porting-your-site-to-modx.html.

      It doesn't address users. One way to do users is to export them to a CSV file (or JSON), then write a custom snippet to read that file and import them into MODX.

      User passwords are a problem, though, unless their passwords are in plain text in the old database, which is seldom the case. Without that, the only way to handle them is to migrate the password hashes as is, and write a plugin that uses the login code from the old site, bypasses the MODX login to log the users in, then creates a regular MODX password for them based on the password they entered in the form.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 32347
        • 143 Posts
        Quote from: BobRay at May 06, 2017, 10:22 PM
        This may help: https://bobsguides.com/porting-your-site-to-modx.html.

        It doesn't address users. One way to do users is to export them to a CSV file (or JSON), then write a custom snippet to read that file and import them into MODX.

        User passwords are a problem, though, unless their passwords are in plain text in the old database, which is seldom the case. Without that, the only way to handle them is to migrate the password hashes as is, and write a plugin that uses the login code from the old site, bypasses the MODX login to log the users in, then creates a regular MODX password for them based on the password they entered in the form.

        Thanks Bob. The issue that I face is almost every page had PHP code that access a Database to pull data on about the users.

          • 3749
          • 24,544 Posts
          As you probably know, all that code needs to be converted to snippets since MODX doesn't allow PHP code in resources. Converting them all can be time-consuming, but it does improve the security of the site and makes it easier to maintain over time since the business logic is completely separated from the presentation code.

          Sometimes, it's possible to handle many of those requests with a well-designed snippet that grabs a TPL chunk with placeholders for the user data and uses $user->toArray() to fill in the values. Here's an example:

          // $c = some user selection criteria here;
          $users = $modx->getCollection('modUser', $c);
          foreach($users and $user) {
             $fields = $user->toArray();
             $output .= $modx->getChunk('userTpl', $fields).
          }
          
          return $output;
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 32347
            • 143 Posts
            Quote from: BobRay at May 07, 2017, 09:40 PM
            As you probably know, all that code needs to be converted to snippets since MODX doesn't allow PHP code in resources. Converting them all can be time-consuming, but it does improve the security of the site and makes it easier to maintain over time since the business logic is completely separated from the presentation code.

            Sometimes, it's possible to handle many of those requests with a well-designed snippet that grabs a TPL chunk with placeholders for the user data and uses $user->toArray() to fill in the values. Here's an example:

            // $c = some user selection criteria here;
            $users = $modx->getCollection('modUser', $c);
            foreach($users and $user) {
               $fields = $user->toArray();
               $output .= $modx->getChunk('userTpl', $fields).
            }
            
            return $output;

            How do I get modx to allow to query a outside DB. I know I can create a Plugin for the user login and write it to the modx to convert all users to modx. Also, do I need ot use a Modx plug in to make front end users or can I use your tutorial on user access?
              • 3749
              • 24,544 Posts
              I'm not sure I understand your questions. Normally, you would export the users from the old DB to a CSV file and import them from there into the MODX database (to the modx_users and modx_user_attributes tables) using a custom snippet rather than having MODX itself query an outside DB.

              If you need to query an outside DB that you can't import into the MODX DB for some reason (like its data is constantly changed from somewhere else), you can just create a PDO instance in a snippet and use that to read the data, ignoring MODX completely.

              In MODX Revolution, there is no distinction between front-end and back-end users as far as the DB is concerned. They're just users. You can control what they can do and see with the Revolution permission system.

                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
                • 32347
                • 143 Posts
                Quote from: BobRay at May 09, 2017, 03:19 AM
                I'm not sure I understand your questions. Normally, you would export the users from the old DB to a CSV file and import them from there into the MODX database (to the modx_users and modx_user_attributes tables) using a custom snippet rather than having MODX itself query an outside DB.

                If you need to query an outside DB that you can't import into the MODX DB for some reason (like its data is constantly changed from somewhere else), you can just create a PDO instance in a snippet and use that to read the data, ignoring MODX completely.

                In MODX Revolution, there is no distinction between front-end and back-end users as far as the DB is concerned. They're just users. You can control what they can do and see with the Revolution permission system.


                Bob, thanks for your time and help. I am more of a front web developer and have been using MOdx for years, but I have never dove into Modx this deep. Most of my clients are just brochure type websites. This site is a client that I want to really help and its forcing me to dig deeper. So I apologize if I don't know all the correct verbiage.

                I understand and work some with Databases, enough to know that I can map data from one database to another write a query to import the data into the correct fields. So.....

                Can I write a query and map the fields for the users and import the data to the modx_users and Modx User attributes? Or would it be better for me to use the custom snippet?

                To query an outside DB.... Can I import what data/tables I want to keep from the old database into the modx database? I may be asking a stupid question, but when you do that do you have to add the data fields to xPDO? I am new to this so trying to understand.

                I have your book, if you need to reference something.
                  • 3749
                  • 24,544 Posts
                  Thanks for buying my book, but what you're trying to do is somewhat beyond it. wink

                  Personally, I would not try to write a query to handle this. I'd do a custom snippet.

                  Basically, you read each users data from the CSV file, then create two arrays -- one for the modUser object, and one for the modUserProfile object. Let's call them $userArray and $profileArray.

                  The fields for each one are here: https://bobsguides.com/modx-object-quick-reference.html#modUser and here: https://bobsguides.com/modx-object-quick-reference.html#modUserProfile. Not all fields are required -- (Important: don't fill in the id for either one, and don't fill in the 'internalKey' for the profile).

                  Then, you do something like this:

                  $user = $modx->newObject('modUser');
                  $user->fromArray($userArray);
                  
                  $profile = $modx->newObject('modUserProfile');
                  $profile->fromArray($profileArray);
                  $user->addOne($profile);
                  
                  $user->save();


                  You can definitely import other tables into the MODX DB (I would). It's recommended that you use a different prefix for them (e.g., NOT modx_).

                  You can definitely make them xPDO-friendly. It's not necessary (you can access them with PDO), but it makes your life much easier if you're familiar with xPDO. There's some info on it, and a script to make them xPDO-friendly, here: https://bobsguides.com/custom-db-tables.html.

                  One option, depending on how secure your site needs to be, is to set each user's password to their username, then encourage them to change their passwords.

                  Do this just before the $user->save() line:

                  $user->set('password', $username);


                  Don't set any of the other password fields (hash_class, salt, cachepwd).
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting