Issue for developing Poll migration.

It is currently for Drupal 7 and not universal because it relies on migration_lookup to look up values from d7_node_complete:poll and d7_user.

The migration involves multiple steps:

Migrations

1. Importing the configuration. Done in 4 steps :
- poll_field_storage_config to create the Field storage.
- poll_field_instance to attach the entity to the poll node.
- poll_field_instance_display for the default view mode display
- poll_field_instance_form_display for the form display.
2. Import poll choices. Done in the Poll_choice migration
3. Create a poll entity for each poll. Created in poll_question migration
4. Create a reference on the poll node to the poll question. Done in poll_reference migration
5. import the votes. Done in the poll_vote migration

Tests

For the tests, migrate fixtures are included. The test uses MigrateDrupal7TestBase which already imports the standard drupal7 fixtures from core. Only the additional fixtures for poll are needed to be added on top of that.

I followed the guide at https://www.drupal.org/docs/8/api/migrate-api/generating-database-fixtur... to create the fixtures:

1. I used existing fixtures to set up a drupal 7 website.
2. After importing the Drupal 7 fixtures I logged in and created the polls via the UI, with relevant options and then I voted on them via the UI.
2. I used the script to create a dump of the foixtures. Following this I deleted all previous data that is in the core drupal 7 fixtures, only leaving the additions.
3. This would work until there was a change to core fixtures which required bumping the nid and vid to greater than what was added to core, but causedAs this caused nid and vid collisions whenever new data was added to the coredrupal 7 fixtures
4. I manually modified the poll fixtures for the nid and vid to start at arbitrarily high numbers (101 on each).
5. I manually added a fixture to update system table and mark poll module as enabled.

CommentFileSizeAuthor
#135 interdiff.txt4.52 KBquietone
#124 poll-2638406-interdiff-122-124.txt7.09 KBnaheemsays
#124 poll-migration-2638406-124.patch33.22 KBnaheemsays
#122 interdiff_120-122.txt1019 bytesdeepak goyal
#122 2638406-122.patch33.12 KBdeepak goyal
#120 interdiff_117-120.txt1.4 KBdeepak goyal
#120 2638406-120.patch33.26 KBdeepak goyal
#117 poll-2638406-interdiff-115-117.txt1.04 KBnaheemsays
#117 poll-migration-2638406-117.patch33.32 KBnaheemsays
#115 poll-2638406-interdiff-113-115.txt867 bytesnaheemsays
#115 poll-migration-2638406-115.patch33.33 KBnaheemsays
#113 poll-2638406-interdiff-110-113.txt2.19 KBnaheemsays
#113 poll-migration-2638406-113.patch33.85 KBnaheemsays
#110 poll-2638406-interdiff-108-110.txt2.71 KBnaheemsays
#110 poll-migration-2638406-110.patch33.18 KBnaheemsays
#108 poll-2638406-interdiff-106-108.txt3.74 KBnaheemsays
#108 poll-migration-2638406-108.patch33.34 KBnaheemsays
#106 poll-2638406-interdiff-103-106.txt5.62 KBnaheemsays
#106 poll-migration-2638406-106.patch33.15 KBnaheemsays
#103 poll-2638406-interdiff-98-103.txt5.86 KBnaheemsays
#103 poll-migration-2638406-103.patch33 KBnaheemsays
#98 poll-2638406-interdiff-97-98.txt4.43 KBnaheemsays
#98 poll-migration-2638406-98.patch32.58 KBnaheemsays
#97 poll-2638406-interdiff-93-97.txt3.3 KBnaheemsays
#97 poll-migration-2638406-97.patch32.66 KBnaheemsays
#93 poll-2638406-interdiff-91-93.txt5.09 KBnaheemsays
#93 poll-migration-2638406-93.patch32.44 KBnaheemsays
#91 poll-migration-2638406-91.patch32.21 KBnaheemsays
#91 poll-2638406-interdiff-89-91.txt762 bytesnaheemsays
#89 poll-2638406-interdiff-87-89.txt2.35 KBnaheemsays
#89 poll-migration-2638406-89.patch32.18 KBnaheemsays
#87 poll-2638406-interdiff-86-87.txt7.21 KBnaheemsays
#87 poll-migration-2638406-87.patch32.18 KBnaheemsays
#86 poll-migration-2638406-86.patch34.27 KBnaheemsays
#86 poll-2638406-interdiff-85-86.txt618 bytesnaheemsays
#85 poll-migration-2638406-85.patch34.29 KBnaheemsays
#85 poll-2638406-interdiff-84-85.txt1.73 KBnaheemsays
#84 poll-migration-2638406-84.patch34.26 KBnaheemsays
#84 poll-2638406-interdiff-83-84.txt904 bytesnaheemsays
#83 poll-migration-2638406-83.patch34.26 KBnaheemsays
#83 poll-2638406-interdiff-82-83.txt1.47 KBnaheemsays
#82 poll-migration-2638406-82.patch34.32 KBnaheemsays
#82 poll-2638406-interdiff-79-82.txt3.84 KBnaheemsays
#81 poll-migration-2638406-81.patch34.31 KBnaheemsays
#81 poll-2638406-interdiff-79-81.txt3.83 KBnaheemsays
#79 poll-migration-2638406-79.patch34.06 KBnaheemsays
#79 poll-2638406-interdiff-77-79.txt1.79 KBnaheemsays
#77 poll-migration-2638406-77.patch33.93 KBnaheemsays
#77 poll-2638406-interdiff-74-77.txt2.47 KBnaheemsays
#76 poll-2638406-interdiff-71-74.txt442 bytesnaheemsays
#74 poll-migration-2638406-74.patch33.61 KBnaheemsays
#73 poll-migration-2638406-73.patch33.61 KBnaheemsays
#71 poll-migration-2638406-71.patch33.61 KBnaheemsays
#71 poll-2638406-interdiff-70-71.txt2.72 KBnaheemsays
#70 2638406-69.patch33.41 KBheddn
#70 interdiff_68-69.txt19.01 KBheddn
#68 poll-migration-2638406-68.1.patch33.51 KBnaheemsays
#68 poll-2638406-interdiff-67-68.1.txt1.16 KBnaheemsays
#67 poll-migration-2638406-68.patch33.32 KBnaheemsays
#67 poll-2638406-interdiff-67-68.txt803 bytesnaheemsays
#66 poll-migration-2638406-66.patch33.27 KBnaheemsays
#66 poll-2638406-interdiff-65-66.txt1.09 KBnaheemsays
#65 poll-migration-2638406-65.patch33.22 KBnaheemsays
#65 poll-2638406-interdiff-64-65.txt1.04 KBnaheemsays
#64 poll-migration-2638406-64.patch33.17 KBnaheemsays
#64 poll-2638406-interdiff-63-64.txt769 bytesnaheemsays
#63 poll-migration-2638406-63.patch33.13 KBnaheemsays
#63 poll-2638406-interdiff-62-63.txt6.48 KBnaheemsays
#62 poll-migration-2638406-62.patch32.69 KBnaheemsays
#62 poll-2638406-interdiff-61-62.txt1.05 KBnaheemsays
#61 poll-migration-2638406-61.patch32.7 KBnaheemsays
#61 poll-2638406-interdiff-60-61.txt807 bytesnaheemsays
#60 poll-migration-2638406-60.patch32.62 KBnaheemsays
#60 poll-2638406-interdiff-59-60.txt853 bytesnaheemsays
#59 poll-migration-2638406-59.patch32.66 KBnaheemsays
#59 poll-2638406-interdiff-58-59.txt5.26 KBnaheemsays
#58 poll-migration-2638406-58.patch32.13 KBnaheemsays
#58 poll-2638406-interdiff-57-58.txt3.8 KBnaheemsays
#57 poll-migration-2638406-57.patch30.21 KBnaheemsays
#57 poll-2638406-interdiff-56-57.txt2.26 KBnaheemsays
#56 poll-migration-2638406-56.patch30.2 KBnaheemsays
#56 poll-2638406-interdiff-55-56.txt5.37 KBnaheemsays
#55 poll-migration-2638406-55.patch30.29 KBnaheemsays
#55 poll-2638406-interdiff-54-55.txt6.91 KBnaheemsays
#54 poll-migration-2638406-54.patch28.41 KBnaheemsays
#54 poll-2638406-interdiff-53-54.txt3.05 KBnaheemsays
#53 poll-migration-2638406-53.patch27.59 KBnaheemsays
#53 poll-2638406-interdiff-52-53.txt3.46 KBnaheemsays
#52 poll-migration-2638406-52.patch27.03 KBnaheemsays
#52 poll-2638406-interdiff-47-52.txt14.09 KBnaheemsays
#51 poll-2638406-interdiff-47-51.txt9.05 KBnaheemsays
#51 poll-migration-2638406-51.patch24.38 KBnaheemsays
#47 poll-migration-2638406-47.patch15.32 KBnaheemsays
#47 poll-2638406-interdiff-44-47.txt984 bytesnaheemsays
#46 drupal7.php_.txt8.42 KBnaheemsays
#44 poll-2638406-interdiff-43-44.txt904 bytesnaheemsays
#44 poll-migration-2638406-44.patch15.3 KBnaheemsays
#43 poll-2638406-interdiff-42-43.txt419 bytesnaheemsays
#43 poll-migration-2638406-43.patch15.25 KBnaheemsays
#42 poll-migration-2638406-42.patch15.33 KBnaheemsays
#41 poll-2638406-interdiff-39-41.txt4.92 KBnaheemsays
#41 poll-migration-2638406-41.patch4.92 KBnaheemsays
#39 poll-migration-2638406-39.patch12.07 KBnaheemsays
#39 poll-2638406-interdiff-32-39.txt7.37 KBnaheemsays
#32 poll-migration-2638406-32.patch10.86 KBnaheemsays
#32 poll-2638406-interdiff-31-32.txt5.67 KBnaheemsays
#31 poll-migration-2638406-31.patch11.19 KBnaheemsays
#31 poll-2638406-interdiff-26-31.txt1.5 KBnaheemsays
#26 pollmigration-26.patch11.25 KBnaheemsays
#26 interdiff-20-25.txt2.75 KBnaheemsays
#24 interdiff-23-24.txt326 bytesnaheemsays
#24 pollmigration-24.patch0 bytesnaheemsays
#23 interdiff-20-23.txt2.56 KBnaheemsays
#23 pollmigration-23.patch2.56 KBnaheemsays
#20 interdiff-16-20.txt13.03 KBnaheemsays
#20 pollmigration.patch11.22 KBnaheemsays
#16 pollmigration.patch11.65 KBnaheemsays
#15 pollmigration.patch11.66 KBnaheemsays
#14 pollmigration.patch9.78 KBnaheemsays
#13 pollmigration.patch9.65 KBnaheemsays
#12 pollmigration.patch9.55 KBnaheemsays
#10 pollmigration.patch8.99 KBnaheemsays
#9 pollmigration.patch7.87 KBnaheemsays
#8 pollmigration.patch7.61 KBnaheemsays
#7 pollmigration.patch5.1 KBnaheemsays
#6 poll--migrate-wip.patch5.63 KBnaheemsays
#5 mypatch.patch5.67 KBnaheemsays

