Convert polls to regular posts

Created on 18 January 2024, about 1 year ago
Updated 23 May 2024, 11 months ago

Problem/Motivation

For the migration off of Drupal 7, poll module will not be used. The polls on the existing site should be rendered to text and content type changed, before the migration.

Remaining tasks

  • Update poll nodes
  • Uninstall poll module
📌 Task
Status

Fixed

Version

1.0

Component

Infrastructure

Created by

🇺🇸United States drumm NY, US

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @drumm
  • 🇫🇷France fmb Perpinyà, Catalonia, EU

    If I understand correctly @drumm, you are planning to convert polls in the current Drupal 7 platform, am I right?

  • 🇺🇸United States drumm NY, US

    Correct, it is good to get this out of the way in-place, so it is less complexity for the larger migration.

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    Fully agreed with this. Thanks for doing it!

    • drumm committed 8107ca3a on 7.x-1.x
      Issue #3415696: Remove access to vote on polls
      
    • drumm committed 1134a2c0 on 7.x-1.x
      Issue #3415696: Remove access to create & edit polls
      
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States drumm NY, US

    For example, https://localize.drupal.org/node/63818 would become:

    Entitásaltípus
    33% (2 szavazat)

    Entitásalosztály
    0% (0 szavazat)

    Entitáscsomag
    67% (4 szavazat)

    Összes szavazat: 6

    I thought about adding a note like “this is a static archive of a poll,” but we would need to round up translations of that note to do it right.

    The draft code is:

    $result = (new EntityFieldQuery())->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'poll')
    ->fieldCondition('og_group_ref', 'target_id', 158) // todo
    ->execute();
    foreach (node_load_multiple(array_keys($result['node'])) as $node) {
      $options = ['langcode' => node_load($node->og_group_ref[LANGUAGE_NONE][0]['target_id'])->l10n_group_language];
      $votes = array_sum(array_column($node->choice, 'chvotes'));
      $output = '';
      // todo weight
      foreach ($node->choice as $choice) {
        $output .= $choice['chtext'] . PHP_EOL . round($choice['chvotes'] / $votes * 100) . '% (' . format_plural($choice['chvotes'], '1 vote', '@count votes', [], $options) . ')' . PHP_EOL . PHP_EOL;
      }
      $output .= t('Total votes: @votes', ['@votes' => $votes], $options);
      print_r($node);
      print $output;
      break;
    }

    Going ahead and marking this needs review for the text in the blockquote and deciding if we add anything else.

  • 🇭🇺Hungary Gábor Hojtsy Hungary

    I think you can add "This is a static archive of a poll" without needing to translate it first. After all the site is a tool for translators from English to other languages, they should understand English :) The example looks great though with or without it.

  • 🇺🇸United States drumm NY, US

    https://migrate-localize.dev.devdrupal.org/node/2899 is a migrated example

    $result = (new EntityFieldQuery())->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'poll')
    ->execute();
    foreach (node_load_multiple(array_keys($result['node'])) as $node) {
      $options = ['langcode' => node_load($node->og_group_ref[LANGUAGE_NONE][0]['target_id'])->l10n_group_language];
      drush_log($options['langcode'] . ' ' . url('node/' . $node->nid, ['absolute' => TRUE]));
      $votes = array_sum(array_column($node->choice, 'chvotes'));
      $output = 'This is a static archive of a poll.' . PHP_EOL . PHP_EOL;
      uasort($node->choice, 'drupal_sort_weight');
      foreach ($node->choice as $choice) {
        $output .= $choice['chtext'] . PHP_EOL . round($choice['chvotes'] / max($votes, 1) * 100) . '% (' . format_plural($choice['chvotes'], '1 vote', '@count votes', [], $options) . ')' . PHP_EOL . PHP_EOL;
      }
      $output .= t('Total votes: @votes', ['@votes' => $votes], $options);
      $node->type = 'story';
      $node->body[LANGUAGE_NONE][0]['value'] = $output;
      node_save($node);
    }
  • 🇫🇷France fmb Perpinyà, Catalonia, EU

    Thanks drumm! The beauty of it is we do not even need to change migrations, since you are using an existing content type.

  • Status changed to Fixed 11 months ago
  • 🇺🇸United States drumm NY, US

    This is now done and poll module is uninstalled.

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

Production build 0.71.5 2024