Commit 54a3c304 authored by catch's avatar catch
Browse files

Issue #3295813 by andypost, Berdir: ViewsEntitySchemaSubscriber access undefined property of View

(cherry picked from commit 6af21dee)
parent 27f361b1
......@@ -83,6 +83,13 @@ class ViewsEntitySchemaSubscriber implements EntityTypeListenerInterface, EventS
*/
protected $logger;
/**
* Array of views that need to be saved, indexed by view name.
*
* @var \Drupal\views\ViewEntityInterface[]
*/
protected $viewsToSave = [];
/**
* Constructs a ViewsEntitySchemaSubscriber.
*
......@@ -208,17 +215,12 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
}
}
// Filter the list of views that needs to be updated.
$views_to_update = array_filter($all_views, function (ViewEntityInterface $view) {
return $view->get('_updated') === TRUE;
});
foreach ($views_to_update as $view) {
foreach ($this->viewsToSave as $view) {
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) {
......@@ -231,6 +233,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI
]);
}
}
$this->viewsToSave = [];
}
/**
......@@ -300,14 +303,14 @@ protected function baseTableRename($all_views, $entity_type_id, $old_base_table,
foreach ($all_views as $view) {
if ($view->get('base_table') == $old_base_table) {
$view->set('base_table', $new_base_table);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_base_table, $new_base_table) {
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_base_table) {
$handler_config['table'] = $new_base_table;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
});
}
......@@ -328,14 +331,14 @@ protected function dataTableRename($all_views, $entity_type_id, $old_data_table,
foreach ($all_views as $view) {
if ($view->get('base_table') == $old_data_table) {
$view->set('base_table', $new_data_table);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
$this->processHandlers($all_views, function (&$handler_config, ViewEntityInterface $view) use ($entity_type_id, $old_data_table, $new_data_table) {
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id && $handler_config['table'] == $old_data_table) {
$handler_config['table'] = $new_data_table;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
});
}
......@@ -368,7 +371,7 @@ protected function dataTableAddition($all_views, EntityTypeInterface $entity_typ
// Move all fields which just exists on the data table.
if ($handler_config['table'] == $base_table && in_array($handler_config['entity_field'], $data_table_fields) && !in_array($handler_config['entity_field'], $base_table_fields)) {
$handler_config['table'] = $data_table;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
});
......@@ -392,7 +395,7 @@ protected function dataTableRemoval($all_views, $entity_type_id, $old_data_table
if (isset($handler_config['entity_type']) && $handler_config['entity_type'] == $entity_type_id) {
if ($handler_config['table'] == $old_data_table) {
$handler_config['table'] = $base_table;
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
}
});
......@@ -414,7 +417,7 @@ protected function revisionRemoval($all_views, EntityTypeInterface $original) {
if (in_array($view->get('base_table'), [$revision_base_table, $revision_data_table])) {
// Let's disable the views as we no longer support revisions.
$view->setStatus(FALSE);
$view->set('_updated', TRUE);
$this->viewsToSave[$view->id()] = $view;
}
// For any kind of field, let's rely on the broken handler functionality.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment