Giter VIP home page Giter VIP logo

versioncontrol's Introduction

Version Control For ProcessWire CMS/CMF

Version Control Module For ProcessWire CMS/CMF. Copyright (c) 2013-2022 Teppo Koivula

This module uses hooks provided by ProcessWire to catch page edits and stores history data in a series of custom database tables, so that it can be later retrieved, reviewed, and restored.

Note that at module settings you can define which specific fieldtypes and fields to track and for which templates tracking values should be enabled. Right out of the box tracking is disabled for all templates and fields.

While editing a page with version control enabled, revision toggle (link which opens list of previous revisions) is shown for fields with earlier revisions available. From this list user can select a revision and rollback value of the field to that specific revision.

Supported fieldtypes and inputfields

All native ProcessWire fieldtypes and inputfields, apart from those that either don't directly store values at all (repeaters fields, fieldsets) or only store hashed values (password), should be supported by the time of this writing:

  • Email
  • Datetime
  • Text (regular and multi-language)
  • Textarea (regular and multi-language)
  • Page Title (regular and multi-language)
  • Checkbox
  • Integer
  • Float
  • URL
  • Page
  • Module
  • File
  • Image
  • Selector
  • Options

Supported third party fieldtypes:

  • ProFields Textareas

If a specific fieldtype isn't listed here, it doesn't necessarily mean that it's not supported; it just hasn't been tested yet. If you know a fieldtype that works properly with this module but isn't included here, please inform the author of this module via GitHub.

You can enable support for any installed fieldtypes locally by modifying the "Compatible fieldtypes" setting, which can be found under "Advanced Settings" in module configuration screen.

Following inputfields are confirmed to be supported:

  • TinyMCE
  • CKEditor (regular and inline mode)
  • Text (+ other inputfields using <input> HTML element, such as Email)
  • Textarea (+ other inputfields using regular <textarea> HTML element)
  • Select
  • File
  • Image
  • Selector

Requirements

Please note that this module requires ProcessWire 2.4.1 or a later version. If you're still running an earlier version of ProcessWire and would like to have a similar feature, please take a look at the Version Control for Text Fields module: https://github.com/teppokoivula/VersionControlForTextFields.

Getting started

Copy (or clone with git) VersionControl folder to /site/modules/, go to Admin > Modules, hit "Check for new modules" and install Version Control. Supporting modules Process Version Control and Page Snapshot are installed automatically.

After installing this module you need to configure it before anything really starts happening. Most configuration options (essentially templates and fields this module is switched on for) can be found from Admin > Modules > Version Control (module config.) Minor settings can be found from related Process modules config: Admin > Modules > Process Version Control.

Diff Match and Patch

The Diff Match and Patch libraries offer robust algorithms to perform the operations required for synchronizing plain text. In the scope of current module, the JavaScript implementation of Diff Match and Patch is used to render diff between different revisions of a field value.

Diff Match and Patch is copyright (c) 2006 Google Inc. and released under the Apache License, Version 2.0. For more information about this library, please visit http://code.google.com/p/google-diff-match-patch/.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

(See included LICENSE file for full license text.)

versioncontrol's People

Contributors

arjenblokzijl avatar happy-kaseem avatar teppokoivula avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

versioncontrol's Issues

Multi-language fields, erroneous diff

The more I explore the module VersionControl, the more I discover great features like the little clock icon next to the input in the admin module for fields included for version control (see screenshot below).

version-control-history

Hovering over the clock icon reveals the list of revisions for the field which then in turn can be compared with the latest revision of the field.

Whereas this feature seems to produce correct results for standard input fields, it produces some erroneous results for multi-language fields.

Since there is only one icon for a multi-language field (see screenshot above) it is not possible to have separate revision histories for the different languages.

Currently the result is a mixture of diffs between languages depending on the languages modified per revisions. So it can be that a change to the German version is compared with the latest English version. A comparison with the latest German version does not seem possible.

For a correct implementation of this feature with multi-language fields, we would probably need to have a clock icon for each language and create a history for each language separately.

A really helpful feature in the context of multi-language fields might be a function which allows to compare two languages and show the differences applied to one language since the last time the other language has been updated. This would help the translator to know what he needs to change without having to read the whole text again in both languages.

History tab appears if not assigned to the specific template but to another template

If VersionControl is added to one single template, the tab will appear in every page UI.

