Skip to content

Instantly share code, notes, and snippets.

@pratik60
Created September 4, 2013 16:18
Show Gist options
  • Save pratik60/6439326 to your computer and use it in GitHub Desktop.
Save pratik60/6439326 to your computer and use it in GitHub Desktop.
Import Dashboard with Session ID
<?php
function import_dashboard_menu() {
$items['admin/content/import_dashboard'] = array(
'title' => 'Import Dashboard',
'page callback' => 'drupal_get_form',
'page arguments' => array('import_dashboard_page'),
'access arguments' => array('access content'),
'type' => MENU_LOCAL_TASK
);
return $items;
}
function import_dashboard_page() {
$data = array(
'parameters[type]' => 'article',
);
$status_mapping = array(
0 => "unpublished",
1 => "published"
);
$url='http://insight-server.local/test/node';
$full_url = url($url, array('query' => $data));
$result = drupal_http_request($full_url);
$list = drupal_json_decode($result->data);
$query=db_select("node","n")
->fields("n",array("uuid"))
->condition("type","article")
->execute();
while($rows=$query->fetchField())
{
$client_uuid[]=$rows;
}
foreach ($list as $key=>$node) {
if (in_array($node["uuid"],$client_uuid))
unset($list[$key]);
}
$options=array();
foreach ($list as $key=>$node) {
$options[$node["uuid"]]["linked_title"] = l($node["title"],preg_replace('/http:\/\/insight-server.local\/test\//', 'http://insight-server.local/', $node["uri"], 1));
$options[$node["uuid"]]["created_at"] = date('Y-m-d H:i:s',$node["created"]);
$options[$node["uuid"]]["changed_at"] = date('Y-m-d H:i:s',$node["changed"]);
$options[$node["uuid"]]["type"] = $node["type"];
$options[$node["uuid"]]["status"] = $status_mapping[$node["status"]];
}
//dsm($list);
$header = array(
'linked_title' => t('Title'),
'type' => t('Type'),
'status' => t('Status'),
'created_at' => t('Created At'),
'changed_at' => t('Updated At')
);
$form['table'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => t('No content available.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Import'),
);
return $form;
//return theme_tableselect($nodes);
//$table=array("header"=>array_keys_multi($nodes[0],$keys=array()),"rows"=>$rows);
//return theme('table',$table);
}
function import_dashboard_page_submit($form, &$form_state) {
//dsm($form_state);
foreach($form_state["values"]["table"] as $uuid){
if ($uuid) {
$url='http://insight-server.local/test/node/'.$uuid;
$nodes[] = drupal_json_decode(drupal_http_request($url)->data);
}
}
//dsm($nodes[0]);
//dsm(node_load(6));
//return;
$mapping_article = array("uuid","type","title","name","language","uid","body","field_tags","field_image","field_accessibility","field_publisher","created","changed");
//return;
foreach ($nodes as $node) {
$new_node = new stdClass;
foreach ($mapping_article as $key) {
$new_node->$key = $node[$key];
}
dsm($new_node);
node_save($new_node);
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment