The website encountered an unexpected error. Please try again later.Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: '' for column 'gid' at row 1: INSERT INTO {node_access} (nid, langcode, fallback, realm, gid, grant_view, grant_update, grant_delete) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7), (:db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15); Array
(
[:db_insert_placeholder_0] => 46
[:db_insert_placeholder_1] => en
[:db_insert_placeholder_2] => 1
[:db_insert_placeholder_3] => content_access_roles
[:db_insert_placeholder_4] =>
[:db_insert_placeholder_5] => 1
[:db_insert_placeholder_6] => 1
[:db_insert_placeholder_7] => 0
[:db_insert_placeholder_8] => 46
[:db_insert_placeholder_9] => en
[:db_insert_placeholder_10] => 1
[:db_insert_placeholder_11] => all
[:db_insert_placeholder_12] => 0
[:db_insert_placeholder_13] => 1
[:db_insert_placeholder_14] => 0
[:db_insert_placeholder_15] => 0
)
in Drupal\node\NodeAccessControlHandler->writeGrants() (line 165 of core/modules/node/src/NodeAccessControlHandler.php).

content_access.module is using deprecated function writeGrants when trying to change grants on the node. Drupal.org recommends that it should be replaced with acquireGrants.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Pejka created an issue. See original summary.

Pejka’s picture

Pejka’s picture

Issue summary: View changes
Pejka’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: deprecated_function_writeGrants_throws_error-2971094-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

imclean’s picture

Acquiring grants is not the same as writing them. You'll need to add a write() after the aquire(). See #2473021: Deprecate NodeAccessControlHandlerInterface::writeGrants() for removal in Drupal 9.0.x

There are also 3 other instances:

src/Form/ContentAccessPageForm.php:    \Drupal::entityTypeManager()->getAccessControlHandler('node')->writeGrants($node);
src/Form/ContentAccessPageForm.php:    \Drupal::entityTypeManager()->getAccessControlHandler('node')->writeGrants($storage['node']);
src/Plugin/RulesAction/ActionCommonTrait.php:    \Drupal::entityTypeManager()->getAccessControlHandler('node')->writeGrants($node);
brooke_heaton’s picture

Priority: Normal » Major

This is now happening on Drupal 8.8.1 using content_access 8.x-1.0-alpha1 and it is a fatal error. Increasing Priority to Major.

brooke_heaton’s picture

Attached patch replaces deprecated writeGrants function with:

$grants = \Drupal::entityTypeManager()->getAccessControlHandler('node')->acquireGrants($node);
 \Drupal::service('node.grant_storage')->write($node, $grants);
brooke_heaton’s picture

Status: Needs work » Needs review
AkashKumar07’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch of #8 on my local. LGTM.
Thanks

imclean’s picture

+++ b/src/Form/ContentAccessPageForm.php
@@ -132,7 +132,8 @@ class ContentAccessPageForm extends FormBase {
+    $grants = \Drupal::entityTypeManager()->getAccessControlHandler('node')->acquireGrants($node);
+    \Drupal::service('node.grant_storage')->write($node, $grants);
     \Drupal::moduleHandler()->invokeAll('per_node', $settings);

These should be injected. \Drupal:: shouldn't be used in a class.

There is more deprecated code unrelated to this patch, such as drupal_set_message() and t().

+++ b/src/Form/ContentAccessPageForm.php
@@ -181,7 +182,9 @@ class ContentAccessPageForm extends FormBase {
     drupal_set_message(t('The permissions have been reseted to the content type defaults.'));
imclean’s picture

Status: Reviewed & tested by the community » Needs work
gisle’s picture

Assigned: brooke_heaton » Unassigned

Unassigning to let others try to finalize this one.

AkashKumar07’s picture

Assigned: Unassigned » AkashKumar07

I will work on this today.

AkashKumar07’s picture

Assigned: AkashKumar07 » Unassigned
MustangGB’s picture

MustangGB’s picture

  • MustangGB authored bdda64a on 8.x-1.x
    Issue #2971094 by MustangGB, Pejka, brooke_heaton: Deprecated function...
gisle’s picture

Status: Needs work » Fixed

Thank you for the patch, MustangGB. It has been committed to the latest development snapshot. It looks like this make the project compatible with Drupal 9, which is great!

As pointed out by imclean in comment #11, \Drupal:: shouldn't be used in a class. However, I prefer to close this one as fixed, and split that out into a separate issue.

Status: Fixed » Closed (fixed)

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