Skip to content

Commit

Permalink
Merge pull request #1588 from RogerHaase/1533-dump-help-2
Browse files Browse the repository at this point in the history
moin dump-help -n en" updates all meta files fixes 1533
  • Loading branch information
RogerHaase authored Feb 3, 2024
2 parents 678b04d + 1038ae3 commit f59252f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
6 changes: 3 additions & 3 deletions docs/devel/development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,12 @@ When editing is complete run one or more of::
moin maint-reduce-revisions -q <item-name> -n help-en --test true # lists selected items, no updates
moin maint-reduce-revisions -q <item-name> -n help-en # updates selected items

Dump all the help files::
Dump all the English help files to the version controlled directory::

moin dump-help -n en

The above command may update meta files even though the data files have not changed, see #1533.
Commit only the target data and meta files. Revert the other meta files.
The above command may may be useful after updating one or more files. All of the files
will be rewritten but only the changed files will be highlighted in version control.

Moin Shell
==========
Expand Down
6 changes: 5 additions & 1 deletion src/moin/cli/maint/modify_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def PutItem(meta_file, data_file, overwrite):
to_kill = [WIKINAME, ] # use target wiki name
for key in to_kill:
meta.pop(key, None)
if not overwrite:
if overwrite:
# by default, indexing.py will update meta[MTIME] with current time making global history useless
# we preserve the old modified time for use by indexing.py
flaskg.data_mtime = meta[MTIME]
else:
# if we remove the REVID, it will create a new one and store under the new one
meta.pop(REVID, None)
meta.pop(DATAID, None)
Expand Down
15 changes: 11 additions & 4 deletions src/moin/cli/maint/reduce_revisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
import click

from flask import current_app as app
from flask import g as flaskg
from flask.cli import FlaskGroup

from whoosh.query import Term, And, Regex, Not

from moin.constants.keys import NAME, NAME_EXACT, NAMESPACE, REVID, WIKINAME, PARENTID, REV_NUMBER
from moin.constants.keys import NAME, NAME_SORT, NAME_EXACT, NAMESPACE, REVID, WIKINAME, PARENTID, REV_NUMBER, MTIME
from moin.constants.namespaces import NAMESPACE_USERPROFILES
from moin.app import create_app, before_wiki

Expand All @@ -36,7 +37,7 @@ def cli():
@click.option('--query', '-q', type=str, default='',
help='Only perform the operation on items found by the given query.')
@click.option('--namespace', '-n', type=str, default='',
help='Limit selection to this namespace.')
help='Limit selection to a namespace; use "default" for default namespace.')
@click.option('--test', '-t', type=bool, default=0,
help='List selected items, but do not update.')
def ReduceRevisions(query, namespace, test):
Expand All @@ -47,11 +48,13 @@ def ReduceRevisions(query, namespace, test):
if query:
q = And([q, Regex(NAME_EXACT, query)])
if namespace:
q = And([q, Regex(NAMESPACE, namespace)])
if namespace == 'default':
namespace = ''
q = And([q, Term(NAMESPACE, namespace)])
else:
q = Not(Term(NAMESPACE, NAMESPACE_USERPROFILES))

for current_rev in app.storage.search(q, limit=None):
for current_rev in app.storage.search(q, limit=None, sortedby=[NAMESPACE, NAME_SORT]):
current_name = current_rev.meta[NAME]
current_revid = current_rev.meta[REVID]
current_namespace = current_rev.meta[NAMESPACE]
Expand All @@ -76,6 +79,10 @@ def ReduceRevisions(query, namespace, test):
changed = True
del meta[PARENTID]
if changed:
# By default store_revision and whoosh will replace mtime with current time making
# global history useless.
# Save existing mtime which has time this revision's data was last modified.
flaskg.data_mtime = meta[MTIME]
current_rev.item.store_revision(meta, current_rev.data, overwrite=True)
print(" (current rev meta data updated)")
continue
Expand Down
10 changes: 7 additions & 3 deletions src/moin/storage/middleware/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ def tell(self, *args, **kw):
doc.set(moin_page.page_href, str(i))
refs_conv(doc)
# side effect: we update some metadata:
meta[ITEMLINKS] = refs_conv.get_links()
meta[ITEMTRANSCLUSIONS] = refs_conv.get_transclusions()
meta[EXTERNALLINKS] = refs_conv.get_external_links()
meta[ITEMLINKS] = sorted(refs_conv.get_links())
meta[ITEMTRANSCLUSIONS] = sorted(refs_conv.get_transclusions())
meta[EXTERNALLINKS] = sorted(refs_conv.get_external_links())
doc = output_conv(doc)
return doc
# no way
Expand Down Expand Up @@ -1233,6 +1233,10 @@ def store_revision(self, meta, data, overwrite=False,
# e.g. userdefined meta keys or stuff we do not validate. thus, we
# just update the meta dict with the validated stuff:
meta.update(dict(m.value.items()))
if hasattr(flaskg, 'data_mtime'):
# this is maint-reduce-revisions OR item-put CL process, restore saved time of item's last update
meta[MTIME] = flaskg.data_mtime
del flaskg.data_mtime
# we do not want None / empty values:
# XXX do not kick out empty lists before fixing NAME processing:
meta = dict([(k, v) for k, v in meta.items() if v not in [None, ]])
Expand Down

0 comments on commit f59252f

Please sign in to comment.