It would be enormously useful to be able to migrate votingapi values from D6 and D7 sites to D8.

See also #2697163: Add migration support for a D7 version of this issue.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

malcomio created an issue. See original summary.

malcomio’s picture

I'm making a start on this at https://github.com/malcomio/votingapi/tree/migrate, although I'm still trying to get my head around how to write migration plugins

https://www.drupal.org/docs/8/api/migrate-api/migrate-api-overview links to https://groups.drupal.org/node/387488, but it seems to be out of date

marvil07’s picture

Status: Active » Needs review
FileSize
3.03 KB

I have not used the mentioned github source above as base because it does not specify license, and since it is not in drupal.org, the license cannot be assumed.
Also, that is about d6 migration, so it is really complementary to this.

What is added:

  • A new d7_vote migrate source plugin.
  • A new d7_node_vote migrate source plugin, extending the previous one. This is really helpful for importing a subset related to nodes.
  • A new d7_vote migration, using d7_vote migrate source plugin, to import all votes from d7 to d8.

We may want to either add independent commits for d6 and d7, or maybe split this into two tickets.

benjifisher’s picture

I am starting to look at this. I have not tested yet, but the code looks solid. Just one suggestion:

+++ b/src/Plugin/migrate/source/d7/Vote.php
@@ -0,0 +1,59 @@
+  public function query() {
+    $query = $this->select('votingapi_vote', 'v')
+      ->fields('v');
+    foreach (['entity_type', 'value_type', 'tag'] as $db_field_name) {
+      if (!empty($this->configuration[$db_field_name])) {
+        $operator = is_array($this->configuration[$db_field_name]) ? 'IN' : '=';
+        $query->condition("v.$db_field_name", $this->configuration[$db_field_name], $operator);
+      }
+    }

I would replace the last two lines with something like this:

        $value = $this->configuration[$db_field_name];
        $query->condition("v.$db_field_name", $value, is_array($value) ? 'IN' : '=');
marvil07’s picture

@benjifisher, I guess the idea behind your suggestion is to be less verbose, I tried to do that in this patch.

benjifisher’s picture

+      if (!empty($this->configuration[$db_field_name])) {
+        $value = (array) $this->configuration[$db_field_name];
+        $query->condition("v.$db_field_name", $value, 'IN');
+      }

I like that! It is easier to read than the original (or my suggestion) and it keeps these lines under 80 characters.

benjifisher’s picture

Status: Needs review » Reviewed & tested by the community

I did some testing of this on my current project. (I am working on this project with @marvil07.) The migration works as expected.

I checked the votes associated to a few nodes (36 votes in all for four nodes): I checked the entity ID and vote value for all of them, and the timestamp and vote_source for a couple. In my test, the entity_type, value_type, and tag were all the same.

I tested the source plugin from this patch, but we are using a custom migration, not the one provided by the patch.

  • pifagor committed 880b7e5 on 8.x-3.x authored by marvil07
    Issue #2831575 by marvil07, benjifisher, malcomio, pifagor: Add migrate...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed
marvil07’s picture

@pifagor: thanks for including the change!

pifagor’s picture

@marvil07 Thank you for your contribution to the development of the module

Status: Fixed » Closed (fixed)

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