Problem/Motivation

VBO uses PrivateTempStore to store data such as the selected items for update.
However, sometimes the temp store name includes the view id and display id and some times it does not.
This can lead to inconsistent behaviour whereby sometimes the temp store data can be found and some times it cannot be found.
The result can be selected items are not cleared or items are selected for an action that have not actually been selected for the view.

For example:

  /**
   * Initialize the current view tempstore object.
   */
  protected function getTempstore($view_id = NULL, $display_id = NULL): PrivateTempStore {
    if (!isset($this->viewTempstore)) {
      $this->tempStoreName = 'views_bulk_operations_' . $view_id . '_' . $display_id;
      $this->viewTempstore = $this->tempStoreFactory->get($this->tempStoreName);
    }
    return $this->viewTempstore;
  }

If $view_id and $display_id are null, then the tempStoreName becomes views_bulk_operations__ whereas if the $view_id and $display_id parameters are passed, then they become part of the tempStoreName.

Steps to reproduce

The related bugs are known, but difficult to reproduce. It happens with certain workflows involving multiple VBO enabled Views or multiple operations / cancellations etc.. within a single VBO enabled View. This patch ensures the temp store name is consistent for a View.

Proposed resolution

Pass the $view_id and $display_id parameters to the related temp store functions implemented in ViewsBulkOperationsFormTrait

Remaining tasks

Update the function calls

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

davidwhthomas created an issue. See original summary.

davidwhthomas’s picture

Assigned: davidwhthomas » Unassigned
Status: Active » Needs review

MR attached for review, with thanks for the useful module.

davidwhthomas’s picture

Issue summary: View changes
astonvictor’s picture

Version: 4.3.x-dev » 4.4.x-dev
Status: Needs review » Reviewed & tested by the community

tested and it works for me

graber’s picture

Status: Reviewed & tested by the community » Needs work

I think it'll be enough to reinitialize tempstore in

  protected function getTempstore(?string $view_id = NULL, ?string $display_id = NULL): PrivateTempStore {
    if ($this->viewTempstore === NULL) {
      $this->tempStoreName = 'views_bulk_operations_' . $view_id . '_' . $display_id;
      $this->viewTempstore = $this->tempStoreFactory->get($this->tempStoreName);
    }
    return $this->viewTempstore;
  }

if $this->tempStoreName is different and throw an exception if $this->viewTempstore === NULL and $view_id or $display_id is NULL.

pminf’s picture

@graber Why should it be possible to access the tempstore without passing $view_id and $display_id? From my understanding both are necessary to make sure you get the correct tempstore. Therefor I would change the function to:

  /**
   * Initialize the current view tempstore object.
   */
  protected function getTempstore(string $view_id, string $display_id): PrivateTempStore {
    $tempStoreName = 'views_bulk_operations_' . $view_id . '_' . $display_id;
    if ($this->viewTempstore === NULL or $this->tempStoreName !== $tempStoreName) {
      $this->viewTempstore = $this->tempStoreFactory->get($this->tempStoreName);
    }
    return $this->viewTempstore;
  }
graber’s picture

It's just that those values are saved statically in a single request so you don't have to pass them all the time.

davidwhthomas’s picture

Status: Needs work » Closed (cannot reproduce)

I've just updated to version 4.4.8

I added some debug logging, performed various VBO operations, (incl. cancel, select all, etc..)
I was unable to produce a log where tempstore name was inconsistent.

My concern remains there might be some edge case where the `$view_id` or `$display_id` is NULL resulting in a shared tempstore name such as `views_bulk_operations__` However, I'm unable to replicate that issue.

I think ok to close this one for now, could always re-open if the issue persists.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

davidwhthomas changed the visibility of the branch 3572714-consistent-temp-store-name-v2 to hidden.

davidwhthomas’s picture

Status: Closed (cannot reproduce) » Needs work

Ah, I just understood Graber's comment in #6 in more detail,

I think it'll be enough to reinitialize tempstore in if $this->tempStoreName is different and throw an exception if $this->viewTempstore === NULL and $view_id or $display_id is NULL.

I can try adding that update to a new MR branch for this.

davidwhthomas changed the visibility of the branch 3572714-consistent-temp-store-name-v2 to active.

davidwhthomas’s picture

Assigned: Unassigned » davidwhthomas

davidwhthomas changed the visibility of the branch 3572714-consistent-temp-store-name to hidden.

davidwhthomas’s picture

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

MR update ready for review. It includes the suggestion from #6 and helps ensure no unexpected edge cases regarding the temp store name.

peri22’s picture

Status: Needs review » Reviewed & tested by the community

I checked MR !171 against the '4.4.x' HEAD. Every call to the tempstore helpers without IDs happens after the tempstore has already been initialized with both, so the new exception does not affect any existing code paths.
The pipeline is green. RTBC.

graber’s picture

Status: Reviewed & tested by the community » Fixed

Looks good, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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