Issue fork poll-2638406

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

nbz created an issue. See original summary.

berdir’s picture

Not sure what you mean with add to any content type? It's a separate entity type, has nothing to do with content types (except you could reference them with a entity reference field).

No plans yet, but any work on this is welcome.

naheemsays’s picture

Are there any guides/tutorials on writing destination plugins? All the guides/tutorials that I have come across seem to be limited to the node/taxonomy/file cases where plugins already exist.

berdir’s picture

Have a look at \Drupal\migrate\Plugin\migrate\destination\DestinationBase and any of its subclasses, for example a simple case like \Drupal\ban\Plugin\migrate\destination\BlockedIP.

Basically the import() method is called with the row as provided by the source and then mapped by the configuration/definition in the yml file, and then you take that and save it.

naheemsays’s picture

StatusFileSize
new5.67 KB

I have attached a not working partial not working migration for the poll question and choices.

I cant get the migrations to show up in Migrate drupal UI and my local drush is playing up, so I dont know how many errors there are. (Reading the docs has been a frustrating experience)

My thinking has broken this down to 4 steps in migratio

1. Migrate poll without options
2. Migrate poll options
3. Migrate stored field data
4. Migrate an entity reference of the poll to the poll node

I have attempted the first 2.

naheemsays’s picture

StatusFileSize
new5.63 KB

slightly updated patch from before if anyone wants to look at it - I havent done much since then, but probably a better starting point to improve on.

naheemsays’s picture

StatusFileSize
new5.1 KB

Updated patch:

1. Migration of Poll Question works.
2. Migration of poll choices does not run and drush gives the following error: "Migration pollchoice did not meet the requirements. [error]"

I cannot seem to get anything more verbose (--debug has been useless) to show why or what requirements are not met.

I have not included my hacky attempts to migrate the vote data - I havent got my head around the data model (votes are not a field?) and I cannot test what I have until migration of poll choices is successfull.

Previous patches had preparerow functions in the source plugin such as the following, but this did not seem to work so using addfield in the query of both plugins instead:

  public function prepareRow(Row $row) {

    $nid = getSourceProperty('nid');
    $row->setSourceProperty('pid', $nid);

    return parent::prepareRow($row);
  }

Any pointers at fixing the migration for poll choices will be much appreciated.

naheemsays’s picture

StatusFileSize
new7.61 KB

Updated patch:

0. No poll entity reference field is created on the original node poll
1. Poll Questions migrated but no reference is created to the poll node.
2. Poll choices are migrated but no reference is created to the poll
3. poll votes migration currently fails.

I need to figure out how to update existing node types during migration to add more fields and how to create references to the newly created entities on existing entities. Any pointers will be welcome.

naheemsays’s picture

StatusFileSize
new7.87 KB

Slight progress:

0. No poll entity reference field is created on the original node poll
1. Poll Questions migrated but no reference is created to the poll node.
2. Poll choices are migrated
2.1. Reference is created to the poll, but current code overwrites itself so only last poll choice reference remains afterwards.
3. poll votes migration currently fails.

I have simplified some of the plugins from prevoius patches too.

naheemsays’s picture

Issue summary: View changes
StatusFileSize
new8.99 KB

Updated code.

Currently:

1. To test, I need to manually create a poll_field entity reference on the poll node. Need to create a migration to add a poll entity reference to the poll node type.
2. The migration to add the reference currently resaves the whole node with a new id. I need to fix that.
3. Creating references to choices on the poll deletes the previously saved choice leaving only one choice per poll. Need to fix.

naheemsays’s picture

Title: Migrate to Drupal 8? » Poll migrate support
Status: Active » Needs review

Set to needs review because I need pointers on the two problems:

1. How to create additional field on an existing node type
2. How to make the migration pollchoice_reference not overwrite the previously saved entry.

naheemsays’s picture

StatusFileSize
new9.55 KB

New Patch.

Before carrying out poll migration, need to manually create field_poll entity reference field on the poll node type. I have asked a question on the forums for ideas on how to do this here: https://www.drupal.org/forum/support/module-development-and-code-questio...

Other than the configuration issue, polls are created correctly with correct options and votes and references to the polls are correctly added to the poll nodes.

naheemsays’s picture

StatusFileSize
new9.65 KB

Slightly updated patch.

Other than the manual step, the rest should work well for Drupal 7 anyway as one of the migrations references another Drupal 7 specific reference.

naheemsays’s picture

StatusFileSize
new9.78 KB

Other than manual step, current patch seems to be fully working.

I have not figured out yet how to create a migration which would add an entity reference to the poll node type but it seems that almost everyone else does that step manually.

naheemsays’s picture

StatusFileSize
new11.66 KB

OK, I have found some documentation in \Drupal\migrate\Plugin\migrate\destination\EntityFieldStorageConfig and \Drupal\migrate\Plugin\migrate\destination\EntityFieldInstance

With Latest patch - field storage is created, but the field instance is not with the following error in the logs:

Source ID : Attempt to create a field without a field_name. ( ... \core\modules\field\src\Entity\FieldConfig.php:112)

Once that above error has been fixed, the patch should be fully complete

naheemsays’s picture

Issue summary: View changes
StatusFileSize
new11.65 KB

The error turned to be an indentation problem which meant the process section of the migration was not being processed.

Full migration from Drupal 7. Marking as RTBC.

There were no database changes between Drupal 6 and Drupal 7 that would impact migration, but as I have not tested from Drupal 6, the tags limit it to Drupal 7 only. Extending it further and potentially adding tests to make sure migration does not break in the future following potential database changes can be done in followups if needed.

naheemsays’s picture

Status: Needs review » Reviewed & tested by the community

Moving to RTBC.

heddn’s picture

Status: Reviewed & tested by the community » Needs work

Mostly just nits. The main thing though to consider is the naming (which is always hard). The real work of this patch is looking nice. Great work.

  1. +++ b/migrations/poll_entityfieldinstance.yml
    @@ -0,0 +1,25 @@
    +id: poll_entityfieldinstance
    
    +++ b/migrations/poll_entityfieldstorageconfig.yml
    @@ -0,0 +1,30 @@
    +id: poll_entityfieldstorageconfig
    
    +++ b/migrations/pollchoice.yml
    @@ -0,0 +1,18 @@
    +  plugin: pollchoice
    
    +++ b/migrations/pollquestion.yml
    @@ -0,0 +1,30 @@
    +id: pollquestion
    
    +++ b/src/Plugin/migrate/source/PollChoice.php
    @@ -0,0 +1,75 @@
    + *   id = "pollchoice",
    
    +++ b/src/Plugin/migrate/source/PollVotes.php
    @@ -0,0 +1,62 @@
    + *   id = "pollvotes",
    

    Nit: we tend to use words separated by an underscore in the naming. And we don't include the word entity, as everything in Drupal is an entity and has no meaning. So split the words with an underscore and drop the entity part.

  2. +++ b/migrations/poll_entityfieldinstance.yml
    @@ -0,0 +1,25 @@
    +  plugin: empty
    
    +++ b/migrations/poll_entityfieldstorageconfig.yml
    @@ -0,0 +1,30 @@
    +  plugin: empty
    

    'embedded_data' is a better source. Empty was used in the past in core, but core doesn't even use it these days. It ends up being the same result, but is more semantic and less risk of having the source plugin deprecated.

  3. +++ b/migrations/poll_entityfieldinstance.yml
    @@ -0,0 +1,25 @@
    \ No newline at end of file
    
    +++ b/migrations/poll_reference.yml
    @@ -0,0 +1,30 @@
    +  field_poll/target_id:    ¶
    ...
    \ No newline at end of file
    
    +++ b/migrations/pollchoice.yml
    @@ -0,0 +1,18 @@
    +  langcode:    ¶
    ...
    \ No newline at end of file
    
    +++ b/migrations/pollquestion.yml
    @@ -0,0 +1,30 @@
    +  langcode:    ¶
    ...
    \ No newline at end of file
    
    +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,134 @@
    +		'uid',
    ...
    +	$query->innerJoin('node', 'n', 'n.vid = nr.vid');
    ...
    +	$query->orderBy('nid', 'ASC');
    ...
    +	  'vid' => $this->t('revision ID'),
    ...
    +  ¶
    ...
    +	$ids['pid']['type'] = 'integer';
    +	$ids['vid']['type'] = 'integer';
    ...
    +  ¶
    ...
    +    ¶
    +	$choices = [];
    ...
    +		 'nid',
    ...
    +	   ->condition('pc.nid', $row->getSourceProperty('pid'), '=')
    +	   ->orderBy('weight', 'ASC')
    ...
    +		$choices[] = [
    ...
    + ¶
    ...
    + ¶
    ...
    \ No newline at end of file
    
    +++ b/src/Plugin/migrate/source/PollChoice.php
    @@ -0,0 +1,75 @@
    +		'nid',
    ...
    +	$query->orderBy('chid', 'ASC');
    +    ¶
    +	return $query;
    ...
    +	  'nid' => $this->t('Node ID'),
    +	  'pid' => $this->t('Poll Node ID'),
    +	  'chtext' => $this->t('Text of the Poll option'),
    +	  'chid' => $this->t('Unique identifier of a poll choice.'),
    +	  'weight' => $this->t('The sort order of this choice among all choices')
    ...
    +  ¶
    ...
    +	$ids['chid']['type'] = 'integer';
    ...
    +	$row->setSourceProperty('deleted', 0);
    + ¶
    ...
    +  ¶
    ...
    \ No newline at end of file
    
    +++ b/src/Plugin/migrate/source/PollVotes.php
    @@ -0,0 +1,62 @@
    +	$query->orderBy('chid', 'ASC');
    +	
    ...
    +	  'chid' => $this->t('The user\'s vote for this poll'),
    +	  'uid' => $this->t('user ID for authenticated user'),
    +	  'pid' => $this->t('user poll ID that this vote has been cast on'),
    +	  'hostname' => $this->t('The ip address this vote is from.'),
    +	  'timestamp' => $this->t('The timestamp of the vote creation.')
    ...
    +  ¶
    ...
    +	$ids['chid']['type'] = 'integer';
    +	$ids['timestamp']['type'] = 'integer';
    ...
    \ No newline at end of file
    

    Lots of whitespace issues. Tabs and extra whitespace. And no new lines.

  4. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,134 @@
    +  public function prepareRow(Row $row) {
    +    // Always include this fragment at the beginning of every prepareRow()
    +    // implementation, so parent classes can ignore rows.
    

    Don't include this. It isn't needed as there is no override of the parent.

  5. +++ b/src/Plugin/migrate/source/PollChoice.php
    @@ -0,0 +1,75 @@
    +    $row->setSourceProperty('bundle', 'poll');
    +	$row->setSourceProperty('deleted', 0);
    

    This isn't needed. Use a 'default_value' plugin in the process or just sent these values with constants in the yaml. It is far easier for someone to alter a yaml then extend and modify a php class file if they want to use some different value.

heddn’s picture

Also, another though. Ideally, the fields and field data could be discovered by a field plugin. Is that not possible here? I feel like it could. Then the code here would /drastically/ simplify. And we'd just need a field plugin for the poll entity reference. See https://api.drupal.org/api/drupal/core%21modules%21migrate_drupal%21src%... as an example of what I mean.

  1. +++ b/migrations/pollvote.yml
    @@ -0,0 +1,40 @@
    +  plugin: table
    +  # Table which is installed in hook schema.
    +  table_name: poll_vote
    +  id_fields:
    

    Really, the destination in D8 is still a table and not an entity?

  2. +++ b/migrations/pollvote.yml
    @@ -0,0 +1,40 @@
    +dependencies:
    +  - migrate_plus
    

    I don't see any requirements in composer.json or .info.yml for this module? That means this migration will /fail/ for those who don't have that module installed.

  3. Also, please ping me in slack #migration for assistance if any of these comments seem too dense and need further clarification.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new11.22 KB
new13.03 KB

Thanks for the review!

#18-1 - this should be fixed.
#18-2 - this should be fixed.
#18-3 - this should be fixed. Do you have a special tool that can find these coding fixes?
#18-4 - I assume you did not mean the code comment only, but the whole section. I deleted:

-    // Always include this fragment at the beginning of every prepareRow()
-    // implementation, so parent classes can ignore rows.
-    if (parent::prepareRow($row) === FALSE) {
-      return FALSE;
-    }

#18-5 - fixed

#19-0 - I looked at this approach a long time ago, I struggled to understand how to use it at the time. I might have another look.
#19-1 - AFAIK votes are fields in the Drupal 8 version of the poll module, but using the tableplugin seemed the simplest path
#19-2 - adding the dependency in the composer or the info.yml file would make migrate_plus a necessity for everyday operation, when it is only used for the migration.

heddn’s picture

Status: Needs review » Needs work

This is shaping up nicely.

  1. +++ b/migrations/poll_choice.yml
    @@ -0,0 +1,24 @@
    +id: poll_choice
    +label: Poll choices
    ...
    +  plugin: poll_choice
    

    Plural or singular?

  2. +++ b/migrations/poll_field_storage_config.yml
    @@ -0,0 +1,35 @@
    +label: Poll entity reference field Storage
    

    Nit: why is storage caps?

  3. +++ b/migrations/poll_question.yml
    @@ -0,0 +1,30 @@
    +id: poll_question
    +label: Poll questions
    

    One is singular, the other is plural?

  4. +++ b/migrations/poll_reference.yml
    @@ -0,0 +1,30 @@
    +id: poll_reference
    +label: Entity Reference for poll nodes to polls
    
    +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,129 @@
    +class Poll extends SqlBase {
    

    I now I'm repeating myself, but this isn't necessary. There is already a node migration for all of this. I think a field plugin is going to be a much better solution. This is going to only work in very specific situations where someone didn't manually create their own differently named reference fields for polls. Use a field migration and this will just get picked up using the normal migrate_drupal processes. For any and all poll reference fields.

  5. +++ b/migrations/poll_vote.yml
    @@ -0,0 +1,40 @@
    +id: poll_vote
    +label: Poll votes
    ...
    +  plugin: poll_votes
    

    Singular or plural?

  6. +++ b/migrations/poll_vote.yml
    @@ -0,0 +1,40 @@
    +destination:
    +  plugin: table
    

    I think you will be much happier to use an entity destination. Otherwise folks won't have that module installed and this migration will fail and cause odd errors for folks. We can't require the use of that module, so just use an entity destination.

heddn’s picture

OK, let's drop my mentions of field migrations. I'm embarrassed to say I hadn't done enough homework on poll.module. There aren't any fields to migrate. The implementation of poll in D7 core was pretty simplistic and used hook_field_extra_fields and assumed that all polls where attached to a node type of 'poll'. So, ignore #21.4

One thing you will need to do. You'll need to extend the embedded source plugins for poll_field_instance.yml and poll_field_storage_config.yml. And add a source_module='poll' in those source plugins. Otherwise this will cause issues for folks who enable this module in D8 and don't have a D7 site with poll enabled. We only want those migrations discovered if the source site also had the poll module installed.

naheemsays’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.56 KB
new2.56 KB

#21.1 - fixed. I have decided to go for the singular.
#21.2 - fixed.
#21.3 - fixed.
#21.4 - ignored as per your following comment.
#21.5 - fixed along with the src plugin.

#21.6 - I dont understand what you mean here. In Drupal 7 the votes were simply stored in a table. In Drupal 8 they are a field to an entity (poll_choice). Can this be done or did you mean ignore this aswell in the following comment?

#22 - added the source_module: poll to the two migrations

naheemsays’s picture

StatusFileSize
new0 bytes
new326 bytes

A small error that was not fixed in previous patch

heddn’s picture

Status: Needs review » Needs work

#21.6 - I dont understand what you mean here. In Drupal 7 the votes were simply stored in a table. In Drupal 8 they are a field to an entity (poll_choice). Can this be done or did you mean ignore this aswell in the following comment?

Just list the entity name and drupal's migrate api will store the values. I don't recommend using table in D8 for an entity destination.

Plus those last patches looks a little small?

naheemsays’s picture

StatusFileSize
new2.75 KB
new11.25 KB

This should be the full patch and interdiff from comment 20.

Still to address #25

naheemsays’s picture

Just list the entity name and drupal's migrate api will store the values. I don't recommend using table in D8 for an entity destination.

From the code I cannot see the vote is being attached to any entity. I had expected it to be a field on the poll_choice entity. Any pointers of where to look will be helpful.

heddn’s picture

It might be a little tricky from looking at https://cgit.drupalcode.org/poll/tree/src/PollVoteStorage.php and https://cgit.drupalcode.org/poll/tree/src/Entity/Poll.php#n412. You might even need to create a custom destination. But you should be able to pass choices to poll and save them.

naheemsays’s picture

Choices (well, their references) are already passed to poll (the question). What is remaining is the votes which are currently copied over via the table plugin.

For the votes I see 2 options if we do not go by what we have right now:

1. A custom destination. But this will probably be a simplified version of the table plugin.
2. Change the poll vote to an entity and use the standard entity plugin destination method.

If 2. is chosen, should it use the same table as now or should it have a new name?

naheemsays’s picture

Before re-rolling this my understanding is that we need to get #3042995: Convert votes into entities in.

Any comments on the patch over there is welcome.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB
new11.19 KB
naheemsays’s picture

StatusFileSize
new5.67 KB
new10.86 KB

Code sniffer fixes only.

Patch works well.

The only issue is that the entity reference instances added to the node poll is disabled in the node form and not in the correct position for display. There is no content loss, but a user will need to manually update these settings.

heddn’s picture

To get the weighting and activation of those fields to function, see PerComponentEntityFormDisplay and PerComponentEntityDisplay. Both of these have really great examples in their doxygen.

dippers’s picture

I had two issues in the migrate source Poll.php.

1. My migration was only finding 2 out of 101 polls from my D7 site. The problem seems to be due to the join statement at line 50 for joining poll to node where it uses n.vid = p.nid. I think this should be n.nid = p.nid as we want to match node ids NOT revision id to node id.

2. When running upgrade_d7_poll_question I was seeing SQL errors due to non-existent column 'pid'. It seems standard SQL does not support column aliases in ON clauses. Instead in getIds() I used

    $ids['nid'] = ['type' => 'integer', 'alias' => 'n'];
    $ids['vid'] = ['type' => 'integer', 'alias' => 'n'];

Which avoids using the 'pid' alias in the ON clause.

dippers’s picture

I also found that the poll_reference migration config was not working. I modified it to:

id: poll_reference
label: Entity Reference for poll nodes to polls
migration_tags:
  - Drupal 7
source:
  plugin: poll
process:
  field_poll/target_id:
    plugin: migration_lookup
    migration: poll_question
    source: 
      - nid
      - vid
  nid:
    plugin: migration_lookup
    migration: d7_node:poll
    source: nid
destination:
  plugin: entity:node
  default_bundle: poll
  overwrite_properties:
    - field_poll
migration_dependencies:
  required:
    - poll_question
    - poll_field_instance

The poll_question migration lookup required two keys, nid and vid. You cannot use the d7_node:poll table to lookup the destination vid as it is not stored. There is no need to change the 'changed' or 'title' fields as this migration should just be updating the poll reference field.

naheemsays’s picture

@Dippers - do you know where the issue was - was it with the creation of the polls (ie in teh database were all the polls being imported) or with the attachment to the node?

We do need to take the vid into account otherwise AFAIK, in nodes with multiple revisions, only one revision will have a poll attached. Maybe the same logic doesnt apply for the poll_question and the poll_reference migrations though.

dippers’s picture

If you do want to reference all revisions then you need to lookup the revision id in the d7_node_revision:poll migration:

  vid:
    plugin: migration_lookup
    migration: d7_node_revision:poll
    source: vid

This makes the d7_node_revision:poll migration a dependency. We generally do not migrate node revisions and having a revision dependency might be a drawback in the case when you just want to migrate the current nodes/polls. It would probably be more useful to have a poll_reference migration and a poll_reference_revision migration to deal with the revisions separately.

There is the wider question of dealing with revisions of polls in D8. As it stands it appears that multiple revisions of D7 poll nodes will create multiple poll entities in D8 - is this the desired effect?

naheemsays’s picture

Status: Needs review » Needs work
naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new7.37 KB
new12.07 KB

Updated patch.

For some reason I am getting a bogus extra poll node being created with a title which is a random string of letters. I cant track down why. but on my new test setup I did have one poll node which had a revision to it to test how the migration handled them.

Other than that it works.

Any help in tracking down the bug(s) much appreciated.

Before this can be finished, we need a resolution on #3042995: Convert votes into entities or agreement/guidance for an alternative form of destination plugin for poll votes that will be acceptable.

(My comment in post 36 was wrong - we were not adding the poll to all the revisions anyway)

naheemsays’s picture

Adding for retest - nothing to do with this patch, just checking if the module works with php 7.3.

naheemsays’s picture

StatusFileSize
new4.92 KB
new4.92 KB

While reading Migrate related issues, I came across reference to the PathAlias migrate destination.

Using a similar approach, I have gotten the poll_vote migration to (mostly) work.

The only two issues I can see that are remaining are:

1. A bogus extra node is created during the migration. It seems to coincide with having 1 extra revision on my test database. I cannot seem to figure out why this is happening.
2. The poll_vote migrate mapping is not saved. The log shows the following message: "Could not save to map table due to missing destination id values"

naheemsays’s picture

StatusFileSize
new15.33 KB

Git-foo fail. Correct patch.

naheemsays’s picture

StatusFileSize
new15.25 KB
new419 bytes

The fix for the poll_reference creating nodes was in comment 35 - thanks @Dippers.

The only remaining fix is figuring out why the migrate map for poll_vote is not being saved.

naheemsays’s picture

StatusFileSize
new15.3 KB
new904 bytes

Code style fixes (interdiff includes diff in comment 43)

naheemsays’s picture

Beyond the remaining bug with poll votes note being added to the migrate map table, I think this module should have migrate tests.

I have created fixtures following the guide at https://www.drupal.org/docs/8/api/migrate-api/generating-database-fixtur... however the tests page at https://www.drupal.org/docs/8/api/migrate-api/migration-tests-in-drupal-8 is not too useful.

Any pointers/guides?

naheemsays’s picture

StatusFileSize
new8.42 KB

Relevant fixtures for anyone interested in working on tests.

naheemsays’s picture

Issue summary: View changes
StatusFileSize
new984 bytes
new15.32 KB

Migrate Map should now also be working.

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Seems like one missing piece at this point is tests.

naheemsays’s picture

Is there a good link/guide that I can follow for relevant tests?

heddn’s picture

naheemsays’s picture

StatusFileSize
new24.38 KB
new9.05 KB

Updated patch.

I do not expect it to work - I cannot seem to get my head around testing...

I tried a migration with the patch on comment 47 on my test site hundreds of polls and thousands of choices/votes.

At some point during the migration the choices seem to be imported/attached twice to the poll (I havent checked which it is yet.) and at that same point it seems the votes are no longer attached to the choice.

For a small number of polls and votes the code seems to work well.

naheemsays’s picture

StatusFileSize
new14.09 KB
new27.03 KB

Now with the correct patches.

naheemsays’s picture

StatusFileSize
new3.46 KB
new27.59 KB

Small cleanups - mostly coding style and notes for what needs testing.

Still not functional.

naheemsays’s picture

StatusFileSize
new3.05 KB
new28.41 KB

Testing patch

naheemsays’s picture

StatusFileSize
new6.91 KB
new30.29 KB

More tests. Fixtures probably still dont load.

naheemsays’s picture

StatusFileSize
new5.37 KB
new30.2 KB

more updates. Hopefully the fixture will be found now.

(I cannot seem to figure out the local testing environment - the failures are cryptic with no details.)

naheemsays’s picture

StatusFileSize
new2.26 KB
new30.21 KB

Updating fixtures to account for new additions in drupal 8.9.

Is there any way to automate these values? I can see having to update the fixtures to keep up new with core tests being troublesome.

naheemsays’s picture

StatusFileSize
new3.8 KB
new32.13 KB

Most tests are in place now. Just need to make it work.

naheemsays’s picture

StatusFileSize
new5.26 KB
new32.66 KB

more improvements and fixes.

naheemsays’s picture

StatusFileSize
new853 bytes
new32.62 KB

Fix errors from last test

naheemsays’s picture

StatusFileSize
new807 bytes
new32.7 KB

Going further down the rabbit hole. Shouldnt these be done by MigrateDrupal7TestBase?

naheemsays’s picture

StatusFileSize
new1.05 KB
new32.69 KB

lets try this

naheemsays’s picture

StatusFileSize
new6.48 KB
new33.13 KB
naheemsays’s picture

StatusFileSize
new769 bytes
new33.17 KB

One more time - enable the text module.

naheemsays’s picture

StatusFileSize
new1.04 KB
new33.22 KB

Adding comment module to be enabled. Might also need to load the schema specifically.

naheemsays’s picture

StatusFileSize
new1.09 KB
new33.27 KB

Add image module to test setup.

naheemsays’s picture

StatusFileSize
new803 bytes
new33.32 KB

Add telephone module.

naheemsays’s picture

StatusFileSize
new1.16 KB
new33.51 KB
heddn’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Here's an attempt to fix up some of the tests. They now run, although fail and the errors seem to be legit. All the time I had for today though.

Also, sorry for the interdiff noise. The test name changed from a folder of Migrate to migrate.

heddn’s picture

StatusFileSize
new19.01 KB
new33.41 KB
naheemsays’s picture

StatusFileSize
new2.72 KB
new33.61 KB

Thanks! I was starting to pull my hair out over getting the tests to run.

That above test doest seem to have run all the tests - the number of passes match before this patch.

Having a look at the interdiff, the nodes being tested have been changed to 1, 2 and 3. The fixtures have the nodes with nids 11, 12 and 13. I am reverting that change.

naheemsays’s picture

Another question - core has the tess/src/Kernel/Migrate folder with a capital M. Are contrib meant to be different in this case?

naheemsays’s picture

StatusFileSize
new33.61 KB

Testing to see if tests are run if the tests folder name is reverted to Migrate with a capital M.

EDIT - I accidentally changed the namespace to migrate without a capital m in this patch...

naheemsays’s picture

StatusFileSize
new33.61 KB

Lets test having them both with lower case m.

Status: Needs review » Needs work

The last submitted patch, 74: poll-migration-2638406-74.patch, failed testing. View results

naheemsays’s picture

StatusFileSize
new442 bytes

Finally the tests/failures are showing!

interdiff from comment 71 - 74 attached.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new2.47 KB
new33.93 KB

Hopefully this works better.

Status: Needs review » Needs work

The last submitted patch, 77: poll-migration-2638406-77.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 KB
new34.06 KB

Try to fixed poll votes test - check specifically if vote count is 8 + make sure that pid check uses integers

Status: Needs review » Needs work

The last submitted patch, 79: poll-migration-2638406-79.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

naheemsays’s picture

StatusFileSize
new3.83 KB
new34.31 KB

The previous patch erroneously tests for 8 votes - the database only has 6.

Nodes do not seem to be loading correctly, so trying a different way.

Also testPollNodeType() didnt seem to run, so renamed to testNodeType()

naheemsays’s picture

StatusFileSize
new3.84 KB
new34.32 KB

Fix typo in last patch

naheemsays’s picture

StatusFileSize
new1.47 KB
new34.26 KB

Slight update - keeping test name to testNodeType() but I think it was actually passing before - reverting the debuginfo in the assert message as that caused the test to fail.

Still need to fix connection query/use to get the nids from the destination database

naheemsays’s picture

StatusFileSize
new904 bytes
new34.26 KB

I still can't get the testing to work on my PC (using Acquia Dev Desktop), so testing here.

naheemsays’s picture

StatusFileSize
new1.73 KB
new34.29 KB

fixing use of fetchCol()

naheemsays’s picture

StatusFileSize
new618 bytes
new34.27 KB
naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new32.18 KB
new7.21 KB

lets try this

Status: Needs review » Needs work

The last submitted patch, 87: poll-migration-2638406-87.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new32.18 KB
new2.35 KB

Updating fixtures. Is there a way of making them less brittle? Right now we will have to update them for every update to node fixtures in core.

Can we start our test data at an arbitrarily high start value for nid and vid?

Status: Needs review » Needs work

The last submitted patch, 89: poll-migration-2638406-89.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new762 bytes
new32.21 KB

Call migrateContent(); before main migration. Lets see if this works.

Status: Needs review » Needs work

The last submitted patch, 91: poll-migration-2638406-91.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new32.44 KB
new5.09 KB

In this patch I have tried to move to the d7_node_complete migration. It still doesnt work - failure is before the tests even start. The setup rabbit hole needs to be fixed.

I have also merged all 3 tests into 1 - since setup doesnt need to happen 3 times, the test runs are faster for me.

Status: Needs review » Needs work

The last submitted patch, 93: poll-migration-2638406-93.patch, failed testing. View results

quietone’s picture

Just a very brief look at the Kernel test.

+++ b/migrations/poll_choice.yml
@@ -0,0 +1,21 @@
+  bundle:

+++ b/tests/src/Kernel/migrate/d7/MigratePollTest.php
@@ -0,0 +1,249 @@
+    $this->executeMigrations([

The migrations here need to be in dependency order. This is a known bug and there is an issue for it.

quietone’s picture

Again, just looking at the Kernel test setup.

+++ b/tests/src/Kernel/migrate/d7/MigratePollTest.php
@@ -0,0 +1,249 @@
+    parent::setUp();
+
+    $this->loadFixture(__DIR__ . '/../../../../fixtures/drupal7.php');

The parent setUp() method will install the migrate_drupal test fixture. I don't know what will happen when you try to load another fixture, I never tried it. If you want to alter that fixture then your test can implement MigrateDumpAlterInterface, see \Drupal\Tests\field\Kernel\Migrate\d6\MigrateFieldInstanceLabelDescriptionTest for an example.

However, if you are altering the core dump you run the risk of having to update your test anytime the core fixture changes, specifically adds nodes. Given the remaining issues, that is unlikely but possible. You could copy the core fixture to your project to avoid that or make your nid/vid values higher.

naheemsays’s picture

StatusFileSize
new32.66 KB
new3.3 KB

Some progress: Fixtures were not the problem, but the comemnt on slack about the grouping of the migration was helpful - Thanks!

The poll_vote migration gives an error in the tests - the following code gives an empty pid:

  pid:
    plugin: migration_lookup
    migration: poll_question
    source: vid

Deleting this migration from the test then allows the setup to complete. For me next failures were when loading Poll node type and again when comparing counts of polls in source and destination databases.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new32.58 KB
new4.43 KB

The fixtures needed fixing - not all had been updated when changing the Node ID's the last time.

Now the setup should all work. Next step: fix the actual tests!

Status: Needs review » Needs work

The last submitted patch, 98: poll-migration-2638406-98.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

quietone’s picture

Sorry to be piecemeal with my comments, just being pulled in many directions today.

+++ b/migrations/poll_reference.yml
@@ -0,0 +1,27 @@
+    plugin: migration_lookup

After migration_lookups it is common to test the transformed value and skip if it is empty. That way you are not trying to save a NULL value. This sample is from d6_vocabulary_entity_display.yml and skips the row but you skip just the process, if that is needed.

  bundle:
    -
      plugin: migration_lookup
      migration: d6_node_type
      source: type
    -
      plugin: skip_on_empty
      method: row
quietone’s picture

This issue is part of a meta for better contrib support, adding related issue.

quietone’s picture

Oh, and add a migrate state file. Modules can now declare their Drupal 8 upgrade status so that 'poll' will be listed as 'will be upgraded' when someone upgrades via /upgrade.

naheemsays’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new33 KB
new5.86 KB

I have added the poll/migrate_drupal.yml file. A question however - I have marked it as finished. Drupal 7 and earlier poll module had a feature to set an offset for votes. This feature does not exist in Drupal 8 but actual votes are all migrated. Should the migrations still be marked as complete?

The Note Type test assert checking that a field_poll is attached passes and the node is also loaded correctly. Currently I am having issues around line 163 of the MigratePollTest.php file:

      // Test Poll attached to node.
      $polls[] = $destination_poll_node->field_poll->referencedEntities();

      // There should only ever be one poll attached to the node following migration from Drupal 7.
      $this->assertCount('1', $polls, "Number of attached polls is incorrect");
      $poll = $polls[0];
      $this->assertInstanceOf(Poll::class, $poll);

I think I am using referencedEntities incorrectly as its not returning a result.

Status: Needs review » Needs work

The last submitted patch, 103: poll-migration-2638406-103.patch, failed testing. View results

quietone’s picture

@NaheemSays, Hi, how is this progressing? Here are responses to #103 and then I took a look at the source plugins and made some suggestions.

#103.1 I am not familiar with poll but if all the possible source data is migrated then the migration has done it's job of getting the data into Drupal 8 or 9. It sounds like the data is migrated so finished would be correct. You may want to add a comment to the Poll project page to clarify what the migration actually does.

#103.2 I don't know the structure. $destination_poll_node->field_poll->target_id?

  1. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,111 @@
    + * Source plugin to migrate Polls.
    

    Source plugins just get the data, they perform the Extract action of an ETL process. So, the summary can be 'Gets the poll data from the source database'.

  2. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,111 @@
    +class Poll extends SqlBase {
    

    Why not extend from DrupalSqlBase? For one, it will has a requirement that the source module is enabled in the source database and if not throw a RequirementsException.

  3. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,111 @@
    +    $query = $this->select('node', 'n')
    +      ->fields('n', [
    +        'nid',
    +        'vid',
    +        'uid',
    +        'type',
    +        'language',
    +        'title',
    +        'status',
    +        'created',
    +      ])
    +      ->fields('p', [
    +        'runtime',
    +        'active',
    +      ]);
    

    It is better to add all the fields to the query, not just the ones you are using in your process pipeline. This allows other contrib of custom modules, who may need the other data, to use this source plugin without modification. They can just add make their own migration yml file.

  4. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,111 @@
    +    // Set a source property that can be referenced in yml.
    +    // Source properties can be named however you like.
    

    setSourceProperty sets a value on \Drupal\migrate\Row not a yml file. Adding a comment here explaining the structure of $choices may help the next dev to look at this code. It would save them a bit of time reading the query.

  5. +++ b/src/Plugin/migrate/source/PollChoice.php
    @@ -0,0 +1,53 @@
    + * Source plugin to migrate Poll choices.
    

    Similar here, 'Gets the poll choices data from the source database.'

  6. +++ b/src/Plugin/migrate/source/PollVote.php
    @@ -0,0 +1,59 @@
    + * Source plugin to migrate Poll votes.
    

    And here too, 'Gets the poll votes data from the source database.'

  7. +++ b/tests/src/Kernel/migrate/d7/MigratePollTest.php
    @@ -0,0 +1,250 @@
    +    foreach ($source_poll_nodes as $source_poll_node) {
    ...
    +      $this->assertEquals($source_poll_node->title, $destination_poll_node->title->value, 'Migrated title does not match');
    

    Speaking for myself, when I have assertions inside a foreach look I add the the changing value to the message so I know exactly which set of data failed.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.15 KB
new5.62 KB

Many thanks for your replies - they are very helpful.

I am moving forward slowly but surely. I have avoided writing tests before, so its a slow process (and most of my prior experience with drupal/php was years ago when we were in a procedural world.)

103.1 - I will sugggest that for a project page update when this patch is ready.

103.2 - I havent gotten this to work so unchanged in this patch. The migration adds a field_poll instance to the poll node type and at this stage I want to 1, test that there is a poll attached to the node, and check that only 1 poll is attached. I can get around it here by loading a poll directly.

I need to get the referencedEntities() code to work, though, because while I can avoid using it here, the next use of it is around 10 lines later where I cannot see a different approach - choices are referenced entities on polls and there is no guarantee that there are a specific number of them (2 test migration has 2 polls with 3 options, 1 poll with 2).

1. changed
2. I need to look into this further. I cant remember why I chose one over the other or even if I was aware of the other at the time.
3. changed
4. I tried improving the comment, but I feel it is still terrible. Should I be pointing out what is being done in the subprococess plugin, or the purpose of the prepareRow() function?
5. changed.
6. changed.
7. changed.

Status: Needs review » Needs work

The last submitted patch, 106: poll-migration-2638406-106.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.34 KB
new3.74 KB

Updated patch. The referencedEntities() code wasnt working because the migrations were all being skipped. Simplified migration code and it now runs.

Now only errors are lines 197/198: later poll vote testing already passes.

These migrations could work for Drupal 6 and 7, however are drupal 7 only because they depend on eg d7_node_complete:poll being completed first. Is there a way to define an or relationship in the yaml that would prevent the need to duplicate the full migration yaml file?

Status: Needs review » Needs work

The last submitted patch, 108: poll-migration-2638406-108.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.18 KB
new2.71 KB

All tests pass locally with this patch (Drupal 9.0.1, phpunit 8.5)

Status: Needs review » Needs work

The last submitted patch, 110: poll-migration-2638406-110.patch, failed testing. View results

naheemsays’s picture

I cannot reproduce the error on line 166 locally.

As for the other test, I have opened #3154918: Failing tests as from what I can see they are unrelated.

Question on fixtures - currently the numbering for the nodes and revisions immediately follows what is last item in core fixtures. however as new fixtures are added to core, these will need to be amended to keep up. Should I start at an arbitrarily high number such as 101 instead?

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.85 KB
new2.19 KB

Included the fix to the failing FieldUI test and also removed hard coded migrate mapping to one that is loaded from the migrate tables - it will make the tests less brittle.

I still need to investigate why there was a failure on line 166 on CI - I cannot reproduce it on my local Drupal 9 setup so it may be Drupal 8 related or due to a lower versioned phpunit.

Status: Needs review » Needs work

The last submitted patch, 113: poll-migration-2638406-113.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.33 KB
new867 bytes

Updated comment and removed fix to failing FieldUI test that has been committed separately. (interdiff is just the comment change - I am unsure how to include the other change after rebasing.)

Will still (probably) fail on CI as i havent made any changes to address that.

Status: Needs review » Needs work

The last submitted patch, 115: poll-migration-2638406-115.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.32 KB
new1.04 KB

Attempt at fixinf failing test.

naheemsays’s picture

w00t!

Only question (other than things found in future reviews) is the question on fixtures. Is it reasonable to start the nids and vids on arbitrarily high numbers instead of following on from what is in core fixtures?

heddn’s picture

Status: Needs review » Needs work

Using high nids is a good way to insulate things if you alter the core fixture. See #96 for possible other options.

  1. +++ b/migrations/poll_choice.yml
    @@ -0,0 +1,24 @@
    \ No newline at end of file
    
    +++ b/migrations/poll_question.yml
    @@ -0,0 +1,37 @@
    \ No newline at end of file
    
    +++ b/migrations/state/poll.migrate_drupal.yml
    @@ -0,0 +1,9 @@
    \ No newline at end of file
    

    Nit: new line at end of file is needed.

  2. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,104 @@
    +    // Set choices array on \Drupal\migrate\Row with values of choice id "chid".
    ...
    +    // and add the choice id's to the poll_question migration.
    

    Nit: "choice id" should be "choice ID".

  3. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,104 @@
    +    // It is assumed the chid value will not change during migration.
    +    // This will allow the subprocess plugin to iterate over the values
    

    Are we sure that the IDs can't change? Why can't we use migration_lookup. Requiring fixed IDs is not a good idea for the reason that incremental migrations won't work. Core supports fixed and non fixed IDs for this reason.

  4. +++ b/tests/src/Kernel/migrate/d7/MigratePollTest.php
    @@ -0,0 +1,244 @@
    +    'migrate_drupal_multilingual',
    

    Is this strictly necessary? I can't see why it would be. And really, there's a few questionable modules, like telephone, datetime, etc. Maybe a review and removal of some of the non-needed modules could be done. It would speed up the test.

deepak goyal’s picture

StatusFileSize
new33.26 KB
new1.4 KB

Hi @heddn
Fixed #119.1 and #119.2
please review.

deepak goyal’s picture

Status: Needs work » Needs review
deepak goyal’s picture

StatusFileSize
new33.12 KB
new1019 bytes

Hi @heddn
Fixed #119.4 please review.

#119.3 is still pending.

Status: Needs review » Needs work

The last submitted patch, 122: 2638406-122.patch, failed testing. View results

naheemsays’s picture

Status: Needs work » Needs review
StatusFileSize
new33.22 KB
new7.09 KB

Thanks for updating the patch Deepak - I have added the datetime and telephone modules back into the setup as their omission was causing a failure.

I tried looking into comment 96 above but I couldnt figure out how to do that or get around the need to calculate new values for the nid and vid after import of the main fixtures so I have kept the current method.

I have updated the patch to change the fixtures to start at 101 for nid and at 111 for revision ID's. The chid is also looked up with migrate_lookup now.

There is something wrong with the interdiff, it is showing that the new lines added by Deepak are deleted, but that is (AFAIK) not the case with the main patch.

naheemsays’s picture

Has any one else tested this yet?

It would be good to have another tester before setting to rtbc, but if not I will do that in a few days.

naheemsays’s picture

Status: Needs review » Reviewed & tested by the community

Setting to RTBC.

If this is committed the commit message and module front page should note that migrate suport is limited to Drupal 8.9+ only.

naheemsays’s picture

quietone’s picture

Status: Reviewed & tested by the community » Needs work

Wow, this looks very nice!

I did not read the entire issue, I focused on a very 'light' first pass at a review of the patch.
1. There are no coding standard errors. Yay!
2. There are no source plugin tests. :-(
3. The Migration tests does provide a database fixture with the needed data. That is excellent. It is not a 'complete' fixture in the sense that one can't install it in a D7 site and use it. Therefor, can someone add in the IS how that was created. And comment on why you believe it is accurate.
4. I notice that the use statements in a least one file is not alphabetized. Usually they are which makes is easier to read the file. This is not a Drupal standard but it an accepted practice.

And then some other items.

  1. +++ b/migrations/poll_choice.yml
    @@ -0,0 +1,24 @@
    +migration_tags:
    
    +++ b/migrations/poll_question.yml
    @@ -0,0 +1,40 @@
    +migration_tags:
    
    +++ b/migrations/poll_reference.yml
    @@ -0,0 +1,24 @@
    +migration_tags:
    
    +++ b/migrations/poll_vote.yml
    @@ -0,0 +1,32 @@
    +migration_tags:
    

    I think there are all content so should have the tag 'Content'

  2. +++ b/src/Plugin/migrate/source/Poll.php
    @@ -0,0 +1,103 @@
    +class Poll extends SqlBase {
    

    should use DrupalSqlBase so checkRequirements run

  3. +++ b/src/Plugin/migrate/source/PollChoice.php
    @@ -0,0 +1,49 @@
    +class PollChoice extends SqlBase {
    
    +++ b/src/Plugin/migrate/source/PollVote.php
    @@ -0,0 +1,53 @@
    +class PollVote extends SqlBase {
    

    Same again

  4. +++ b/tests/src/Kernel/migrate/d7/MigratePollTest.php
    @@ -0,0 +1,242 @@
    +    $this->installConfig([
    

    this can be shorted to
    $this->installConfig(static::$modules);

quietone’s picture

Category: Feature request » Task

And let's make this a task because it is something that needs to be done to support the users of Poll.

naheemsays’s picture

Issue summary: View changes

Updated issue summary with how the test fixtures were generated/modified.

naheemsays’s picture

I couldnt figure out how to get git to push my local changes so I have manually added them manually via gui with some trial and error. what is uploaded now should be idential to patch in comment 124

naheemsays’s picture

Status: Needs work » Needs review

Changes following comment #128:

1. Reordered the use statements
2. Added the Content migration tag
3. Use DrupalSqlBase
4. shortened install config to $this->installConfig(static::$modules);

naheemsays’s picture

from comment #128 items 1 and 4 have been done.

I have tried to do 2. and 3. but using DrupalSqlBase has always failed for me. I dont know how to do that change or if it is required.

tests should be passing again - apologies for such a ling time to fix the tests, my test system was broken and I finally got around to updating the patch.

There is also an extra line in src/Plugin/migrate/destination/PollVote.php, but I cant see it in my vscode, so I cant push a fix from there. I am guessing there is a problem with my config here.

Please feel free to commit to the branch and get this over the line, especially as Drupal 7 is coming to EoL so this issue has greater importance.

quietone’s picture

StatusFileSize
new4.52 KB

I have added the start of a source plugin test for the Poll source plugin. Like any test they are worth doing, even for the source plugins. Here that are not overly complicated. Hopefully, someone will use that to update the other source plugins to use DrupalSqlBase and to write the tests.

And fixed some coding standards issues.

Some questions:

  1. Why is this limited to the lastest revision of the node? What if someone needs all the revisions?
  2. Is there a reason this the Poll source plugin is not extending Node or NodeComplete, which it should be using since that is the default.

Feel free to ping me in #migration when a review is needed.

Well, once again I cannot push. Therefor I have added an interdiff with my changes. Can someone add them to the MR?

Edit: fix grammar

naheemsays’s picture

Thank you for looking at this!

I have enabled the setting to allow commits from members in the merge request. I hope this is enough.

I have pushed a commit with the interdiff minus the mode to drupalSqlBase as that was causing the following error:

PHPUnit 9.5.4 by Sebastian Bergmann and contributors.

Warning: Your XML configuration validates against a deprecated schema.
Suggestion: Migrate your XML configuration using "--migrate-configuration"!

Testing Drupal\Tests\poll\Kernel\migrate\d7\MigratePollTest
E 1 / 1 (100%)R

Time: 00:28.839, Memory: 10.00 MB

There was 1 error:

1) Drupal\Tests\poll\Kernel\migrate\d7\MigratePollTest::testPoll
PHPUnit\Framework\Exception: PHP Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:89
Stack trace:
#0 Standard input code(89): serialize(Array)
#1 Standard input code(123): __phpunit_run_isolated_test()
#2 {main}
thrown in Standard input code on line 89
Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:89
Stack trace:
#0 Standard input code(89): serialize(Array)
#1 Standard input code(123): __phpunit_run_isolated_test()
#2 {main}
thrown in Standard input code on line 89

/srv/drupaldev/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:270
/srv/drupaldev/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:187
/srv/drupaldev/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:667
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/Command.php:143
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/Command.php:96

--

There was 1 risky test:

1) Drupal\Tests\poll\Kernel\migrate\d7\MigratePollTest::testPoll
This test did not perform any assertions

/srv/drupaldev/web/core/tests/Drupal/Tests/Listeners/DrupalListener.php:127
/srv/drupaldev/vendor/phpunit/phpunit/src/Framework/TestResult.php:446
/srv/drupaldev/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:376
/srv/drupaldev/vendor/phpunit/phpunit/src/Util/PHP/AbstractPhpProcess.php:187
/srv/drupaldev/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:667
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/Command.php:143
/srv/drupaldev/vendor/phpunit/phpunit/src/TextUI/Command.php:96

ERRORS!
Tests: 1, Assertions: 0, Errors: 1, Risky: 1.

...

In relation to the two questions, I will have to go back and check but from my recollection:
1. the reason was that the poll does not have revisions and from the manual testing I did, adding the field to the node displayed it on all revisions.
2. The source plugin works for both Drupal 6 and 7. if I depended on the node source plugins I would need to have 2 versions. (probably less of an issue now since Drupal 6 migrations are not in core.)

naheemsays’s picture

I have updated the merge request and I would be grateful for another review/pointers:

1. I switched to DrupalSqlBase from sqlBase. I also needed to change source_module to node instead of poll as otherwise the test complained that the source module was not installed. If this is the incorrect fix, I would be grateful for a pointer where I need to change it.

2. There are test failures but these seem to exist on Drupal 9.3 onwards on the main module too - testing on Drupal 9.2 shows no errors. Again, any pointers where I need to fix what I assume are deprecations would be much appreciated.
Fixed main branch failires. if any remain past this point, they are from this branch (tests currently running)

naheemsays’s picture

naheemsays’s picture

ok, tests fixed. Just the one question from comment 137 over whether I did the right thing.

naheemsays’s picture

I managed to figure out why using DrupalSqlBase had resulted in errors previously: the fixtures had not included changes to the system table to mark the poll module as enabled.

I have manually added that to the fixtures now and the tests work properly without the previous workaround of having to set the source module to node.

If tests pass, this is ready. All previous feedback now dealt with

EDIT - Failing test does not seem to be due to this patch but due to change to testing on Drupal 9.4 and failing FieldUITest. Second test run will confirm.

naheemsays’s picture

Issue summary: View changes
naheemsays’s picture

rebased to fix unrelated failing test.

phjou’s picture

The poll status to know if a poll is active or not is not migrated. It is always active when using the migration for me.

The migration is putting the published status in the status property of the entity, but the status is actually used for "active", so the active value should go in the property status.

process:
  uid: uid
  question: title
  langcode:
    plugin: default_value
    source: language
    default_value: "und"
  runtime: runtime
  status: active
  created: created
  timestamp: created
  choice:
    plugin: sub_process
    source: choices
    process:
      target_id:
          plugin: migration_lookup
          migration: poll_choice
          source: chid
  anonymous_vote_allow: constants/anonymous_vote_allow
  cancel_vote_allow: constants/cancel_vote_allow
  result_vote_allow: constants/result_vote_allow
naheemsays’s picture

good catch @phjou - should be fixed now.

phjou’s picture

I confirm that the issue I've reported is fixed :)

naheemsays’s picture

Can you confirm how big of a dataset you tested this one? Also, I would be grateful if you could change the status to rtbc - it technically isnt but I suspect it wont get the necessary eyeballs until that is done. Last time I did it myself, but it feels a little... egotistical.

naheemsays’s picture

Status: Needs review » Reviewed & tested by the community

I think the patch is ready. I have incorporated the feedback and fixed issues.

berdir’s picture

Status: Reviewed & tested by the community » Needs work

The test is failing on D10.

naheemsays’s picture

Status: Needs work » Needs review

It should be passing again i Just had to remove the mention of a module that was no longer a separate module in drupal 10.

The commits on the merge request are a bit of a mess but my attempt to rebase them was... less than adequate so when merging please make sure to squash into one. Thanks!

naheemsays’s picture

Status: Needs review » Reviewed & tested by the community

I have moved the code into a new merge request to avoid the previous messy commit history.

It is the same code as before plus a fix to a coding standards error (which is separate commit).

I would be grateful to get this done as I want to work on another feature for poll (multiple poll types), but I dont want to touch that until this is in place to ensure that nothing is broken by that work

  • Berdir committed 6448e9a9 on 8.x-1.x authored by NaheemSays
    Issue #2638406 by NaheemSays, Deepak Goyal, heddn: Poll migrate support
    
berdir’s picture

Status: Reviewed & tested by the community » Fixed

I didn't test this myself nor review in depth, but I see it has been tested a bit and it shouldn't interfere with regular functionality of the module, so merged.

And don't worry about clean commits, merge requests are always squashed when using the d.o tools

Status: Fixed » Closed (fixed)

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