yeah looks good to go, but lets do it after next alpha so we don't break heaps of patches in queue.

CommentFileSizeAuthor
#45 2614644-split-45.patch56.69 KBandypost
#45 interdiff.txt4.98 KBandypost
#41 default_content-importer_exporter_split-2614644-41.patch51.82 KBAaronBauman
#41 interdiff.txt14.23 KBAaronBauman
#35 2614644-split-34.patch43.66 KBandypost
#35 interdiff.txt10.67 KBandypost
#33 2614644-split-33.patch30.95 KBandypost
#33 interdiff.txt11.31 KBandypost
#32 default_content-importer_exporter_split-2614644-32.patch44.34 KBAaronBauman
#29 default_content-importer_exporter_split-2614644-29.patch44.34 KBAaronBauman
#27 default_content-importer_exporter_split-2614644-27.patch27.47 KBAaronBauman
#25 default_content-importer_exporter_split-2614644-25.patch26.31 KBAaronBauman
#15 interface-split-2614644-15.diff.txt2.15 KBvprocessor
#15 interface-split-2614644-15.patch27.02 KBvprocessor
#13 interface-split-2614644-13.diff.txt2.15 KBvprocessor
#13 interface-split-2614644-13.patch44.71 KBvprocessor
#7 2614644-interface-split.patch27.55 KBSam152
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sam152 created an issue. See original summary.

larowlan’s picture

+1

jibran’s picture

Priority: Minor » Normal

+1 with more tests. :)

claudiu.cristea’s picture

Shouldn't the import process be handled as a normal migration, as we already have migrate as a core functionality?

claudiu.cristea’s picture

Some PROS for #4:

  • Code reuse.
  • Use of an official API for importing entities.
  • The import can be done anytime, not only on module enabling. This is very useful when having sites on production to whom we still need to add new content or update existing content. Old items (already imported) can be refreshed too, as we do in Migrate.

CONS:

  • New dependency on 'migrate'.
Sam152’s picture

> Use of an official API for importing entities.

This module is implemented on top of cores REST and serialization services. The key thing here is that entities can be imported AND exported, which migrate isn't natively concerned with.

> The import can be done anytime, not only on module enabling.

All functionality is exposed via services. You can use these services anywhere.

This is of course one of the many possible solutions for default content. It has already had a surprising amount of battle-testing despite being so early in D8s life but you're of course welcome to create a solution based on Migrate, however it doesn't live in this project. I've discussed default content solutions based on Migrate previously, I believe the outcome was that it would be less "automatic" but with potentially other upsides.

Sam152’s picture

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Looks great, only one nit that could be fixed on commit

