Important Notice

This documentation page is no longer actively maintained and will be deactivated soon. Please visit our new documentation at https://docs.structr.com and update your bookmarks.

▸ https://docs.structr.com

changelog()

Usage

changelog(entity[, resolve=false[, filterKey, filterValue...]])
Structr.changelog(entity[, resolve=false[, filterObject]])

Description
Returns the changelog for a specific entity. See Changelog for details on what the contents of a changelog are.
The resolve parameter controls if remote entities are resolved. Every changelog entry which has a target will be resolved as targetObj (if the remote entity still exists in the database).

Filtering (supported from version 2.2)

All filter options are chained using the boolean AND operator. Only changelog entries matching all of the specified filters will be returned.
For filter keys which can occurr more than once, the filter values are combined using the boolean OR operator (see examples 1 and 2)

Filter Key Applicable Changlog verbs (*) Changelog Entry will be returned if max. occurrences
timeFrom (**) create, delete, link, unlink, change timeFrom <= time of the entry 1 (***)
timeTo (**) create, delete, link, unlink, change timeTo >= time of the entry 1 (***)
verb create, delete, link, unlink, change verb of the entry matches at least one of the verbs n (****)
userId create, delete, link, unlink, change userId of the entry matches at least one of the userIds n (****)
userName create, delete, link, unlink, change userName of the entry matches at least one of the userNames n (****)
relType link, unlink rel of the entry matches at least one of the relTypes n (****)
relDir link, unlink relDir of the entry matches the given relDir 1 (***)
target create, delete, link, unlink target of the entry matches at least one of the targets n (****)
key change key of the entry matches at least one of the keys n (****)

(*) If a filter parameter is supplied, only changelog entries can be returned to which it is applicable. (e.g. combining key and relType can never yield a result as they are mutually exclusive)

(**) timeFrom/timeTo can be specified as a Long (time in ms since epoch), as a JavaScript Date object, or as a String with the format yyyy-MM-dd'T'HH:mm:ssZ

(***) The last supplied parameter takes precedence over the others

(****) The way we supply multiple occurrences of a keyword can differ from StructrScript to JavaScript

  • StructrScript: changelog(node, false, ‘verb’, ‘link’, ‘verb’, ‘unlink’)
  • JavaScript: Structr.changelog(node, false, ‘verb’, ‘link’, ‘verb’, ‘unlink’); OR Structr.changelog(node, false, {verb: [“link”, “unlink”]});

Note: The Changelog has to be enabled for this function to work properly. This can be done via the application.changelog.enabled key in structr.conf.

Note: The prev and val keys in the change event contain JSON encoded elements since they can be strings or arrays.

Examples

  1. StructrScript

    1. Return all changelog entries with verb=link
      • changelog(node, false, 'verb', 'link')
    2. Return all changelog entries with verb=(link OR unlink)
      • changelog(node, false, 'verb', 'link', 'verb', 'unlink')
    3. Return all changelog entries with (rel=OWNS) AND (verb=(link OR unlink))
      • changelog(node, false, 'verb', 'link', 'verb', 'unlink', 'relType', 'OWNS')
      • Note: filtering for the verbs link and unlink is redundant in this case as relType implies that only those verbs can be returned
    4. Return all changelog entries with (target=) AND (verb=(link OR unlink))
      • changelog(node, false, 'verb', 'link', 'verb', 'unlink', 'target', '<NODEID>')
      • Note: In this case the verb filter makes sense as the fitler key target also applies to the verbs create and delete
  2. The same examples in JavaScript. For each entry both versions are identical. One uses the StructrScript way of supplying parameters, the other uses the JavaScript way.

    1. Return all changelog entries with verb=link
      • Structr.changelog(node, false, 'verb', 'link')
      • Structr.changelog(node, false, {verb: 'link'});
    2. Return all changelog entries with verb=(link OR unlink)
      • Structr.changelog(node, false, 'verb', 'link', 'verb', 'unlink')
      • Structr.changelog(node, false, {verb: ['link', 'unlink']});
    3. Return all changelog entries with (rel=OWNS) AND (verb=(link OR unlink))
      • Structr.changelog(node, false, 'verb', 'link', 'verb', 'unlink', 'relType', 'OWNS')
      • Structr.changelog(node, false, {verb: ['link', 'unlink'], 'relType': 'OWNS'});
    4. Return all changelog entries with (target=) AND (verb=(link OR unlink))
      • Structr.changelog(node, false, 'verb', 'link', 'verb', 'unlink', 'target', '<NODEID>')
      • Structr.changelog(node, false, {verb: ['link', 'unlink'], 'target': '<NODEID>'});
About this article
Last change 2020-04-28
Topics ExperimentalFunctionsStructr 2.1