View source
#!/usr/bin/env php
<?php
$cmd = 'index.php';
$_SERVER['HTTP_HOST'] = 'default';
$_SERVER['PHP_SELF'] = '/index.php';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_SOFTWARE'] = NULL;
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['QUERY_STRING'] = '';
$_SERVER['PHP_SELF'] = $_SERVER['REQUEST_URI'] = '/';
$_SERVER['HTTP_USER_AGENT'] = 'console';
$modules_to_enable = array(
'og',
'user',
'node',
);
include_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
include_once './modules/system/system.admin.inc';
$form = system_modules();
foreach ($modules_to_enable as $module) {
$form_state['values']['status'][$module] = TRUE;
}
$form_state['values']['disabled_modules'] = $form['disabled_modules'];
system_modules_submit(NULL, $form_state);
unset($form_state);
drupal_cron_run();
module_load_include('inc', 'node', 'content_types');
$form_state = array(
'values' => array(),
);
$form_state['values']['name'] = 'test-group';
$form_state['values']['type'] = 'test_group';
$form_state['values']['og_content_type_usage'] = 'group';
drupal_execute('node_type_form', $form_state);
$form_state = array(
'values' => array(),
);
$form_state['values']['name'] = 'test-post-group';
$form_state['values']['type'] = 'test_post_group';
$form_state['values']['og_content_type_usage'] = 'group_post_standard';
drupal_execute('node_type_form', $form_state);
$user_ids = array();
foreach (range(3, 7) as $i) {
$user_values = array();
$user_values['name'] = 'og_test_user' . $i;
$user_values['mail'] = 'og_test_user' . $i . '@example.com';
$user_values['pass'] = user_password(5);
$user_values['status'] = 1;
$user = user_save(NULL, $user_values);
$user_ids[$i] = $user->uid;
}
interface ogContent {
public function groupList($user_ids);
public function postList($user_ids, $groups);
public function groupActions($user_ids, $groups, $posts);
}
class ogGroupSelectiveState implements ogContent {
public function groupList($user_ids) {
$list = array();
foreach (og_selective_map() as $key => $value) {
$list[] = array(
'title' => 'group-selective-state-' . $key,
'uid' => $user_ids[3],
'body' => 'Group with selective state set to ' . $value,
'og_description' => 'Group with selective state set.',
'og_selective' => $key,
);
}
return $list;
}
public function postList($user_ids, $groups) {
return array();
}
public function groupActions($user_ids, $groups, $posts) {
}
}
$og_content_config = array();
$og_content_config[] = new ogGroupSelectiveState();
foreach ($og_content_config as $content_config) {
$groups = array_map('og_group_node', $content_config
->groupList($user_ids));
$posts = array_map('og_post_node', $content_config
->postList($user_ids, $groups));
$content_config
->groupActions($user_ids, $groups, $posts);
}
function og_group_node($values = array()) {
$node = (object) $values;
$node->type = 'test_group';
node_save($node);
return $node->nid;
}
function og_post_node($values = array()) {
$node = (object) $values;
$node->type = 'test_post_group';
node_save($node);
return $node->nid;
}