The hook in ProcessPageEdit::getTabs() added by init() is assigned if the property (array) $enabled_templates is not empty. This check is a bit lazy.

Solution:
Move the hook inside hook function buildFormHistory() Line 971 after checking data:

if (!$data) return;
$this->addHookAfter('ProcessPageEdit::getTabs', $this, 'addTabHistory');

Multi-language textfields - database is not filled with the original values at module installation time

VersionControl does at the moment of its installation not store the initial values of TextareaLanguage (Textarea [Multi-language]) fields. To be specific probably all fields which store there data with the class LanguagesPageFieldValue.
I have been testing it again on the latest release version 1.2.9 by installing VersionControl on my test site and activating it for two fields on one template. The two fields are of type:

  • Textarea (normal single language text)
  • TextareaLanguage (multi-language)
    When I check the table "version_control__data" I find only entries for the field of type "Textarea" whereas there are no entries at all for the field of type "TextareaLanguage".
    As far as I can tell, there is an issue with the function used to find the data of fields of type "TextareaLanguage" at the time of installation of the module: $data->getChanges() will only return changes made to the data of the instance of $data at run-time which is the case when this code finds changes to a field of type "TextareaLanguage". But when the module is newly installed the function $data->getChanges() will return nothing since the field data is in it's original state as stored in the database table.
                } else if ($data instanceof LanguagesPageFieldValue) {
                    foreach ($data->getChanges() as $key) {
                        if ($key == 'data') continue;
                        $data_array[$key] = $data->getLanguageValue(str_replace('data', '', $key));
                    }
                } else {

(see code on github here)

I have done some research on how the data is stored internally at run-time and on the database and I hope that my patch addresses the problem correctly: Every language value, including the default language, is stored under a key 'data'.$language->id, the same way the function getChanges() returns the keys.

I have made a suggestion for how to changes this on my fork. There is a pull request available.

AsmSelects of PageArrays not saved

It appears that for Page fields that can contain multiple pages and are entered using the AsmSelect input field type, values are not saved. Saving the page clears this type of fields.

Small CSS issue with new AdminThemeUikit

Add width: auto !important; to .field-revisions class.

VersionControl.css (line 39)

.field-revisions {
    width: auto !important;
    padding: 36px 0 0 0 !important;
    overflow: visible !important;
    position: absolute;
    margin-top: -28px;
    display: none;
    z-index: 99;
    right: 10px;
}

Error when installing

Installing this module in my ProcessWire 3.0.42 (on Windows 10 XAMPP) throws the following error:
Call to undefined function finfo_open()
...\site\modules\VersionControl\VersionControl.module:844
$finfo = finfo_open(FILEINFO_MIME_TYPE);
But after reloading the page the error does not appear.

Can version history be persisted for deleted pages?

The question I have concerns version history of pages that are deleted. My understanding from reading the documentation some months ago was that, if a page of content is deleted, then the corresponding VCS history is deleted.

Essentially the basic requirement is to be able to track and potentially restore deleted content. Is that a possibility?

Scroll bars on revisions div (dev branch)

There are unnecessary scroll bars on the revisions div:

2020-01-29_142329

Possible fix: change...

.field-revisions > div {
    overflow: scroll !important;
}

...to...

.field-revisions > div {
    overflow: auto !important;
}

Bug: Missing required GET param pages_id

Hi, I have tried your module but get:

{"error":true,"message":"Missing required GET param pages_id"}

output on top of the page after saving.

I also wonder where to find the history of all page edits.

In the readme, the information is missing how to access the page history and revert. Can you please add this. It would help others too.

Pagination on history tab

Hi @teppokoivula - would you mind appending the tab hash to the url when clicking page links on the history tab, eg: /edit/?page=2&id=10416#VersionControlHistory

Currently it loads the edit page on the main content tab which isn't ideal. Or maybe the tab can be triggered the same way the PW core does when you save a page and you're on a different tab at the time. I haven't looked into how this is done.

Thanks.

PHP Deprecated: Creation of dynamic property VersionControl\ProcessModuleConfig::$data is deprecated in ProcessModuleConfig.php:25

Seeing this on PHP8.2. That's it really :)


PHP Deprecated: Creation of dynamic property VersionControl\ModuleConfig::$data is deprecated in .../html/site/modules/VersionControl/lib/ModuleConfig.php:25

PHP Deprecated: Creation of dynamic property VersionControl\ProcessModuleConfig::$data is deprecated in .../modules/VersionControl/lib/ProcessModuleConfig.php:25

PHP Deprecated: Creation of dynamic property VersionControl\CleanupModuleConfig::$data is deprecated in .../modules/VersionControl/lib/CleanupModuleConfig.php:25

Module prevents required asterisk appearing in field headers

Copying this over from a forum comment that might have been overlooked.

The Version Control module is preventing the red asterisk from appearing in the header of required fields. The relevant admin CSS is:

.InputfieldStateRequired>.InputfieldHeader:first-child:after {
    content: ' *';
    color: #C00C19;
}

The addition of the field-revisions div interferes with this.

P.S. This relates to the dev branch - not sure if the v1 branch is also affected.

Request: hookable methods to facilitate use with non-core Fieldtypes

It would be great if there were some hookable methods in the module that allowed for special treatment to be applied to non-core fieldtypes. I'm imagining hooks that let a developer modify the history data that is saved to the database, and modify the result of that data when it is restored to a field.

For instance, I tested with FieldtypeMapMarker and the history and diff parts seemed to work okay but the restore action failed because the saved data needs to be converted into an object of the right class.

"There is no difference between these revisions" - entry for certain API saves and certain field types.

Hi @teppokoivula

I am seeing new entries with that text for certain field types. For some field types it only happens if I use setAndSave(), but for others, it happens even with a regular save().

The save is happening via an AJAX call and I don't do any checking on old (already in the DB) vs new (values submitted via the form) so I am always setting the value of every field as part of the save process. Not sure if that is relevant or not though.

For text and date fields it's only an issue if I do setAndSave(), but for page reference fields, it happens regardless of how I save. Another problematic field type is my phone field which also gets a revision entry regardless of how I save.

I wonder if perhaps the easiest way to fix this would be to have an option to not record a revision if there is no change?

OT, but back to the phone field - it only supports the main number subfield - do you think it would be possible to support the country subfield as well?

[DOM] Found 2 elements with non-unique id #Inputfield_id

Hi @teppokoivula - I am seeing this error in the browser console when viewing a user page (Access > Users > xxxxxx). It seems to be coming from the History tab.

Obviously you'll need version control on for some of the fields on the user template. Please let me know if you have any problems reproducing.

Thanks.

Restore Revision not working properly

Hi, I'm running on a fresh processwire install with a fresh install of the module. No third party/incompatible field types are being used. Tracked templates and fields have been configured properly upon module installation.;

Clicking the "Restore Revision" button on the history tab of a page for some revision will show the message that "Page restored to revision #X", however, the page content and the field values never get changed to the values in the revision that was supposed to be reverted to.

Edit: I can, however, revert an individual field to a selected revision. Reverting the entire page "acts" as if it worked, but none of the content is actually reverted changed.

Restoring revisions

I am wondering if I misunderstand the concept of this module or if this is an actual bug.

Let's say, I have a template with two fields A and B which I have added to VersionControl. Then I apply the following changes:

  1. Change field A to the value A2
  2. Change field B to the value B2

This results in the following revision history:

Revision  Field A Field B
3 B2
2 A2
1 A1 B1

If I now restore (or preview) Revision 2, I would assume that I get the following values A = A2 and B = B1.

But what I get is A = A2 and B = B2. Which means no change at all and VersionControl ignores the request to restore to Revision 2.

As far as I understand from the code, this happens, because VersionControl in order to restore a revision, clones the current page and applies the requested revision (2 in this case). The result is the above A = A2 and B = B2. And not what I would expect A = A2 and B = B1.

All would work fine if I had changed both fields at every step. But this is generally not the case.

With the current setup, I can only see one solution to the problem on how to restore a revision:

  1. clone the page
  2. apply all the revisions from revision 1 to the requested revision, in this way we would end up with A = A2 and B = B1.

Feature request: Revisions icon next to each field in the changes column of the history tab

Hi @teppokoivula - I think it would be very handy to have the revision popup available from the history tab for each field. When you have a template with lots of fields with version control enabled, it can be very useful to look at the history tab to see what has actually changed, and accessing the diffs from here would make it even more useful, I think.

Mostly OT, but I would also like to see a close "X" on the popup - I find some users struggle to close it, not realizing they need to click the same icon again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.