You are here

public function ConvertNodesForm::convertNodes in Convert Nodes 8

1 call to ConvertNodesForm::convertNodes()
ConvertNodesForm::submitForm in src/Form/ConvertNodesForm.php
Form submission handler.

File

src/Form/ConvertNodesForm.php, line 120

Class

ConvertNodesForm
ConvertNodesForm.

Namespace

Drupal\convert_nodes\Form

Code

public function convertNodes() {
  $base_table_names = ConvertNodes::getBaseTableNames();
  $userInput = ConvertNodes::sortUserInput($this->userInput, $this->fieldsNewTo, $this->fieldsFrom);
  $map_fields = $userInput['map_fields'];
  $update_fields = $userInput['update_fields'];
  $field_table_names = ConvertNodes::getFieldTableNames($this->fieldsFrom);
  $nids = ConvertNodes::getNids($this->fromType);
  echo "<pre>";
  exit(print_r($this->fieldsTo));
  $limit = 100;
  if ($nids) {
    $batch = [
      'title' => $this
        ->t('Converting Base Tables...'),
      'operations' => [
        [
          '\\Drupal\\convert_nodes\\ConvertNodes::convertBaseTables',
          [
            $base_table_names,
            $nids,
            $this->toType,
          ],
        ],
        [
          '\\Drupal\\convert_nodes\\ConvertNodes::convertFieldTables',
          [
            $field_table_names,
            $nids,
            $this->toType,
            $update_fields,
          ],
        ],
        [
          '\\Drupal\\convert_nodes\\ConvertNodes::addNewFields',
          [
            $nids,
            $limit,
            $map_fields,
          ],
        ],
      ],
      'finished' => '\\Drupal\\convert_nodes\\ConvertNodes::convertNodesFinishedCallback',
    ];
    batch_set($batch);
    return 'All nodes of type ' . $this->fromType . ' were converted to ' . $this->toType;
  }
  else {
    return 'No nodes of type ' . $this->fromType . ' were found';
  }
}