Problem/Motivation

Running tests on PHP 8.2 I got

  34x: Creation of dynamic property Drupal\views\Entity\View::$_updated is deprecated
    13x in ViewsEntitySchemaSubscriberIntegrationTest::testVariousTableUpdates from Drupal\Tests\views\Kernel\EventSubscriber
    5x in ViewsEntitySchemaSubscriberIntegrationTest::testVariousTableUpdatesForRevisionView from Drupal\Tests\views\Kernel\EventSubscriber
    3x in ViewsEntitySchemaSubscriberIntegrationTest::testBaseTableRename from Drupal\Tests\views\Kernel\EventSubscriber
    3x in ViewsEntitySchemaSubscriberIntegrationTest::testDataTableRename from Drupal\Tests\views\Kernel\EventSubscriber
    3x in ViewsEntitySchemaSubscriberIntegrationTest::testRevisionDataTableRename from Drupal\Tests\views\Kernel\EventSubscriber

Steps to reproduce

Run ViewsEntitySchemaSubscriberIntegrationTest on PHP 8.2

Proposed resolution

Define the property

Remaining tasks

patch, review, commit

User interface changes

no

API changes

no

Data model changes

no

Release notes snippet

no

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

andypost created an issue. See original summary.

andypost’s picture

here's initial fix

andypost’s picture

Related issues: +#2052421: [META] Rename Views properties to core standards
FileSize
508 bytes
731 bytes

disable PHPCS for the property

Berdir’s picture

+++ b/core/modules/views/src/Entity/View.php
@@ -114,6 +114,18 @@ class View extends ConfigEntityBase implements ViewEntityInterface {
+  /**
+   * Runtime property used for config updates.
+   *
+   * phpcs:disable Drupal.Classes.PropertyDeclaration
+   * @todo Remove PHPCS override https://www.drupal.org/i/2052421.
+   *
+   * @var bool|null
+   *
+   * @see \Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber::onEntityTypeUpdate()
+   */
+  protected ?bool $_updated;

this is a pretty weird one.

Ironically, this property was created 6 years *after* the meta issue that's supposed to remove them which wasn't updated since 2016, which also makes sense as renaming them is an API change in many cases. And it actually explicitly uses get/set, wondering if it wasn't clear that this just sets a property with that name.

This is clearly an internal property that is just used in that single subscriber. Could we rewrite it to e.g. store the list of ids that should be resaved in a protected property of that subscriber:

$this->viewsToResave[$view->id] = TRUE/$view;

andypost’s picture

FileSize
5.51 KB
4.79 KB

Thank you! Great idea, less loops and indexed array prevents saving more then one time

andypost’s picture

BTW it could use WeakReference but then it can't be backported to 9.5

Berdir’s picture

+++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
@@ -208,17 +215,12 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
+    $this->viewsToSave = array_filter($this->viewsToSave, function (ViewEntityInterface $view) use ($entity_type) {
       try {
         // All changes done to the views here can be trusted and this might be
         // called during updates, when it is not safe to rely on configuration
         // containing valid schema. Trust the data and disable schema validation
         // and casting.
-        $view->set('_updated', NULL);
         $view->trustData()->save();
       }
       catch (\Exception $e) {
@@ -230,7 +232,8 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI

@@ -230,7 +232,8 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
           '%entity_type_id' => $entity_type->id(),
         ]);
       }
-    }
+      return FALSE;
+    });

that's a very creative use case for array_filter() :) should we just make this a plain old foreach and reset viewstoSave at the end?

andypost’s picture

fixed it))

andypost’s picture

+++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
@@ -83,6 +83,13 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
+  protected array $viewsToSave = [];

type needs to be removed to backport to 9.x

andypost’s picture

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

9.5 looks like an unrelated random fail:


1) Drupal\Tests\ckeditor5\FunctionalJavascript\MediaLibraryTest::testButton
Failed asserting that a NULL is not empty.

/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:119
/var/www/html/vendor/phpunit/phpunit/src/Framework/Constraint/LogicalNot.php:115
/var/www/html/core/modules/ckeditor5/tests/src/FunctionalJavascript/MediaLibraryTest.php:174
/var/www/html/vendor/phpunit/phpunit/src/Framework/TestResult.php:703

this is just one of what's going to be many necessary fixes, but I think this makes sense.

Disclaimer: I didn't write any code, but the patch is directly based on my suggestion in #4, so maybe someone else wants to +1 this.

catch’s picture

Status: Reviewed & tested by the community » Fixed
diff --git a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
index 9c008ef728..f8f5ea845b 100644
--- a/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
+++ b/core/modules/views/src/EventSubscriber/ViewsEntitySchemaSubscriber.php
@@ -84,7 +84,7 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
   protected $logger;
 
   /**
-   * Indexed array by view name that require to save.
+   * Array of views that need to be saved, indexed by view name.
    *
    * @var \Drupal\views\ViewEntityInterface[]
    */

Made this change on commit. Everything else looks great so committed/pushed to 10.1.x and cherry-picked back to 9.5.x

  • catch committed d9e654e on 10.0.x
    Issue #3295813 by andypost, Berdir: ViewsEntitySchemaSubscriber access...
  • catch committed 6af21de on 10.1.x
    Issue #3295813 by andypost, Berdir: ViewsEntitySchemaSubscriber access...
  • catch committed 54a3c30 on 9.5.x
    Issue #3295813 by andypost, Berdir: ViewsEntitySchemaSubscriber access...

Status: Fixed » Closed (fixed)

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