• General code cleanup
  • Avoid duplicated code in pull form
  • Currently there are the importChannel and importEntities methods inside the importService (the importChannelPage is currently not implemented because not useful). I think the equivalent of importService and importChannel without being batched will be useful to avoid duplicated code. Or the same methods but with an additional parameter $is_batched or $batched
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Grimreaper created an issue. See original summary.

Grimreaper’s picture

  • General code cleanup
  • Avoid duplicated code in pull form

Grimreaper’s picture

Issue summary: View changes
Grimreaper’s picture

Issue summary: View changes
Grimreaper’s picture

Title: code cleanup » Code cleanup
Status: Active » Needs review
FileSize
28.5 KB
Grimreaper’s picture

adityasingh’s picture

Status: Needs review » Reviewed & tested by the community

Patch looks good to me.

  • Grimreaper authored b95014c on 8.x-3.x
    Issue #3122246 by Grimreaper: Code cleanup: Remove methods to  delete....
Grimreaper’s picture

Status: Reviewed & tested by the community » Active

  • Grimreaper authored 2815871 on 8.x-3.x
    Issue #3122246 by Grimreaper: Code cleanup: PHPCS and PHPMD
    

  • Grimreaper authored 518a2a9 on 8.x-3.x
    Issue #3122246 by Grimreaper: Code cleanup: Fix typo
    
Grimreaper’s picture

Issue summary: View changes
yarik.lutsiuk’s picture

Assigned: Unassigned » yarik.lutsiuk
yarik.lutsiuk’s picture

Assigned: yarik.lutsiuk » Unassigned
ivan.vujovic’s picture

Assigned: Unassigned » ivan.vujovic
ivan.vujovic’s picture

Hello, @grimreaper

The uploaded patch contains several refactorings of code, mostly in pullForm.
I have left the usage of GET parameters (such as $this->query->get('offset')) as they are, I am not sure if we can simplify this code much. If you have some concrete ideas, please let me know.

I will now work on the last point (importService and importChannel without being batched).

Grimreaper’s picture

Status: Active » Needs review

Thanks for the patch. Will give a look when possible.

Triggering automated tests.

Grimreaper’s picture

  1. +++ b/modules/entity_share_async/src/Plugin/QueueWorker/EntityShareAsyncWorker.php
    @@ -89,17 +88,7 @@ class EntityShareAsyncWorker extends QueueWorkerBase implements ContainerFactory
    +    $prepared_url = $this->importService->prepareUuidsFilteredUrl($url, [$item['uuid']]);
    

    Nice. Can we make this method a static one in EntityShareUtility.

    Because it is only manipulating data on its own without calling anything else.

  2. +++ b/modules/entity_share_client/src/Service/StateInformation.php
    @@ -191,6 +143,62 @@ class StateInformation implements StateInformationInterface {
    +      'local_entity_link' => $entity instanceof ContentEntityInterface ? $entity->toUrl() : NULL,
    +      'local_revision_id' => $entity instanceof ContentEntityInterface ? $entity->getRevisionId() : NULL,
    

    Hum as previous code did not handled it. That's ok. But maybe we can add some checks for security in the case of a paragraph entity like on #3162950: Entity import status report broken. And maybe checking if the entity is revisionable for the "->getRevisionId()".

    As previous code did not do that. I will not block the patch for that.

Going to test.

  • ivan.vujovic authored 277b029 on 8.x-3.x
    Issue #3122246 by Grimreaper, ivan.vujovic: Code cleanup
    
Grimreaper’s picture

Status: Needs review » Needs work

Test ok.

Patch from comment 17 merged.

@ivan.vujovic, can you please take my review points into account in your next patch please?

ivan.vujovic’s picture

Thanks @grimreaper for you review and merge!

I totally agree with what you commented.
I think the reason we've never encountered an error with toUrl is that Paragraph entities don't have "changed" attribute so for them the status is always Undefined.

Here is a patch containing just the fixes related to your comments.
I will not have time to work on the rest next week, the issue can be kept open.

Grimreaper’s picture

Status: Needs work » Needs review

  • ivan.vujovic authored ac95044 on 8.x-3.x
    Issue #3122246 by Grimreaper, ivan.vujovic: Move prepareUuidsFilteredUrl...
Grimreaper’s picture

Issue summary: View changes

Patch merged! Thanks :)

