You are here

function coder_upgrade_conversions_prepare in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/includes/conversion.inc \coder_upgrade_conversions_prepare()

Returns the parameters to submit for module conversion.

1 call to coder_upgrade_conversions_prepare()
coder_upgrade_conversions_apply in coder_upgrade/includes/conversion.inc
Applies the module conversion code.

File

coder_upgrade/includes/conversion.inc, line 329

Code

function coder_upgrade_conversions_prepare($form_state) {

  // Gather the submitted parameters.
  list($upgrades, $extensions, $directories, $modules) = coder_upgrade_selections($form_state);

  // TODO Cache this list so we don't have to query all the files again.
  $upgrades_all = _coder_upgrade_upgrades();
  foreach ($upgrades as $name => $upgrade) {
    $upgrades[$name] = array(
      'module' => isset($upgrades_all[$name]['module']) ? $upgrades_all[$name]['module'] : '',
      'files' => isset($upgrades_all[$name]['files']) ? $upgrades_all[$name]['files'] : array(),
    );
  }
  $old_dir = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('old');
  $new_dir = DRUPAL_ROOT . '/' . coder_upgrade_directory_path('new');

  // Combine directory and module items into a single list.
  // Omit name from key so as to allow for duplicate names.
  // TODO Handle duplicate names when making new conversion directories.
  // Could intersect keys in $directories, $modules; then add counter suffix to new_dir???
  // Use global counter??? Or copy $directories to files/dirs and $modules to files/modules???
  $items = array();
  foreach ($directories as $key => $directory) {
    $items[] = array(
      'name' => $key,
      'old_dir' => $old_dir . $key,
      'new_dir' => $new_dir . $key,
    );
  }
  $last = 'xx_XX';
  $rows = coder_upgrade_module_list();
  foreach ($modules as $key => $module) {
    if (isset($rows[$key])) {
      $row = $rows[$key];
      if (strpos($row['dir'] . '/', $last . '/') === 0) {

        // Omit modules contained in subdirectory of a parent module.
        continue;
      }
      $last = $row['dir'];
      $items[] = array(
        'name' => $key,
        'old_dir' => $row['dir'],
        'new_dir' => $new_dir . $key,
      );
    }
  }
  return array(
    $upgrades,
    $extensions,
    $items,
  );
}