Jump to content

RockSVN brings Version Control to your Fields & Templates


bernhard
 Share

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
Link to comment
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 

Link to comment
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?

Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 2 weeks later...
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 6 months later...

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
Link to comment
Share on other sites

  • 2 years later...

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
 Share

×
×
  • Create New...