Jump to content
bernhard

RockSVN brings Version Control to your Fields & Templates

Recommended Posts

I needed to create some Fields and Templates via API and it was always a pain to get the right settings (like columwith, field context settings and so on). With the brand new (and ALPHA) RockSVN Module you can create your fields via the backend and then show a diff of your changes.

Please see the comments on top of the module for todos and limitations. 

I'm not totally happy with the diff tool, so if anybody knows a better one or knows ho to change the behaviour to line-based diff (that would be better in this case i guess) feel free to comment. As @ryan is using the same diff tool in ProDrafts i guess there's not too much hope... anyway - i think the module can be a big timesaver and also help you to keep track of changes - an often requested feature and maybe also a good companion for @LostKobrakai s Migrations module! (Benjamin, jump in ;) )

The module will create some Fields, Templates and Pages for you. All properly tagged and hidden, so it should not mess up things more than needed.

Caution: Currently the module removes all those pages, templates and fields on uninstall!

Requires my new basemodule called RockTools

2016-10-25 02_13_18-Edit Page_ 0.1 change field body by admin @ 25.10.16 01_49_10 • sandbox.dev.png

2016-10-25 02_22_41-Fields • ProcessWire • sandbox.dev.png

 

RockSVN.zip

  • Like 11

Share this post


Link to post
Share on other sites

Cool!

That immediately comes to mind is some wild wishes:

  • add a generation script @LostKobrakai's Migrations and we got a nice GUI-based migrations for PW;
  • add comparison to remote installation.

Big thanks!

  • Like 5

Share this post


Link to post
Share on other sites

Thank you Bernhard for sharing it! I will take a closer look, as soon as I have some spare time.

Somewhat related is my own "pet" project that I have just published here:

My Bash script compares two databases.

9 hours ago, bernhard said:

The module will create some Fields, Templates and Pages for you. All properly tagged and hidden, so it should not mess up things more than needed.

Caution: Currently the module removes all those pages, templates and fields on uninstall!

I used the changes made by your module to demonstrate the script:

https://youtu.be/V6eF4NBNDbc 

Share this post


Link to post
Share on other sites

hi @Ivan Gretsky

thank you for your suggestions. seems we share the same wishes (as many others also do, i suppose), but such things are very tricky and i don't think one (especially i) can build a solid solution for that. you have ids and integers all around and you have to know the order of editing/removing/adding stuff. for example you cant create a template when the corresponding fields do not exist. maybe we would just need a GUI for providing the order of the changes to be applied. thinking of every change as a page the pagefield comes to my mind... there we already have such GUI.

hmm, maybe it would be possible, but not for me right now - i have loads of client work to do :rolleyes:

i'll also wait for @teppo s response. maybe he can integrate my module into his more mature ProcessChangelog module...

@szabesz

thanks for the video. as i said above i'm not really happy with the current diff tool. i found this one (https://diff2html.xyz/demo?diff=https://github.com/rtfpessoa/diff2html/pull/106) but that needs a diff string to make the output and i found no easy solution for creating this diff string on the fly. there's xdiff php extension but i don't really like the idea of relying to a php extension not installed on most of the hosting platforms (or am i wrong here?).

maybe you have some hints here?

Share this post


Link to post
Share on other sites
4 minutes ago, bernhard said:

such things are very tricky and i don't think one (especially i) can build a solid solution for that

The most tricky thing is, that the state of some fields in not even stored explicitly in one place. E.g. the fields selected for repeaters are stored in a template and the repeater -> template matching does only happen based on name. So there's no explicit connection. There are lot's of solutions of resolving state changes automatically, but first there would need to be a standardized way to capture all those changes. Considering that things might even be hookable, there currently are a lot of cases to cover.

Share this post


Link to post
Share on other sites
48 minutes ago, bernhard said:

maybe you have some hints here?

Not really, I'm afraid, but I have just found this one:

https://github.com/gorhill/PHP-FineDiff

It has an online test site:

http://www.raymondhill.net/finediff/viewdiff-ex.php

It generated this nice, one liner for a one line change, eg:

c270d30i34: "label": "Location Eng", c583

The output of the diff tool you use is "too" verbose, is it what you do not like about it? It is probably enough to see what is different, and not the complete json string.

  • Like 1

Share this post


Link to post
Share on other sites
13 minutes ago, szabesz said:

The output of the diff tool you use is "too" verbose, is it what you do not like about it? It is probably enough to see what is different, and not the complete json string.

i don't think it's too verbose as you should always be aware of the context where the change happened. maybe some collapse feature would be nice, though. but looking at the markup i have no idea how to implement that shortly.

the problem is that it sometimes creates not so good readable results. i'll paste one when i have a good example. maybe thats already fixed by using the module's initialization feature that i added later.

 

  • Like 1

Share this post


Link to post
Share on other sites
52 minutes ago, szabesz said:

But this is the one I already linked to :D

lol, really?! :D

sorry for that - i have to take a closer look anyhow. but i have to use my module first some time to see what/if there is a need...

sometimes in live you need a second look :) even on processwire i needed it - and i'm really happy i took it!

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, bernhard said:

even on processwire i needed it - and i'm really happy i took it!

The same is true in my case...

 

  • Like 1

Share this post


Link to post
Share on other sites
On 25/10/2016 at 1:06 PM, bernhard said:

i'll also wait for @teppo s response. maybe he can integrate my module into his more mature ProcessChangelog module...

Sorry for the delay -- meant to answer a while ago, but then something came up, and I forgot the whole thing. Hopefully you haven't been waiting this whole time :)

I'm going to answer your suggestion at the Changelog support thread separately, but as a quick comment to this: I think your module looks really neat, and while listing changes to fields is definitely something I might consider for Changelog, I do also feel that these modules serve a different purpose. At least that's my first impression.

When I first built the Changelog module, it was just a simple list of changes to public pages of the site. While it does display which fields were changed and now also includes system pages, I've intentionally left actual field values out of the equation. That's where VersionControl comes in: it stores field values and keeps track of changes to those. Again, the purpose is different: a relatively high-level log of changes vs. an actual versioning tool.

Tracking changes to fields might fit VersionControl better than Changelog, but I'm currently not convinced that it would really be worth it. It seems to me that while there may be some common ground, these are mostly separate features. And, to be honest, VersionControl is already doing so much behind the scenes that I'm having hard time keeping up with everything that's happening. Smaller, more targeted modules do have certain benefits :)

I'm definitely going to keep an eye out for what you do with this module, but for the time being I don't think there's much benefit in trying to combine them.

---

By the way, I've been meaning to ask you about the naming of your module: what does the SVN part actually refer to? My first guess would be Subversion (SVN), but then again, I don't see any link between Subversion and your module. Hopefully I'm not being too intrusive here, but if my guess is right, I'd suggest reconsidering the naming. While Subversion is a commonly used product, in the long run this might become a bit confusing to some users :)

  • Like 5

Share this post


Link to post
Share on other sites

Regarding the diff tool: I've also been using diff-match-patch for automatic diffs. It's a solid library and particularly useful if you prefer to generate diffs on the fly (client side). The kind of issues you mentioned above, i.e. the library comparing column names in addition to values, may be difficult to avoid with any tool that isn't "JSON-aware". This is why, for an example, in VersionControl I ended up mocking up my own diff logic for page field comparisons.

What I'm trying to say here is that simply diffing two strings may not always yield sensible results, as you have noted here too. In this case it would make more sense to iterate items one by one and generating a separate diff for each pair of old and new values.

Hopefully I'm making sense here.. and sorry if I'm mixing things up and this is what you're already doing, I didn't read your code that thoroughly :)

  • Like 1

Share this post


Link to post
Share on other sites

just wanted to let you know that i found a very nice jsdiff library today that is ideal for this usecase (line-based diff): https://github.com/kpdecker/jsdiff/

5916d0202c74a_2017-05-1311_19_03-DiffLines.thumb.png.2f64d24a3ff56332f7a948654e0bdb4b.png

i'm not sure any more if a module like this would make sense, though. i built a module that makes adding and removing fields and templates very easy:


