We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24935
    • 160 Posts
    I wanted to find out interest and get some feedback on an idea for a subversion plugin. I know many people would like to have certain elements (like snippets, templates, chunks...) under version control. Keeping a dump of the DB under version control just isn’t a good solution.

    My idea is to create a plugin that automatically creates a file with the contents of an element when the element is saved. These files would be kept in a directory protected by an .htaccess file. When you open an element for editing, the plugin would update (and save) the content of the element from the file first. The plugin would also check all the files in the elements directory when logging in (maybe also logging out) of the manager, and update any elements from the files. This would make it easy to track changes with svn and collaborate. After an SVN update, just log out and log in, and all of the elements would be synced with the repository!

    The proposed structure would be:
    assets
      elements
        chunks
          chunkname.htm
          anotherchunk.htm
        snippets
          snippetname.php
        templates
          1.htm
          2.htm
        .htaccess
    

    (templates saved by id, since that is how they are linked to documents)

    I’d like to hear what others think and see how much interest there is in collaborating on this.

    Some past discussions on this topic:
    http://modxcms.com/forums/index.php/topic,7712.0.html
    http://modxcms.com/forums/index.php/topic,22104.0.html
      • 5689
      • 289 Posts
      rfoster, this is a really excellent idea! I would definitely use it. I can’t say I’m experienced enough with MODx yet to be able to collaborate, but I think it would definitely be worth the time to make.

      I’m getting started using the Netbeans IDE for PHP along with Subversion, and it’d be really cool to be able to edit elements right in my IDE, and still have use of the Subversion capabilities. I’m thinking that if the plugin is going to keep copies of the elements from the database as files, it might be possible to figure out a way to make it practical to use an IDE to edit the files. Perhaps this should be a different plugin, and I remember hearing somebody talk about doing it, but I don’t know. It’s just a thought.
        I'm learning more about MODx all the time and loving it.
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        All of the elements can be included from a file using a single snippet to include the file as the content of the element.
          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
          • 22303 MODX Staff
          • 10,725 Posts
          The key here would be the format for storing the content. Without the metadata associated with the content, you are not really versioning the entire data set, just the content, and this is not much more useful than including the content from a file. There would have to be a serialized format that contained all of the metadata for this to truly be effective, which would make the IDE usage less than optimal. Using an existing or custom protocol like WebDAV might be possible where the metadata becomes properties of the SVN content, but the effort to develop this would not be insignificant.
            • 24935
            • 160 Posts
            Quote from: sottwell at Aug 06, 2009, 11:57 AM

            All of the elements can be included from a file using a single snippet to include the file as the content of the element.
            Susan, could you share the snippet you use (if you have one?). I think that is the simplest approach to the problem. However, a synchronizing plug in would have a few additional advantages--

            • You could edit resources in the manager or edit the files
            • Creating a file would actually create the corresponding element--so if you are working collaboratively, you don’t have to manually create those resources.

            Jason--good point. What about two files for each element--one with the raw content, and one with the metadata in JSON or XML format? If the metadata was missing, default values would be assumed. That way it would be easy to edit the content in an IDE and also easy to update the metadata with an editor.
              • 24935
              • 160 Posts
              One concern I would have is that it might be possible on some less than ideal shared servers, for another user on the server to actually write code into your writeable directory. However, this would probably be used mostly by people who have their own VPS or server.
                • 25663 MODX Staff
                • 12,272 Posts
                Hey Ryan, interesting idea. Here’s a link to a thread on the include snippet/template idea: http://modxcms.com/forums/index.php/topic,30755.msg186652.html#msg186652
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Just curious, if you edited the files, how would the database, and thus the manager interface, know about the changes, or lock manager users from editing it until it did? One has to be the master, no?
                    • 24935
                    • 160 Posts
                    When you open an element in the manager, it would load any changes made to the content or metadata file. That would prevent any conflicts as long as someone doesn’t edit the file and edit the element in the manager at the same time (in which case the last one to hit save wins).

                    I think this would be used by people working on a local copy on their own workstation, so there shouldn’t be any problems if people follow a logical sequence of steps: edit files, sync, test, svn update and commit, sync again if any changes came from the update...