You are here

function _monitoring_setup_create_node in Monitoring 7

Same name and namespace in other branches
  1. 8 modules/demo/monitoring_demo.install \_monitoring_setup_create_node()

Creates nodes for testing purposes.

Parameters

array $settings: Node data.

Return value

object Created node.

1 call to _monitoring_setup_create_node()
monitoring_demo_enable in test/monitoring_demo.install
Implements hook_enable().

File

./monitoring.setup.inc, line 158
Set up dependencies for demo and tests.

Code

function _monitoring_setup_create_node($settings = array()) {

  // Populate defaults array.
  $settings += array(
    'body' => array(
      LANGUAGE_NONE => array(
        array(),
      ),
    ),
    'title' => _monitoring_setup_random_name(8),
    'comment' => 2,
    'changed' => REQUEST_TIME,
    'moderate' => 0,
    'promote' => 0,
    'revision' => 1,
    'log' => '',
    'status' => 1,
    'sticky' => 0,
    'type' => 'page',
    'revisions' => NULL,
    'language' => LANGUAGE_NONE,
    'uid' => 0,
  );

  // Use the original node's created time for existing nodes.
  if (isset($settings['created']) && !isset($settings['date'])) {
    $settings['date'] = format_date($settings['created'], 'custom', 'Y-m-d H:i:s O');
  }

  // Merge body field value and format separately.
  $body = array(
    'value' => _monitoring_setup_random_name(32),
    'format' => filter_default_format(),
  );
  $settings['body'][$settings['language']][0] += $body;
  $node = (object) $settings;
  node_save($node);

  // Small hack to link revisions to our test user.
  db_update('node_revision')
    ->fields(array(
    'uid' => $node->uid,
  ))
    ->condition('vid', $node->vid)
    ->execute();
  return $node;
}