public function ___upgrade($from, $to) {
    // define variables
    $fat = $this->wire->modules->get('FieldsAndTemplatesHelper');
    $pages = $this->wire->pages;

    // upgrade
    if($from < $to) {
        // 001
        if($from < 1 AND $to >= 1) {
            $this->message("upgrade v001");

            // create templates and fields
                $t_clients = $fat->createTemplate('clients');
                $t_client = $fat->createTemplate('client');
                $f_domain = $fat->createField('domain', 'text');
                $f_nossl = $fat->createField('nossl', 'checkbox');

            // early exit if anything went wrong
                if(!$t_clients) return;
                if(!$t_client) return;
                if(!$f_domain) return;
                if(!$f_nossl) return;

            // apply settings
                $t_clients->noParents = -1;
                $t_clients->childTemplates = [$t_client->id];
                $t_clients->childNameFormat = 'title';
                $t_clients->save();

                $t_client->noChildren = 1;
                $t_client->parentTemplates = [$t_clients->id];
                $t_client->save();

                $t_client->fieldgroup
                    ->add($f_domain)
                    ->add($f_nossl)
                    ->save();

            // create page
                $p = new Page();
                $p->template = $t_clients;
                $p->parent = 1;
                $p->addStatus(Page::statusHidden);
                $p->addStatus(Page::statusLocked);
                $p->name = $p->title = 'MyClients';
                $p->save();
        }
        
        // 002
        if($from < 2 AND $to >= 2) {
            $this->message("upgrade v002");
        }

        [...]

in many occasions it would not make much sense to have the diff-tool because you would have to change the code anyway, eg:

$t_clients->childTemplates = [$t_client->id];

and all the correct names of the options can easily be inspected via code inspector:

5916d387dea06_2017-05-1311_34_36-DeveloperTools-http___markupregions.dev_processwire_setup_template_edit_id1.thumb.png.13a60986cd1aea7999017cb1a9881126.png

so... i guess i will not take this further :) or are there other opinions?

  • Like 2

Share this post


Link to post
Share on other sites

Hi @Sevarf2 

Maybe, but I don't use it any more on any installs. I'm using RockMigrations on all my sites and TracyDebugger makes it absolutely trivial to get the information necessary 🙂 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By MoritzLost
      This module allows you to integrate hCaptcha bot / spam protection into ProcessWire forms. hCaptcha is a great alternative to Google ReCaptcha, especially if you are in the EU and need to comply with privacy regulations.

      The development of this module is sponsored by schwarzdesign.
      The module is built as an Inputfield, allowing you to integrate it into any ProcessWire form you want. It's primarily intended for frontend forms and can be added to Form Builder forms for automatic spam protection. There's a step-by-step guide for adding the hCaptcha widget to Form Builder forms in the README, as well as instructions for API usage.
      Features
      Inputfield that displays an hCaptcha widget in ProcessWire forms. The inputfield verifies the hCaptcha response upon submission, and adds a field error if it is invalid. All hCaptcha configuration options for the widget (theme, display size etc) can be changed through the inputfield configuration, as well as programmatically. hCaptcha script options can be changed through a hook. Error messages can be translated through ProcessWire's site translations. hCaptcha secret keys and site-keys can be set for each individual inputfield or globally in your config.php. Error codes and failures are logged to help you find configuration errors. Please check the README for setup instructions.
      Links
      Github Repository and documentation InputfieldHCaptcha in the module directory (pending approval) Screenshots (configuration)

      Screenshots (hCaptcha widget)

       
       

       
    • By joshua
      This module is (yet another) way for implementing a cookie management solution.
      Of course there are several other possibilities:
      - https://processwire.com/talk/topic/22920-klaro-cookie-consent-manager/
      - https://github.com/webmanufaktur/CookieManagementBanner
      - https://github.com/johannesdachsel/cookiemonster
      - https://www.oiljs.org/
      - ... and so on ...
      In this module you can configure which kind of cookie categories you want to manage:

      You can also enable the support for respecting the Do-Not-Track (DNT) header to don't annoy users, who already decided for all their browsing experience.
      Currently there are four possible cookie groups:
      - Necessary (always enabled)
      - Statistics
      - Marketing
      - External Media
      All groups can be renamed, so feel free to use other cookie group names. I just haven't found a way to implement a "repeater like" field as configurable module field ...
      When you want to load specific scripts ( like Google Analytics, Google Maps, ...) only after the user's content to this specific category of cookies, just use the following script syntax:
      <script type="text/plain" data-type="text/javascript" data-category="statistics" data-src="/path/to/your/statistic/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing" data-src="/path/to/your/mareketing/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="external_media" data-src="/path/to/your/external-media/script.js"></script> <script type="text/plain" data-type="text/javascript" data-category="marketing">console.log("Inline scripts are also working!");</script> The type has to be "optin" to get recognized by PrivacyWire, the data-attributes are giving hints, how the script shall be loaded, if the data-category is within the cookie consents of the user. These scripts are loaded asynchronously after the user made the decision.
      If you want to give the users the possibility to change their consent, you can use the following Textformatter:
      [[privacywire-choose-cookies]] It's planned to add also other Textformatters to opt-out of specific cookie groups or delete the whole consent cookie.
      You can also add a custom link to output the banner again with a link / button with following class:
      <a href="#" class="privacywire-show-options">Show Cookie Options</a> <button class="privacywire-show-options">Show Cookie Options</button> This module is still in development, but we already use it on several production websites.
      You find it here: PrivacyWire Git Repo
      Download as .zip
      I would love to hear your feedback 🙂
      CHANGELOG
      0.1.1 Debugging: fixed error during uninstall 0.1.0 Added new detection of async scripts for W3C Validation 0.0.6 CSS-Debugging for hiding unused buttons, added ProCache support for the JavaScript tag 0.0.5 Multi-language support included completely (also in TextFormatter). Added possibility to async load other assets (e.g. <img type="optin" data-category="marketing" data-src="https://via.placeholder.com/300x300">) 0.0.4 Added possibility to add an imprint link to the banner 0.0.3 Multi-language support for module config (still in development) 0.0.2 First release 0.0.1 Early development
    • By bernhard
      --- Please use RockFinder3 ---
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory (pending approval) If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By Craig
      I've been using Fathom Analytics for a while now and on a growing number of sites, so thought it was about time there was a PW module for it.
      WayFathomAnalytics
      WayFathomAnalytics is a group of modules which will allow you to view your Fathom Analytics dashboard in the PW admin panel and (optionally) automatically add and configure the tracking code on front-end pages.
      Links
      GitHub Readme & documentation Download Zip Modules directory Module settings screenshot What is Fathom Analytics?
      Fathom Analytics is a simple, privacy-focused website analytics tool for bloggers and businesses.

      Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don't need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
      Privacy focused Fast-loading dashboards, all data is on a single screen Easy to get what you need, no training required Unlimited email reports Private or public dashboard sharing Cookie notices not required (it doesn't use cookies or collect personal data) Displays: top content, top referrers, top goals and more
×
×
  • Create New...