Grimreaper’s picture

Status: Needs review » Needs work

I forgot to update the status back to "Needs work".

ivan.vujovic’s picture

Assigned: ivan.vujovic » Unassigned
Status: Needs work » Needs review
FileSize
11.58 KB

Hello,
I'm uploading the patch which should fix the last point of this issue.
I added the non-batched versions of these methods (using the parameter $is_batched), but they are not used anywhere yet.
I see a possibility to actually use it in EntityShareAsyncWorker::processItem().

Grimreaper’s picture

Assigned: Unassigned » Grimreaper
Grimreaper’s picture

Assigned: Grimreaper » Unassigned
Status: Needs review » Needs work

Thanks @ivan.vujovic for the patch.

Really nice work!

Here is my review.

  1. +++ b/modules/entity_share_async/src/Plugin/QueueWorker/EntityShareAsyncWorker.php
    @@ -90,14 +89,10 @@ class EntityShareAsyncWorker extends QueueWorkerBase implements ContainerFactory
    +    $ids = $this->importService->importFromUrl($prepared_url);
    

    From the comment just above, now that importEntities has a $is_batched parameter, is it possible to use it directly?

  2. +++ b/modules/entity_share_client/src/Service/ImportService.php
    @@ -128,24 +128,29 @@ class ImportService implements ImportServiceInterface {
    +  public function importChannel(ImportContext $context, bool $is_batched = TRUE) {
    

    I am sorry. I think I was wrong about the usefullness of having the importChannel not batched. Or maybe you see a case where it can be usefull?

    As it may be used for a great amount of entities. Without batch, it is timeout or memory_limit errors ensured.

    Also, not sure that if not batched, only the first page imported will be appreciated.

    If you don't see any usage without batch of importChannel, please revert the changes in this method.

  3. +++ b/modules/entity_share_client/src/Service/ImportService.php
    @@ -234,6 +244,19 @@ class ImportService implements ImportServiceInterface {
    +  public function importFromUrl(string $url) {
    

    Nice!

    I think the importChannelPage method can be removed. This one seems better.

  4. +++ b/modules/entity_share_client/tests/src/Functional/EntityShareClientFunctionalTestBase.php
    @@ -676,12 +676,11 @@ abstract class EntityShareClientFunctionalTestBase extends BrowserTestBase {
    +    // Imports data from the remote URL.
    

    Nice to have adapted code in test classes!

ivan.vujovic’s picture

Status: Needs work » Needs review
FileSize
9.04 KB
7.34 KB

Hello @grimreaper,

I added the call to ImportEntities() in the Async module, the function itself needed a small adaptation to return the array of entities.

Also I removed the changes to importChannel(), I agree it is not so useful because we cannot guarantee the number of items will be small enough.
However, we have only an assumed limit of entities of 50 in ImportEntities() because in the BO it is impossible to select more, but otherwise I don't see we have this limit implemented in code. I don't think this is an issue for now, but maybe later if this method becomes more used, we should think about it.

Grimreaper’s picture

Thanks @ivan.vujovic for the updated patch!

One last comment. I can make the change myself, only need your opinion.

+++ b/modules/entity_share_client/src/Service/ImportService.php
@@ -119,27 +119,32 @@ class ImportService implements ImportServiceInterface {
+      return [];

+++ b/modules/entity_share_client/src/Service/ImportServiceInterface.php
@@ -20,8 +20,13 @@ interface ImportServiceInterface {
+   * @return array|null
+   *   The list of entity IDs imported keyed by UUIDs, or NULL if batched.

I think it is "void" and not "NULL".

And you are right about the limit. 50 is the default max of JSON:API. I know that there is a module or patch to be able to control it. But we will see when someone will create an issue.

Grimreaper’s picture

Assigned: Unassigned » ivan.vujovic
ivan.vujovic’s picture

Hi, adding the small correction of function's comment, it should indeed be void.

  • ivan.vujovic authored 6282eeb on 8.x-3.x
    Issue #3122246 by ivan.vujovic, Grimreaper: Be able to use...
Grimreaper’s picture

Assigned: Grimreaper » Unassigned
Status: Needs review » Fixed

Thanks! This is merged now.

Status: Fixed » Closed (fixed)

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