+++ b/src/Tests/DefaultContentManagerIntegrationTest.php
@@ -29,9 +29,9 @@ class DefaultContentManagerIntegrationTest extends KernelTestBase {
    * The tested default content manager.
    *
-   * @var \Drupal\default_content\DefaultContentManager
+   * @var \Drupal\default_content\ExportManagerInterface

nit, comment needs fix also

Sam152’s picture

Retesting to see if this still applies.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 2614644-interface-split.patch, failed testing.

Sam152’s picture

Issue tags: +Needs reroll
vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

Hi guys,
Reroll is ready (rerolled & fixed), check install/uninstall only because I am not sure about how to test this module properly

vprocessor’s picture

Assigned: vprocessor » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll
vprocessor’s picture

Updated with "git diff -M25%" to reduce size of patch

Sam152’s picture

I'll let someone else review and commit this having written the original patch.

andypost’s picture

Assigned: Unassigned » larowlan
Status: Needs review » Reviewed & tested by the community

that looks great but breaks a lot of patches in queue

@Larowlan please decide, this suppose to be in alpha 4 release, but maybe better to wait

larowlan’s picture

Issue summary: View changes
+++ b/default_content.services.yml
@@ -1,10 +1,13 @@
\ No newline at end of file

minor nit to fix on commit

andypost’s picture

andypost’s picture

@larowlan do you mind to keep BC shim for old manager?

And names should be default_content.importer & default_content.exporter

larowlan’s picture

Issue tags: -Needs reroll +Needs change notice

@andypost - given its still an alpha, I'm happy if we break BC, provided we have a change notice.

andypost’s picture

Title: Consider splitting DefaultContentManager into DefaultContentExportManager and DefaultContentImportManager » Split DefaultContentManager into DefaultContentExporter and DefaultContentImporter
Assigned: larowlan » Unassigned

proper title

AaronBauman’s picture

Assigned: Unassigned » AaronBauman
AaronBauman’s picture

#13 is old enough that i'm gonna have to re-roll from scratch.
significant divergences in the past 12 months

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
26.31 KB

In this patch:
- Minimal changeset (in terms of class methods) to split import and export methods into two different classes
- Elimination of ununsed dependencies from constructors, use statements, and service definitions
- Elimination of unused setScanner() method

I don't think an interdiff will be helpful, because of the significant delta in codebase.

Status: Needs review » Needs work

The last submitted patch, 25: default_content-importer_exporter_split-2614644-25.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
27.47 KB

- Removes export methods from import interface

Status: Needs review » Needs work

The last submitted patch, 27: default_content-importer_exporter_split-2614644-27.patch, failed testing.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
44.34 KB

- Fix service arguments to match constructors

git is creating a difficult to read patch for this, with a copy and a couple rename operations.
Makes it somewhat hard to read.

Status: Needs review » Needs work

The last submitted patch, 29: default_content-importer_exporter_split-2614644-29.patch, failed testing.

AaronBauman’s picture

OK, looks like testbot is choking on the patch.
I'll have to hand-roll something to appease testbot.

AaronBauman’s picture

Status: Needs work » Needs review
FileSize
44.34 KB

OK one more try with services DIC before i do a hand roll

andypost’s picture

Here's a reroll after #2857589: Remove the run-as option in drush commands

Also I cleaned-up code a bit.

After that I think it makes sense
- to get rid of "DefaultContent" in interfaces and classes because they are namespaced already
- move dumplication of LINK_DOMAIN const somewhere, maybe container param?!

AaronBauman’s picture

So, rename classes to "Importer", "Exporter", "ImporterInterface" and "ExporterInterface"?
And a container param goes where? services.yml?

andypost’s picture

FileSize
10.67 KB
43.66 KB

A bit more clean-up

andypost’s picture

@aaronbauman yes, exactly, I think that will be more readable and while we do so destructive change better to architect it right

larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/src/DefaultContentExporter.php
    @@ -0,0 +1,225 @@
    +      file_prepare_directory($entity_type_folder, FILE_CREATE_DIRECTORY);
    ...
    +        file_put_contents($entity_type_folder . '/' . $uuid . '.json', $serialized_entity);
    

    Future follow up would be to put this behind a service too, so we could unit test

  2. +++ b/src/DefaultContentImporter.php
    @@ -0,0 +1,243 @@
    +  const LINK_DOMAIN = 'http://drupal.org';
    

    We should just refer to the constant on the exporter, no need to define twice

  3. +++ b/src/DefaultContentImporter.php
    @@ -0,0 +1,243 @@
    +    $folder = drupal_get_path('module', $module) . "/content";
    ...
    +        if (!file_exists($folder . '/' . $entity_type_id)) {
    ...
    +    return file_get_contents($file->uri);
    

    Follow up would be to put this behind another service

  4. +++ b/src/DefaultContentScanner.php
    @@ -16,7 +16,7 @@ class DefaultContentScanner {
    -  public function scan($directory) {
    +  public static function scan($directory) {
    

    Why this change - we can't mock static methods

larowlan’s picture

Also, still need a change notice

AaronBauman’s picture

Here's a new change record: https://www.drupal.org/node/2862246

working on a re-roll now.

AaronBauman’s picture

wrt the file_* operations, i'm looking for examples from core. Looks like the preferred way to do this with a service is to create StreamWrapperInterfaces, extending LocalStream (for export) and LocalReadOnlyStream (for import). The stream wrapper would replace the existing Scanner altogether. The Gettext / PO components have a robust example.

To me, this seems like overkill to implement a new stream service just to wrap a handful of PHP functions, especially when we don't really have any special reading or parsing considerations like PO. Importer::parseFile() already provides a level indirection which we can mock for testing. Refactoring Exporter::writeDefaultContent to add indirection around function calls should, I think, be sufficient for unit testing. There are dozens of examples of core classes calling file_get_contents directly within a protected utility method, for example to read YAML files.

What do you think?

AaronBauman’s picture

In this patch:
- parameterizes link_domain in services.yml and updates relevant classes (Maybe this makes more sense as an install config or setting?)
- splits DefaultContentManager and its interface into Importer and Exporter
- rename DefaultContentScanner to Scanner
- Add ScannerInterface
- Expose Scanner as a service and inject dependency into Importer (rolls in #2861315)
- Add wrapper methods in Exporter for file_prepare_directory and file_put_contents

I had to fudge the interdiff a bit because i couldn't git wouldn't grok the file moves, should be readable though.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change notice

Yeah the file_ changes are 100% out of scope here - but something we should create follow ups for.

If we had them behind a service/interface, we could mock or use vfsStream - leading to the ability to use pure unit tests.

But 100% follow ups.

Added some code samples to the change record.

This is ready in my book.

andypost’s picture

Assigned: AaronBauman » Berdir

@Berdir please confirm that

+++ b/drush/default_content.drush.inc
@@ -55,9 +54,9 @@ function default_content_drush_command() {
+  /** @var \Drupal\default_content\DefaultContentExporterInterface $exporter */

@@ -76,8 +75,8 @@ function drush_default_content_export($entity_type_id, $entity_id) {
-  /** @var \Drupal\default_content\DefaultContentManagerInterface $manager */

+++ b/src/Exporter.php
@@ -0,0 +1,254 @@
+class Exporter implements ExporterInterface {

+++ b/src/ExporterInterface.php
@@ -0,0 +1,57 @@
+interface ExporterInterface {

+++ b/src/Importer.php
@@ -0,0 +1,258 @@
+class Importer implements ImporterInterface {

+++ b/src/ImporterInterface.php
@@ -0,0 +1,21 @@
+interface ImporterInterface {

could be fixed on commit

andypost’s picture

+++ b/src/Scanner.php
@@ -0,0 +1,43 @@
+class Scanner implements ScannerInterface {
...
+  public function scan($directory) {

I still see this as Component and static implementation

directory totally injectable with vfs

andypost’s picture

FileSize
4.98 KB
56.69 KB

I'm going to commit this soon and continue with #2867579: Core 8.3 compatibility

andypost’s picture

Title: Split DefaultContentManager into DefaultContentExporter and DefaultContentImporter » Split DefaultContentManager into Exporter and Importer
Assigned: Berdir » larowlan
larowlan’s picture

Assigned: larowlan » Unassigned

+1

  • andypost committed 14b0c7c on 8.x-1.x
    Issue #2614644 by aaronbauman, andypost, vprocessor, Sam152, larowlan:...
andypost’s picture

Status: Reviewed & tested by the community » Fixed

Now a lot of patches will need re-roll

PS: CR published https://www.drupal.org/node/2862246

andypost’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.