-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from plone/maurits-sustainable-exports-update-…
…dates-at-end-take-two Import: update dates again at the end. Take 2.
- Loading branch information
Showing
9 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Import: update modification dates again at the end. The original modification dates may have changed. @mauritsvanrees |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from .base import BaseDatalessImporter | ||
from plone import api | ||
from plone.exportimport import logger | ||
from plone.exportimport.interfaces import IExportImportRequestMarker | ||
from plone.exportimport.utils import content as content_utils | ||
from plone.exportimport.utils import request_provides | ||
from Products.CMFCore.indexing import processQueue | ||
|
||
import transaction | ||
|
||
|
||
class FinalImporter(BaseDatalessImporter): | ||
# name: str = "" | ||
|
||
def do_import(self) -> str: | ||
count = 0 | ||
|
||
with request_provides(self.request, IExportImportRequestMarker): | ||
catalog = api.portal.get_tool("portal_catalog") | ||
# getAllBrains does not yet process the indexing queue before it starts. | ||
# It probably should. Let's call it explicitly here. | ||
processQueue() | ||
for brain in catalog.getAllBrains(): | ||
obj = brain.getObject() | ||
logger_prefix = f"- {brain.getPath()}:" | ||
for updater in content_utils.final_updaters(): | ||
logger.debug(f"{logger_prefix} Running {updater.name} for {obj}") | ||
updater.func(obj) | ||
|
||
# Apply obj hooks | ||
for func in self.obj_hooks: | ||
logger.debug( | ||
f"{logger_prefix} Running object hook {func.__name__}" | ||
) | ||
obj = func(obj) | ||
|
||
count += 1 | ||
if not count % 100: | ||
transaction.savepoint() | ||
logger.info(f"Handled {count} items...") | ||
|
||
report = f"{self.__class__.__name__}: Updated {count} objects" | ||
logger.info(report) | ||
return report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
from DateTime import DateTime | ||
from plone.exportimport import interfaces | ||
from plone.exportimport.importers import content | ||
from plone.exportimport.importers import final | ||
from zope.component import getAdapter | ||
|
||
import pytest | ||
|
||
|
||
class TestImporterContent: | ||
@pytest.fixture(autouse=True) | ||
def _init(self, portal_multilingual_content): | ||
self.portal = portal_multilingual_content | ||
self.importer = final.FinalImporter(self.portal) | ||
|
||
def test_adapter_is_registered(self): | ||
adapter = getAdapter( | ||
self.portal, interfaces.INamedImporter, "plone.importer.final" | ||
) | ||
assert isinstance(adapter, final.FinalImporter) | ||
|
||
def test_output_is_str(self, multilingual_import_path): | ||
result = self.importer.import_data(base_path=multilingual_import_path) | ||
assert isinstance(result, str) | ||
assert result == "FinalImporter: Updated 19 objects" | ||
|
||
def test_empty_import_path(self, empty_import_path): | ||
# The import path is ignored by this importer. | ||
result = self.importer.import_data(base_path=empty_import_path) | ||
assert isinstance(result, str) | ||
assert result == "FinalImporter: Updated 19 objects" | ||
|
||
|
||
class TestImporterDates: | ||
@pytest.fixture(autouse=True) | ||
def _init(self, portal, base_import_path, load_json): | ||
self.portal = portal | ||
content_importer = content.ContentImporter(self.portal) | ||
content_importer.import_data(base_path=base_import_path) | ||
importer = final.FinalImporter(portal) | ||
importer.import_data(base_path=base_import_path) | ||
|
||
@pytest.mark.parametrize( | ||
"uid,method_name,value", | ||
[ | ||
[ | ||
"35661c9bb5be42c68f665aa1ed291418", | ||
"created", | ||
"2024-02-13T18:16:04+00:00", | ||
], | ||
[ | ||
"35661c9bb5be42c68f665aa1ed291418", | ||
"modified", | ||
"2024-02-13T18:16:04+00:00", | ||
], | ||
[ | ||
"3e0dd7c4b2714eafa1d6fc6a1493f953", | ||
"created", | ||
"2024-03-19T19:02:18+00:00", | ||
], | ||
[ | ||
"3e0dd7c4b2714eafa1d6fc6a1493f953", | ||
"modified", | ||
"2024-03-19T19:02:18+00:00", | ||
], | ||
[ | ||
"e7359727ace64e609b79c4091c38822a", | ||
"created", | ||
"2024-02-13T18:15:56+00:00", | ||
], | ||
# Note: this would fail without the final importer, because this | ||
# is a folder that gets modified later when a document is added. | ||
[ | ||
"e7359727ace64e609b79c4091c38822a", | ||
"modified", | ||
"2024-02-13T20:51:06+00:00", | ||
], | ||
], | ||
) | ||
def test_date_is_set(self, uid, method_name, value): | ||
from plone.exportimport.utils.content import object_from_uid | ||
|
||
content = object_from_uid(uid) | ||
assert getattr(content, method_name)() == DateTime(value) |