1 node.install node_update_1005()

Convert content types to configuration files.

Related topics

File

core/modules/node/node.install, line 447
Install, update and uninstall functions for the node module.

Code

function node_update_1005() {
  // Basic sanity check.
  if (!db_table_exists('node_type')) {
    return;
  }

  // Ensure module-provided code is loaded.
  backdrop_load('module', 'node');
  backdrop_load('module', 'entity');

  $result = db_query("SELECT * FROM {node_type}");
  foreach ($result as $row) {
    $node_type = (object) $row;
    unset($node_type->locked);
    unset($node_type->custom);

    // To help assist moving to config from Features in Drupal 7, reclaim node
    // types owned by other modules that use the standard node base type.
    if ($node_type->base === 'node_content') {
      $node_type->module = 'node';
    }

    // Create each content type.
    $options = update_variable_get('node_options_' . $node_type->type, array('status', 'promote'));
    $node_type->settings = array(
      'status_default' => in_array('status', $options),
      'sticky_enabled' => TRUE,
      'sticky_default' => in_array('sticky', $options),
      'promote_enabled' => TRUE,
      'promote_default' => in_array('promote', $options),
      'revision_enabled' => TRUE,
      'revision_default' => in_array('revision', $options),
      'node_preview' => update_variable_get('node_preview_' . $node_type->type, BACKDROP_OPTIONAL),
      'node_submitted' => update_variable_get('node_submitted_' . $node_type->type, TRUE),
      'node_user_picture' => update_variable_get('node_user_picture_' . $node_type->type, TRUE),
      'language' => update_variable_get('node_type_language_' . $node_type->type),
    );
    node_type_save($node_type);

    // Delete the migrated variables.
    update_variable_del('node_options_' . $node_type->type);
    update_variable_del('node_preview_' . $node_type->type);
    update_variable_del('node_submitted_' . $node_type->type);
    update_variable_del('node_user_picture_' . $node_type->type);
    update_variable_del('node_type_language_' . $node_type->type);
  }
}