<?php

/**
 * Implements hook_install()
 *
 */
function groups_groups_install() {
  groups_groups_update_7301();
}

/**
 * Set default display settings for group content type and
 * hide author and date information.
 */
function groups_groups_update_7301() {
  $v = variable_get('node_submitted_group', 0);
  variable_set('node_submitted_group', $v);
}

/**
 * Set default group status to "unsupported".
 */
function groups_groups_update_7302() {
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'group');
  $result = $query->execute();
  $nids = array_keys($result['node']);
  foreach ($nids as $nid) {
    $entity = node_load($nid);
    $wrapper = entity_metadata_wrapper('node', $entity);
    $wrapper->field_group_status->set('0');
    $wrapper->save();
  }
}

/**
 * Disable commenting on existing group nodes.
 */
function groups_groups_update_7303() {
  $query = new EntityFieldQuery();
  $query->entityCondition('entity_type', 'node')
    ->entityCondition('bundle', 'group');
  $result = $query->execute();
  if (isset($result['node'])) {
    $nids = array_keys($result['node']);
    $nodes = node_load_multiple($nids, NULL, TRUE);
    foreach ($nodes as $node) {
      $node->comment = 0;
      node_save($node);
    }
  }
}