Remove extra "item_" prefix when using getNidsOfType()

Created on 13 April 2024, 8 months ago
Updated 15 April 2024, 8 months ago

Problem/Motivation

I was testing out the batch operation and looking through the log, noticing that each row repeated the "item" string in the key, as so:

item_item_322: Updated Primary care - Pittsburgh VA Medical Center-University Drive. 
item_item_323: Updated Mental health care - Pittsburgh VA Medical Center-University Drive. 
item_item_348: Updated Emergency care - Pittsburgh VA Medical Center-University Drive. 
item_item_349: Updated Audiology and speech - Pittsburgh VA Medical Center-University Drive. 

Steps to reproduce

  1. Call the getNidsOfType() method in the gatherItemsToProcess() method of your script to populate an array of node ids.

Proposed resolution

  1. Update the getNidsOfType() to not call the stringify() function.
item_9084: Updated Geriatrics - George E. Wahlen Department of Veterans Affairs Medical Center.
item_9085: Updated Homeless Veteran care - George E. Wahlen Department of Veterans Affairs Medical Center.
item_9086: Updated LGBTQ+ Veteran care - George E. Wahlen Department of Veterans Affairs Medical Center.

Remaining tasks

  1. Push my local code changes.
  2. Get feedback from the co-maintainer.

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States skyriter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @skyriter
  • πŸ‡ΊπŸ‡ΈUnited States skyriter

    Another option would be to have getNidsOfType() accept a prefix argument, which could be the <bundle_type> or anything else.

  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Interesting. I think the source of the problem is that the caller of gatherItemsToProcess() is getItemsToProcess() and it stringifies the keys, and in your case, calling getNidsOfType() to feed gatherItemsToProcess() also calls stringify, so it is getting double stringified, which is not the intent.

    The simplest change would be to remove the call to stringify from getNidsOfType(). That makes things right by not double stringifying everything.

    I do like the more meaningful prefix though, but unfortunately there is no way to customize that in getItemsToProcess() so that everything could have good meaningful prefixes... unless we added a new method getTypeOfThingOperatedOn() to the BatchScriptInterface interface. Doing that would make it a required method that would need to be defined in all scripts. getTypeOfThingOperatedOn() would just need to return a string, like "facility_health_service", or xyz_paragraph or whatever the key happened to represent.

    I don't think we want it to be baked into getNidsOfType() like you are proposing for a few reasons:

    1. It is an expansion of concerns of the function. It is only supposed to get the nids, it does not always mean those nids are going to be the things operated on. Yes I may load all the nids, but what I am actually operating on are the terms that are used on all those nids, or paragraphs that are referenced (anything related to the nid, but not the nid itself.
    2. Similar to above, it makes it the function more opinionated than it should be.
    3. It is relying on double stringification, which I think we should not be doing.

    Recommended path:

    1. Remove the call to stringify from getNidsOfType()
    2. Add a method getTypeOfThingOperatedOn() that returns a string, to the BatchScriptInterface
    3. Add examples of uising getTypeOfThingOperatedOn() to the following"
      1. /src/cbo_scripts/TestDo10Things.php
      2. /src/cbo_scripts/TestDo10ThingsWithError.php
      3. /StarterScript.php.text
  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • πŸ‡ΊπŸ‡ΈUnited States skyriter
  • Status changed to Fixed 8 months ago
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    This is fantastic and simple. Thank you so much for finding and fixing.

  • Status changed to Fixed 8 months ago
Production build 0.71.5 2024