Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-10-06 20:04:51

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Is there an database field for an article's revision number?

I write an article, I publish, and that’s revision 1. I make a change to the article, I do not change the date stamp…that’s now revision 2. I make another change to the same article, I update the date stamp, that’s revision 3.

Is there a way to extract the revision number of the article? I don’t care about the dates, I don’t care about the content of the older revisions, I’m just interested in the numeric value of the revision. I can achieve this manually with a custom field, of course, but that assumes I’m able to remember it every time I update an article.

Is this possible?

Offline

#2 2019-10-06 20:19:49

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Is there an database field for an article's revision number?

Nope. Not without a plugin. Saving just replaces the content with no indicator of how many times.

rah_post_versions is a full-blown history-saving plugin so the revision states – content and everything – are kept. If you installed that, it’s not beyond the realm of possibility to query the database and COUNT(*) the rows the plugin has saved that are attached to an article to find out how many revisions have been made.

?

EDIT: Alternatively, a little plugin that increments the revision counts against each article ID ought to be possible by hooking into the article.save callback. Would you want to display this on the Write panel itself? Or display it on the public site via a tag? Or just know by looking in the database from time to time?

Last edited by Bloke (2019-10-06 20:22:16)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2019-10-06 20:50:58

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Re: Is there an database field for an article's revision number?

Bloke wrote #319553:

Nope. Not without a plugin. Saving just replaces the content with no indicator of how many times.

[…]

EDIT: Alternatively, a little plugin that increments the revision counts against each article ID ought to be possible by hooking into the article.save callback. Would you want to display this on the Write panel itself? Or display it on the public site via a tag? Or just know by looking in the database from time to time?

Public site using a tag (or etc_query…). I’m looking to populate the SEQUENCE data in an iCalendar form and subscription. I could probably bodge it by using a modified conditional and perhaps do something with the epoch timestamp or a specially-formatted date, so my SEQUENCE value would start at a huge number instead of 1, but any revisions would definitely make the SEQUENCE higher, with the nature of epoch values. I don’t know how the various calendar clients would cope with huge numbers, so that’s another consideration.

Please don’t spend time writing a plugin on my account, Stef!

Offline

#4 2019-10-06 22:27:35

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Is there an database field for an article's revision number?

gaekwad wrote #319554:

I’m looking to populate the SEQUENCE data in an iCalendar form and subscription.

So you don’t need to capture the sequence number for all articles, right? Only those in certain sections that contain events?

Not sure how best to do this: new field in the textpattern table which could be updated on save for all articles. Or a separate table that contains article_id and sequence. That could either capture all articles or just those from a defined series of section names.

Curve ball: use rvm_counter like this:

  1. Install plugin.
  2. Write a tiny few-line plugin that hooks into the save mechanism which calls rvm_counter() on save and uses the article’s ID as part of the name (e.g. name="article-<ID>").
  3. In your iCalendar form, read the value of the counter for the current article via <txp:rvm_counter name='article-<txp:article_id />' step="0" />
  4. Profit.

The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2019-10-06 22:58:29

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Is there an database field for an article's revision number?

Like this:

# smd_article_sequence v0.1.0
# Keep track of how many times an article is saved. Requires rvm_counter plugin.
# Stef Dawson
# https://stefdawson.com/

# ......................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# ......................................................................

H4sIAAAAAAAAA52TzY7aMBCA73mKqbVSAFEIAXaDEVUPe6l63CNC0WA7YDWxU9uBohXvXjsJ
Fa2QWtUnz/ib/zHSWUrfLV1QorASZG1pmlBiK56jcZKVIrfieyMUa99eKDkJY6VWQVpSkkxm
kyTcnynBxh21CcJsRsmbEwW84tl27Cy5AXljZBtnTsnRudrS6dR6mLfshOlqevPBhWVG1q6P
t1hR8lWIGpxB9g10AUd9hgrVBZyshAVU0GcN0oLFk+CTPlFtuOhyo2TZOqPEXWrRqxY9VpR4
sL0u6bGjKOtw9RX0GqZ5a7jMvCALGLgftVROmAKZgM1mAzHySqp4CO8R+GPEQfoaTc6wLPc+
+UH8qMXx2Bv2ulp7Ax4P1//roC0/2F+jaDoaRTCC7SMbuOvyLlCfazRYAWxDf3bwJE7OC3+j
rKv/geLo8AFlhGuMulHd+ZOaRkWjWJDgURmDkOe4zWPcxRlGXfMPpd5jCU912Ryksuuo1Yax
fZDK+zF4GcTmVOVMN2GIvok3dngbYDilRp53D7/z/YyuneO7l0HvPHytGDaffg3nYzxpU9zG
X17j3bAdUliorNu23OD5buP8R6l4u7TzlJIs2YvVnL0sWZZmuEiwWAlRZAueps+r5cov5vUn
DL6S+9YDAAA=

Install and activate rvm_counter then this’ll do exactly what you want I think.

EDIT: currently that’s indescriminant of Status. If you only want it to start counting when the status is one of the published ones, it’s a couple of extra lines of code. Let me know if so.

Last edited by Bloke (2019-10-06 23:02:09)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2019-10-06 23:38:27

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Is there an database field for an article's revision number?

Oh alright, here’s an updated version that only increments the counter for published articles (Live and Sticky). Added docs and stuff too.

# smd_article_sequence v0.2.0
# Keep track of how many times an article is saved. Requires rvm_counter plugin.
# Stef Dawson
# https://stefdawson.com/

# ......................................................................
# This is a plugin for Textpattern - http://textpattern.com/
# To install: textpattern > admin > plugins
# Paste the following text into the 'Install plugin' box:
# ......................................................................

H4sIAAAAAAAAA+1XTW/jNhC961dMtQFkB478sU68VWo3KYICaS9FN4uiKBYCJY0tIhKpkpQd
7yL/vUOKSmzUl+2ph/hgmdR8vHnzOIRZMp0lX3UyT0LBagyvdTKbJKGui5Qpw/MKU41/tyhy
926RhFtUmkthV5dJOIln8cT+vkpC1ppSKruYTpPwo8E13LGd7myn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ZpyF9Hbhd25nvuEhd2kF0IAHiqbcd9j2yHzv50+7F
sb1vw/Nr4G+Kax0c4L+ij4aZVkefYbWE+aGNa/NrqIGPbk94BMvVS2MvotiHur+LPg89sg5d
9/0cWHF+6K7TVLHd25X6dqW+XalvV+r/9Uql/y514f4qvJ8l4fSSfT/HyXyWZevL+YR+ZVO2
WLB8cZWxSV6E18//AFsCI9JpDQAA

And the official release for anyone interested.

Last edited by Bloke (2019-10-06 23:55:31)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2019-10-07 08:03:02

gaekwad
Server grease monkey
From: People's Republic of Cornwall
Registered: 2005-11-19
Posts: 4,134
GitHub

Re: Is there an database field for an article's revision number?

Crikey, oh-blimey. Thanks Stef!

Offline

#8 2019-10-07 08:40:30

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,250
Website GitHub

Re: Is there an database field for an article's revision number?

You’re welcome. Hope it’s useful. Let me know if you need it to do anything else.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB