Created
September 6, 2013 12:53
-
-
Save pratik60/6463368 to your computer and use it in GitHub Desktop.
Import Dashboard without session id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function import_dashboard_menu() { | |
$items['admin/content/import_dashboard'] = array( | |
'title' => 'Import Dashboard', | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('import_dashboard_new_content'), | |
'access arguments' => array('access content'), | |
'type' => MENU_LOCAL_TASK | MENU_NORMAL_ITEM, | |
'expanded' => TRUE | |
); | |
$items['admin/content/import_dashboard/new_content'] = array( | |
'title' => 'New Content', | |
'access arguments' => array('access content'), | |
'type' => MENU_DEFAULT_LOCAL_TASK | |
); | |
$items['admin/content/import_dashboard/updated_content'] = array( | |
'title' => 'Updated Content', | |
'page callback' => 'drupal_get_form', | |
'page arguments' => array('import_dashboard_updated_content'), | |
'access arguments' => array('access content'), | |
'type' => MENU_LOCAL_TASK | |
); | |
return $items; | |
} | |
function import_dashboard_new_content() { | |
$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_new_content_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; | |
} | |
function import_dashboard_updated_content(){ | |
echo "Hello"; | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment