Support from Acquia helps fund testing for Drupal Acquia logo

Comments

osopolar created an issue. See original summary.

osopolar’s picture

Content Access settings might be set with the help of an Event Subscriber subscribing to the event MigrateEvents::POST_ROW_SAVE, see attached patch.

Example on how to set the Content Access Settings for operation view (node view) in a migrate template (see also the PHPDoc for MigrationEventSubscriber::migratePostRowSave):

destination:
  plugin: entity:node
process:
 'content_access_settings/view':
   source: content_visibility
   plugin: static_map
   map:
     public:
       - anonymous
       - authenticated
       - administrator
     private:
       - authenticated
       - administrator

The default settings don't have to be defined in the migration template, it would be just enough to define the customized settings, as above, where only the $content_access_settings['view'] is defined. In this example the settings for update or delete will be received from the content types default content access settings. If the per node settings matches the default settings the per node settings aren't saved to the database (as it's not necessary).

osopolar’s picture

Status: Active » Needs review
rwmanos’s picture

Status: Needs review » Needs work
PHP Fatal error:  Class 'Drupal\migrate\Event\MigrateEvents' not found in /8.5.4/modules/content_access/src/EventSubscriber/MigrationEventSubscriber.php on line 104

Patch in #2 needs some work to prevent those fatal errors.

osopolar’s picture

Status: Needs work » Needs review

Where did you define your migration? In a custom module? If so, may you please add the following to the modules .info.yml file:

dependencies:
  - drupal:migrate

It's just a guess based on what I found searching for your error message. It looks similar to the issue the commerce migrate module had, see: #2912247: Fatal error MigrateEvents not found.

Otherwise we may need to outsource the code in a custom sub-module with dependency on migrate – or the error is related to something else.

rwmanos’s picture

I assumed some migration dependency is missing but I'd expect this dependency to be added in the module by the patch itself.
The point is that this patch is for content_access and if you apply it, you are not able to enable the module any more.

In addition, I enabled all migration-related modules (i.e. migrate_upgrade migrate_plus migrate_tools migrate migrate_drupal) but I still cannot enable this module with this patch applied. The error is different this time:

exception 'ReflectionException' with message 'Class Drupal\content_access\EventSubscriber\MigrationEventSubscriber does not exist' in                                                               [error]
/drupal/8.5.4/core/lib/Drupal/Core/DependencyInjection/Compiler/RegisterEventSubscribersPass.php:30

I strongly believe this patch needs some work.

mahtab_alam’s picture

The last submitted patch, 7: 2880499-7.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 7: 2880499-7.patch, failed testing. View results

mahtab_alam’s picture

Status: Needs review » Needs work

The last submitted patch, 10: 2880499-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mahtab_alam’s picture

Issue summary: View changes

Patch #10 is working but it is not passing the test because of drupal coding standards.

osopolar’s picture

Adding the migrate dependencies directly to Content Access means that everybody who wants to use the Content Access module needs to enable the Migrate module, no mater if the site will use migration, or am I missing something?

It may be implemented in a submodule of Content Access (Content Access Migration) or in a custom module, which implements the migration if present. See also #5.

DamienMcKenna’s picture

Patch #10 also shouldn't specify @package Drupal\example_module\EventSubscriber.

DamienMcKenna’s picture

Also, is there a specific reason to rename MigrateEvents as MigrateEventsCore?

gisle’s picture

Patch fails to apply, and needs to be rerolled against HEAD. Also comments needs to be addressed.

pattersonc made their first commit to this issue’s fork.

pattersonc’s picture

Issue summary: View changes

See MR #20 as I added proper migration support for per node content_access records.

nsciacca made their first commit to this issue’s fork.

nsciacca’s picture

@pattersonc Thanks for your merge request - with a few tweaks I made it work well for my implementation. I pushed these changes:

  • Replaced "acpol_migrate" with "content_access" in class namespaces
  • Added $supportsRollback = TRUE and a rollback function calling "content_access_delete_per_node_settings"
  • Using migrate.lookup service to get the destination role id as mine had capitalizations and spaces that weren't working
  • Code standards checked
bisonbleu’s picture

Can someone please explain what the setup is to make this work? Thanks!

gisle’s picture

Version: 8.x-1.x-dev » 2.0.x-dev

This should go into the version compatible with Drupal 10.

sclsweb’s picture

I need to migrate a D7 site using Content Access to Drupal 10 and would love to see this added to the D10 version. I can't code it, but I would test if someone ported it.