valtech / aem-easy-content-upgrade

AEM Easy Content Upgrade simplifies content migrations in AEM projects
Other
61 stars 25 forks source link

Feature request: print execution stats #216

Open ncautotest opened 1 year ago

ncautotest commented 1 year ago

Allow displaying a grand total for modified resources

While printPath(), printProperty() and printJson() are sure very useful, they only apply to a single resource in a matched resultset. Would there be any value in a feature to display a grand totals that will show an outline of what the script did?

Use case: given a script like the one below, allow the possibility to display grand totals showing which nodes/resources/pages were traversed/modifed/deleted/created etc:

isDryRun = false
isShowStats = true

aecu.contentUpgradeBuilder()
        .forResourcesBySql2Query('''
            SELECT * FROM [cq:Page] as p 
            WHERE ISDESCENDANTNODE(p, "/content") 
            AND p.[jcr:content/sling:resourceType] in (
                "weretail/components/structure/page"
        )''')
        .printPath()
        .doDeleteContainingPage()
        .run(isDryRun)
        .printStats(isShowStats) // <<< example of possible syntax

Or maybe a better approach would be to allow passing an extra parameter to run() e.g:

...
    .run(isDryRun, isShowStats)

Or as a map (more flexible in terms of future customization):

    ...
    run([dryRun: true, showStats: true])

These are just quick not not very well thought through ideas; maybe it would make more sense to have the accounting features configurable/available on the AecuBinding or on the ContentUpgrade object, etc.

Another possible approach might be to expose some simple API to allow the users to add a create/modify/delete record that could be accessed on some global object after execution, e.g. with println(log.printStats() or something like that.

Example of possible grand totals (only a raw idea):

Nodes traversed:  123456789
Nodes created/modified/deleted: 0/0/4200
Properties created/modified/deleted: 0/0/0
Pages created/deleted: 0/400

This is meant to be as a starting point for figuring out a clean approach that would be simple to implement and helpful for API consumers.

wdyt?

nhirrle commented 1 year ago

Hi @ncautotest

Sorry for the late feedback. The idea looks indeed interesting.

As the tracking will take computing time, I would add this as an option to not be executed by default. We need to add it as a binding similar as we do it with the dryRun paramater. Adding a new method .run(isDryRun, isShowStats) seems like a good way and the current one will just add false as the second argument.

In terms of tracking:

Moving forward: If you need this feature soon, feel free to work on it. Otherwise we can put it on the roadmap.

Best Nicolas