We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40641 ☆ A M B ☆
    • 56 Posts
    Hi.

    I'm trying to create a starter-pack, to install with each clean MODX installation, for my own use. I know there are ones already out there, but I need my own for my own purposes.

    Is it possible to configure a package to create users, set user/group permissions etc on install?

    Additionally, is it also possible to have the installation of that package default the manager to a new theme (included in that package).

    What limitations are there with packages and automating this kind of requirement?

    Many thanks for your help.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      It's all in the database. Study the database tables for user management, and then just enter what you need into the appropriate tables.

      http://rtfm.modx.com/display/revolution20/Users
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        Erm . . . This is the MODX Evolution forum and Evolution doesn't have a Package Manager. We can give you a more specific answer once we know if you're using Evolution or Revolution.


        ------------------------------------------------------------------------------------------
        PLEASE, PLEASE specify the version of MODX you are using.
        MODX info for everyone: http://bobsguides.com/modx.html
          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
          • 40641 ☆ A M B ☆
          • 56 Posts
          RobRay - Sorry, I had intended to use the Revolution forum - my mistake. Can the post be moved?

          Scotwell - Ok, so essentially are you saying that as long as it's controlled in the database (which I appreciate it is) I can create a procedure as part of my setup to create my users and/or permissions?

          Can you give me some pointers to how I might do that (I don't mean the actual code, I can do that, but how to make it part of the setup process). Sorry I am very new to MODX, but encouraged by what's possible.

          Additionally, I assume this can all be done via the API (I wouldn't want to write inline SQL as that's bound to cause issues in the future) so can you show me some documentation for creating users via the API?

          Again, sorry for the newbie questions, I just want to get it right from the start smiley
            • 3749
            • 24,544 Posts
            There are at least two ways to go. One is to create a MODX Transport Package: http://rtfm.modx.com/display/revolution20/Transport+Packages.

            The other would be to write a custom snippet that "exports" everything you want to a file, then another custom snippet to run on the target site that "imports" that file.


            Neither approach would be simple.

            The Provisioner package would make it relatively simple, but I don't think it works in the current version of Revolution. You could install older versions of Revolution at each site, use Provisioner, then upgrade.



            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html
              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
              • 40641 ☆ A M B ☆
              • 56 Posts
              Thank you for your reply again, however, I think you've misunderstood my problem.

              I have created a transport package - that's all well and good smiley

              However, I do not need to import users from another site. I'm attempting to create a 'standard' set of users (beyond the current one admin on install) with 'Editors', 'User Manager', 'Sales Staff' etc, with different groups/permissions.

              I see I can create users via the API now, that's super. However, at what stage would I 'run' such a script. It is possible to inlclude this login somewhere within build.transport.php? Or do I have to create it as a snippit (I hadn't thought of this until you said it) and then have that snippit run when the package is installed.

              I've seen plenty of packages which 'do stuff to my database' when they install, so I wanted to know how to do that myself.

              Many thanks
                • 40641 ☆ A M B ☆
                • 56 Posts
                When I say 'do stuff to my database' I mean add data/change values in it, not just create tables with xPDO
                  • 3749
                  • 24,544 Posts
                  You could do it with a script resolver, which is essentially a snippet that runs during the install.

                  In theory, you could create the users and user groups in the same way you create elements and resources and add everything in build.transport.php, but TBH, unless you have a whole lot of users, I think it would easier to just do it all in a resolver.

                  There's an example of a Resolver in the MyComponent/getMyComponent package, but I wouldn't recommend using that package at this point, because I'm currently refactoring it from the ground up.

                  A script resolver looks like this (it could go in a file: _build/resolvers/install.script.php):

                  <?php
                  
                  if ($object->xpdo) {
                      $modx =& $object->xpdo;
                  
                      switch ($options[xPDOTransport::PACKAGE_ACTION]) {
                          case xPDOTransport::ACTION_INSTALL:
                          case xPDOTransport::ACTION_UPGRADE:
                                 /* your code here */
                              break;
                          case xPDOTransport::ACTION_UNINSTALL
                              /* Your code here */
                              break;:
                      }
                  }
                  
                  return true;



                  In build.transport.php, you need this code to add the resolver (at some point where $vehicle exists):

                  $modx->log(modX::LOG_LEVEL_INFO,'Adding in Script Resolver.');
                      $vehicle->resolve('php',array(
                          'source' => $sources['resolvers'] . 'install.script.php',
                      ));



                  BTW, this is a great place to see how to do stuff in a Transport Package: https://github.com/splittingred


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  MODX info for everyone: http://bobsguides.com/modx.html
                    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
                    • 40641 ☆ A M B ☆
                    • 56 Posts
                    Thank you, that's great. I've got users being created during install now, which is just what I was looking for.
                      • 3749
                      • 24,544 Posts
                      I'm glad you got it sorted. Thanks for reporting back. smiley


                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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