tripal_bulk_loader.module.orig 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. <?php
  2. include('tripal_bulk_loader.loader.inc');
  3. include('tripal_bulk_loader.constants.inc');
  4. /**
  5. * Implements hook_init
  6. * Used to add stylesheets and javascript files to the header
  7. */
  8. function tripal_bulk_loader_init() {
  9. // Add javascript and style sheet
  10. drupal_add_css(drupal_get_path('theme', 'tripal') . '/css/tripal_bulk_loader.css');
  11. drupal_add_js(drupal_get_path('theme', 'tripal') . '/js/tripal_bulk_loader.js');
  12. }
  13. /**
  14. * Implements hook_menu
  15. */
  16. function tripal_bulk_loader_menu() {
  17. $items = array();
  18. // Show all loaders
  19. $items['tripal_bulk_loaders'] = array(
  20. 'title' => 'Tripal Bulk Loaders',
  21. 'description' => 'Tripal bulk loaders for loading tab-delimited file into chado database',
  22. 'page callback' => 'tripal_bulk_loader_list',
  23. 'access arguments' => array('access tripal_bulk_loader'),
  24. 'type' => MENU_NORMAL_ITEM,
  25. );
  26. // Bulk Loading Job Node
  27. $items['node/%node/constants/%/edit'] = array(
  28. 'title' => 'Edit Constant Set',
  29. 'description' => 'Edit a group of constants associated with the current bulk loader',
  30. 'page callback' => 'drupal_get_form',
  31. 'page arguments' => array('tripal_bulk_loader_edit_constant_set_form', 1, 3),
  32. 'access arguments' => array('administer site configuration'),
  33. 'type' => MENU_CALLBACK,
  34. <<<<<<< HEAD
  35. 'file' => 'tripal_bulk_loader.constants.inc',
  36. =======
  37. 'file' => 'tripal_bulk_loader.constants.inc',
  38. >>>>>>> 6.x-0.4-dev
  39. );
  40. $items['node/%node/constants/%/delete'] = array(
  41. 'title' => 'Delete Constant Set',
  42. 'description' => 'Delete a group of constants associated with the current bulk loader',
  43. 'page callback' => 'drupal_get_form',
  44. 'page arguments' => array('tripal_bulk_loader_delete_constant_set_form', 1, 3),
  45. 'access arguments' => array('administer site configuration'),
  46. 'type' => MENU_CALLBACK,
  47. <<<<<<< HEAD
  48. 'file' => 'tripal_bulk_loader.constants.inc',
  49. =======
  50. 'file' => 'tripal_bulk_loader.constants.inc',
  51. >>>>>>> 6.x-0.4-dev
  52. );
  53. // Admin page to create the template
  54. $items['admin/tripal/tripal_bulk_loader_template'] = array(
  55. 'title' => 'Bulk Loader Template',
  56. 'description' => 'Templates for loading tab-delimited data',
  57. 'page callback' => 'tripal_bulk_loader_admin_template',
  58. 'access arguments' => array('administer site configuration'),
  59. 'type' => MENU_NORMAL_ITEM,
  60. <<<<<<< HEAD
  61. 'file' => 'tripal_bulk_loader.admin.inc',
  62. );
  63. // Create/Edit Template -------
  64. =======
  65. 'file' => 'tripal_bulk_loader.admin.inc',
  66. );
  67. $items['admin/tripal/tripal_bulk_loader_template/configure'] = array(
  68. 'title' => 'Configuration',
  69. 'description' => 'Configure the Tripal Bulk Loader Module',
  70. 'page callback' => 'drupal_get_form',
  71. 'page arguments' => array('tripal_bulk_loader_configuration_form'),
  72. 'access arguments' => array('administer site configuration'),
  73. 'type' => MENU_NORMAL_ITEM,
  74. 'file' => 'tripal_bulk_loader.admin.inc',
  75. );
  76. // Create/Edit Template -------
  77. >>>>>>> 6.x-0.4-dev
  78. $items['admin/tripal/tripal_bulk_loader_template/create'] = array(
  79. 'title' => 'Create Bulk Loader Template',
  80. 'description' => 'Create loader template for loading tab-delimited data',
  81. 'page callback' => 'drupal_get_form',
  82. 'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'create'),
  83. 'access arguments' => array('administer site configuration'),
  84. 'type' => MENU_NORMAL_ITEM,
  85. <<<<<<< HEAD
  86. 'file' => 'tripal_bulk_loader.admin.inc',
  87. =======
  88. 'file' => 'tripal_bulk_loader.admin.inc',
  89. >>>>>>> 6.x-0.4-dev
  90. );
  91. $items['admin/tripal/tripal_bulk_loader_template/edit'] = array(
  92. 'title' => 'Edit Bulk Loader Template',
  93. 'description' => 'Edit loader template for loading tab-delimited data',
  94. 'page callback' => 'drupal_get_form',
  95. 'page arguments' => array('tripal_bulk_loader_modify_template_base_form', 'edit'),
  96. 'access arguments' => array('administer site configuration'),
  97. 'type' => MENU_NORMAL_ITEM,
  98. <<<<<<< HEAD
  99. 'file' => 'tripal_bulk_loader.admin.inc',
  100. =======
  101. 'file' => 'tripal_bulk_loader.admin.inc',
  102. >>>>>>> 6.x-0.4-dev
  103. );
  104. $items['admin/tripal/tripal_bulk_loader_template/edit_record'] = array(
  105. 'title' => 'Edit Template Record',
  106. 'description' => 'Edit a record in an existing tripal bulk loader template.',
  107. 'page callback' => 'drupal_get_form',
  108. 'page arguments' => array('tripal_bulk_loader_edit_template_record_form'),
  109. 'access arguments' => array('administer site configuration'),
  110. 'type' => MENU_CALLBACK,
  111. <<<<<<< HEAD
  112. 'file' => 'tripal_bulk_loader.admin.inc',
  113. );
  114. $items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
  115. =======
  116. 'file' => 'tripal_bulk_loader.admin.inc',
  117. );
  118. $items['admin/tripal/tripal_bulk_loader_template/add_field'] = array(
  119. >>>>>>> 6.x-0.4-dev
  120. 'title' => 'Add Template Field',
  121. 'description' => 'Add a template field to an existing tripal bulk loader template.',
  122. 'page callback' => 'drupal_get_form',
  123. 'page arguments' => array('tripal_bulk_loader_add_template_field_form'),
  124. 'access arguments' => array('administer site configuration'),
  125. 'type' => MENU_CALLBACK,
  126. <<<<<<< HEAD
  127. 'file' => 'tripal_bulk_loader.admin.inc',
  128. );
  129. $items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
  130. =======
  131. 'file' => 'tripal_bulk_loader.admin.inc',
  132. );
  133. $items['admin/tripal/tripal_bulk_loader_template/edit_field'] = array(
  134. >>>>>>> 6.x-0.4-dev
  135. 'title' => 'Edit Template Field',
  136. 'description' => 'Edit an existing field from a tripal bulk loader template.',
  137. 'page callback' => 'drupal_get_form',
  138. 'page arguments' => array('tripal_bulk_loader_edit_template_field_form'),
  139. 'access arguments' => array('administer site configuration'),
  140. 'type' => MENU_CALLBACK,
  141. <<<<<<< HEAD
  142. 'file' => 'tripal_bulk_loader.admin.inc',
  143. );
  144. // Delete Template -----
  145. $items['admin/tripal/tripal_bulk_loader_template/delete'] = array(
  146. =======
  147. 'file' => 'tripal_bulk_loader.admin.inc',
  148. );
  149. // Delete Template -----
  150. $items['admin/tripal/tripal_bulk_loader_template/delete'] = array(
  151. >>>>>>> 6.x-0.4-dev
  152. 'title' => 'Delete Bulk Loader Template',
  153. 'description' => 'Delete bulk loader template',
  154. 'page callback' => 'drupal_get_form',
  155. 'page arguments' => array('tripal_bulk_loader_delete_template_base_form'),
  156. 'access arguments' => array('administer site configuration'),
  157. 'type' => MENU_NORMAL_ITEM,
  158. <<<<<<< HEAD
  159. 'file' => 'tripal_bulk_loader.admin.inc',
  160. );
  161. // Import/Export ---------
  162. =======
  163. 'file' => 'tripal_bulk_loader.admin.inc',
  164. );
  165. // Import/Export ---------
  166. >>>>>>> 6.x-0.4-dev
  167. $items['admin/tripal/tripal_bulk_loader_template/import'] = array(
  168. 'title' => 'Import Bulk Loader Template',
  169. 'description' => 'Import Loaders',
  170. 'page callback' => 'drupal_get_form',
  171. 'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'import'),
  172. 'access arguments' => array('administer site configuration'),
  173. 'type' => MENU_NORMAL_ITEM,
  174. <<<<<<< HEAD
  175. 'file' => 'tripal_bulk_loader.admin.inc',
  176. =======
  177. 'file' => 'tripal_bulk_loader.admin.inc',
  178. >>>>>>> 6.x-0.4-dev
  179. );
  180. $items['admin/tripal/tripal_bulk_loader_template/export'] = array(
  181. 'title' => 'Export Bulk Loader Template',
  182. 'description' => 'Export Loaders',
  183. 'page callback' => 'drupal_get_form',
  184. 'page arguments' => array('tripal_bulk_loader_import_export_template_form', 'export'),
  185. 'access arguments' => array('administer site configuration'),
  186. 'type' => MENU_NORMAL_ITEM,
  187. <<<<<<< HEAD
  188. 'file' => 'tripal_bulk_loader.admin.inc',
  189. );
  190. // AHAH ---------
  191. $items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
  192. 'page callback' => 'tripal_bulk_loader_add_field_ahah',
  193. 'access arguments' => array('administer site configuration'),
  194. 'type' => MENU_CALLBACK,
  195. 'file' => 'tripal_bulk_loader.admin.inc',
  196. );
  197. $items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
  198. 'page callback' => 'tripal_bulk_loader_edit_field_ahah',
  199. 'access arguments' => array('administer site configuration'),
  200. 'type' => MENU_CALLBACK,
  201. 'file' => 'tripal_bulk_loader.admin.inc',
  202. );
  203. =======
  204. 'file' => 'tripal_bulk_loader.admin.inc',
  205. );
  206. // AHAH ---------
  207. $items['admin/tripal/tripal_bulk_loader_template/add_field_ahah'] = array(
  208. 'page callback' => 'tripal_bulk_loader_add_field_ahah',
  209. 'access arguments' => array('administer site configuration'),
  210. 'type' => MENU_CALLBACK,
  211. 'file' => 'tripal_bulk_loader.admin.inc',
  212. );
  213. $items['admin/tripal/tripal_bulk_loader_template/edit_field_ahah'] = array(
  214. 'page callback' => 'tripal_bulk_loader_edit_field_ahah',
  215. 'access arguments' => array('administer site configuration'),
  216. 'type' => MENU_CALLBACK,
  217. 'file' => 'tripal_bulk_loader.admin.inc',
  218. );
  219. >>>>>>> 6.x-0.4-dev
  220. return $items;
  221. }
  222. /**
  223. * Implements hook_theme
  224. */
  225. function tripal_bulk_loader_theme() {
  226. return array(
  227. 'tripal_bulk_loader_set_constants_form' => array(
  228. 'arguments' => array('form' => NULL),
  229. ),
  230. 'tripal_bulk_loader_template' => array(
  231. 'arguments' => array('template_id' => NULL),
  232. 'template' => 'tripal_bulk_loader_template'
  233. ),
  234. 'tripal_bulk_loader_modify_template_base_form' => array(
  235. 'arguments' => array('form' => NULL),
  236. 'template' => 'tripal_bulk_loader_modify_template_base_form',
  237. ),
  238. 'tripal_bulk_loader_edit_template_field_form' => array(
  239. 'arguments' => array('form' => NULL),
  240. 'template' => 'tripal_bulk_loader_edit_template_field_form',
  241. ),
  242. 'tripal_bulk_loader_add_template_field_form' => array(
  243. 'arguments' => array('form' => NULL),
  244. 'template' => 'tripal_bulk_loader_add_template_field_form',
  245. ),
  246. );
  247. }
  248. /**
  249. * Implements hook_access
  250. */
  251. function tripal_bulk_loader_access($op, $node, $account) {
  252. if ($op == 'create') {
  253. if (!user_access('create tripal_bulk_loader', $account)) {
  254. return FALSE;
  255. }
  256. }
  257. if ($op == 'update') {
  258. if (!user_access('edit tripal_bulk_loader', $account)) {
  259. return FALSE;
  260. }
  261. }
  262. if ($op == 'delete') {
  263. if (!user_access('delete tripal_bulk_loader', $account)) {
  264. return FALSE;
  265. }
  266. }
  267. if ($op == 'view') {
  268. if (!user_access('access tripal_bulk_loader', $account)) {
  269. return FALSE;
  270. }
  271. }
  272. return NULL;
  273. }
  274. /**
  275. * Implements hook_perm
  276. */
  277. function tripal_bulk_loader_perm() {
  278. return array(
  279. 'access tripal_bulk_loader',
  280. 'create tripal_bulk_loader',
  281. 'delete tripal_bulk_loader',
  282. 'edit tripal_bulk_loader',
  283. );
  284. }
  285. /**
  286. * Creates a listing page for all bulk loading jobs
  287. */
  288. function tripal_bulk_loader_list() {
  289. $num_results_per_page = 50;
  290. $output = '';
  291. <<<<<<< HEAD
  292. $header = array('', 'Status', 'Loader', 'File');
  293. =======
  294. $header = array('','Status','Loader','File');
  295. >>>>>>> 6.x-0.4-dev
  296. $rows = array();
  297. $query = 'SELECT * FROM {tripal_bulk_loader} l '
  298. .'LEFT JOIN {node} n ON n.nid = l.nid '
  299. .'LEFT JOIN {tripal_bulk_loader_template} t ON t.template_id = cast(l.template_id as integer)';
  300. $resource = pager_query($query, $num_results_per_page, 0, NULL);
  301. while ($r = db_fetch_object($resource)) {
  302. $row = array(
  303. l($r->title, 'node/' . $r->nid),
  304. $r->job_status,
  305. $r->name,
  306. $r->file
  307. );
  308. $rows[] = $row;
  309. }
  310. $output .= theme('table', $header, $rows);
  311. return $output;
  312. }
  313. //////////////////////////////////////////////////////////////////////////////////////////////
  314. // Node Functions
  315. //////////////////////////////////////////////////////////////////////////////////////////////
  316. /**
  317. * Implements hook_node_info
  318. */
  319. function tripal_bulk_loader_node_info() {
  320. $nodes = array();
  321. $nodes['tripal_bulk_loader'] = array(
  322. 'name' => t('Bulk Loading Job'),
  323. 'module' => 'tripal_bulk_loader',
  324. 'description' => t('A bulk loader for inserting tab-delimited data into chado database'),
  325. 'has_title' => TRUE,
  326. 'has_body' => FALSE,
  327. 'locked' => TRUE
  328. );
  329. return $nodes;
  330. }
  331. /**
  332. * Implements node_form
  333. * Used to gather the extra details stored with a Bulk Loading Job Node
  334. */
  335. function tripal_bulk_loader_form($node, $form_state) {
  336. $form = array();
  337. if (isset($form_state['values'])) {
  338. $node = $form_state['values'] + (array)$node;
  339. $node = (object) $node;
  340. }
  341. $sql = "SELECT * FROM {tripal_bulk_loader_template}";
  342. $results = db_query($sql);
  343. $templates = array();
  344. while ($template = db_fetch_object ($results)) {
  345. $templates [$template->template_id] = $template->name;
  346. }
  347. if (!$templates) {
  348. $form['label'] = array(
  349. '#type' => 'item',
  350. '#description' => t("Loader template needs to be created before any bulk loader can be added. Go to 'Tripal Management > Bulk Loader Template' to create the template."),
  351. '#weight' => -10,
  352. );
  353. return $form;
  354. }
  355. $form['loader'] = array(
  356. '#type' => 'fieldset',
  357. '#title' => t('Basic Details'),
  358. );
  359. $form['loader']['loader_name'] = array(
  360. '#type' => 'textfield',
  361. '#title' => t('Loading Job Name'),
  362. '#weight' => -10,
  363. '#required' => TRUE,
  364. '#default_value' => $node->loader_name
  365. );
  366. $form['loader']['template_id'] = array(
  367. '#type' => 'select',
  368. '#title' => t('Template'),
  369. '#description' => t('Please specify a template for this loader'),
  370. '#options' => $templates,
  371. '#weight' => -9,
  372. '#required' => TRUE,
  373. '#default_value' => $node->template_id,
  374. );
  375. $form['loader']['file']= array(
  376. '#type' => 'textfield',
  377. '#title' => t('Data File'),
  378. '#description' => t('Please specify the data file to be loaded.'),
  379. '#weight' => -8,
  380. '#default_value' => $node->file
  381. );
  382. $form['loader']['has_header'] = array(
  383. '#type' => 'radios',
  384. '#title' => t('File has a Header'),
  385. '#options' => array( 1 => 'Yes', 2 => 'No'),
  386. '#weight' => -7,
  387. '#default_value' => $node->file_has_header,
  388. );
  389. return $form;
  390. }
  391. /**
  392. * Implements node_load
  393. */
  394. function tripal_bulk_loader_load($node) {
  395. $sql = "SELECT * FROM {tripal_bulk_loader} WHERE nid = %d";
  396. $node = db_fetch_object(db_query($sql, $node->nid));
  397. <<<<<<< HEAD
  398. $node->title = 'Bulk Loading Job: ' . $node->loader_name;
  399. // Add the loader template
  400. $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
  401. $results = db_fetch_object(db_query($sql, $node->template_id));
  402. $template = unserialize($results->template_array);
  403. $node->template = $results;
  404. $node->template->template_array = $template;
  405. =======
  406. $node->title = 'Bulk Loading Job: '.$node->loader_name;
  407. // Add the loader template
  408. $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
  409. $results = db_fetch_object(db_query($sql, $node->template_id));
  410. $template = unserialize($results->template_array);
  411. $node->template = $results;
  412. $node->template->template_array = $template;
  413. >>>>>>> 6.x-0.4-dev
  414. // Add inserted records
  415. $sql = 'SELECT * FROM {tripal_bulk_loader_inserted} WHERE nid=%d';
  416. $resource = db_query($sql, $node->nid);
  417. while ($r = db_fetch_object($resource)) {
  418. <<<<<<< HEAD
  419. $r->num_inserted = sizeof(preg_split('/,/', $r->ids_inserted));
  420. =======
  421. $r->num_inserted = sizeof(preg_split('/,/',$r->ids_inserted));
  422. >>>>>>> 6.x-0.4-dev
  423. $node->inserted_records->{$r->table_inserted_into} = $r;
  424. }
  425. // Add exposed field list
  426. $node->exposed_fields = array();
  427. if ($template) {
  428. foreach ($template as $record_id => $record) {
  429. foreach ($record['fields'] as $field_id => $field) {
  430. if ($field['exposed']) {
  431. $node->exposed_fields[] = array(
  432. 'record_id' => $record_id,
  433. 'field_id' => $field_id,
  434. 'title' => $field['title'],
  435. );
  436. }
  437. }
  438. }
  439. if (empty($node->exposed_fields)) {
  440. $node->exposed_fields[] = array();
  441. }
  442. }
  443. // Add constants
  444. $sql = 'SELECT * FROM {tripal_bulk_loader_constants} WHERE nid=%d ORDER BY group_id, record_id, field_id';
  445. $resource = db_query($sql, $node->nid);
  446. while ($r = db_fetch_object($resource)) {
  447. $node->constants[$r->group_id][$r->record_id][$r->field_id] = array(
  448. 'constant_id' => $r->constant_id,
  449. 'group_id' => $r->group_id,
  450. <<<<<<< HEAD
  451. 'chado_table' => $r->chado_table,
  452. 'chado_field' => $r->chado_field,
  453. 'record_id' => $r->record_id,
  454. 'field_id' => $r->field_id,
  455. 'value' => $r->value
  456. =======
  457. 'chado_table'=>$r->chado_table,
  458. 'chado_field'=>$r->chado_field,
  459. 'record_id'=>$r->record_id,
  460. 'field_id'=>$r->field_id,
  461. 'value'=>$r->value
  462. >>>>>>> 6.x-0.4-dev
  463. );
  464. }
  465. if (!$node->constants) {
  466. $node->constants[] = array();
  467. }
  468. <<<<<<< HEAD
  469. return $node;
  470. =======
  471. return $node;
  472. >>>>>>> 6.x-0.4-dev
  473. }
  474. /**
  475. * Implements node_insert
  476. * Insert the data from the node form on Create content
  477. */
  478. <<<<<<< HEAD
  479. function tripal_bulk_loader_insert($node) {
  480. =======
  481. function tripal_bulk_loader_insert ($node) {
  482. >>>>>>> 6.x-0.4-dev
  483. // Insert into tripal_bulk_loader
  484. $sql = "INSERT INTO {tripal_bulk_loader} (nid, loader_name, template_id, file, file_has_header, job_status) VALUES (%d, '%s', %d, '%s', %d, '%s')";
  485. db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, 'Initialized');
  486. <<<<<<< HEAD
  487. // Update title
  488. $node->title =$node->loader_name;
  489. drupal_write_record('node', $node, 'nid');
  490. drupal_write_record('node_revision', $node, 'nid');
  491. =======
  492. // Update title
  493. $node->title =$node->loader_name;
  494. drupal_write_record('node',$node,'nid');
  495. drupal_write_record('node_revision',$node,'nid');
  496. >>>>>>> 6.x-0.4-dev
  497. drupal_set_message('After reviewing the details, please Submit this Job (by clicking the "Submit Job" button below). No data will be loaded until the submitted job is reached in the queue.');
  498. }
  499. /**
  500. * Implements node_delete
  501. * Deletes the data when the delete button on the node form is clicked
  502. */
  503. function tripal_bulk_loader_delete($node) {
  504. $sql = "DELETE FROM {tripal_bulk_loader} WHERE nid = %d";
  505. db_query($sql, $node->nid);
  506. }
  507. /**
  508. * Implements node_update
  509. * Updates the data submitted by the node form on edit
  510. */
  511. <<<<<<< HEAD
  512. function tripal_bulk_loader_update($node) {
  513. // Update tripal_bulk_loader
  514. $sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
  515. db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
  516. // Add a job if the user want to load the data
  517. global $user;
  518. if ($node->job) {
  519. $job_args[0] =$node->loader_name;
  520. $job_args[1] = $node->template_id;
  521. $job_args[2] = $node->file;
  522. if (is_readable($node->file)) {
  523. $fname = preg_replace("/.*\/(.*)/", "$1", $node->file);
  524. tripal_add_job("Bulk Load: $fname", 'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
  525. }
  526. else {
  527. drupal_set_message(t("Can not open %file. Job not scheduled.", array('%file' => $node->file)));
  528. }
  529. }
  530. =======
  531. function tripal_bulk_loader_update ($node) {
  532. // Update tripal_bulk_loader
  533. $sql = "UPDATE {tripal_bulk_loader} SET nid = %d, loader_name = '%s', template_id = %d, file = '%s', file_has_header = '%s' WHERE nid = %d";
  534. db_query($sql, $node->nid, $node->loader_name, $node->template_id, $node->file, $node->has_header, $node->nid);
  535. // Add a job if the user want to load the data
  536. global $user;
  537. if($node->job) {
  538. $job_args[0] =$node->loader_name;
  539. $job_args[1] = $node->template_id;
  540. $job_args[2] = $node->file;
  541. if (is_readable($node->file)) {
  542. $fname = preg_replace("/.*\/(.*)/", "$1", $node->file);
  543. tripal_add_job("Bulk Load: $fname",'tripal_bulk_loader', 'tripal_bulk_loader_load_data', $job_args, $user->uid);
  544. } else {
  545. drupal_set_message("Can not open $node->file. Job not scheduled.");
  546. }
  547. }
  548. >>>>>>> 6.x-0.4-dev
  549. }
  550. ///////////////////////////////////////////////////////////
  551. /**
  552. * Preprocessor function for the tripal_bulk_loader template
  553. */
  554. function tripal_bulk_loader_preprocess_tripal_bulk_loader_template(&$variables) {
  555. $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
  556. $template = db_fetch_object(db_query($sql, $variables['template_id']));
  557. $template->template_array = unserialize($template->template_array);
  558. $variables['template'] = $template;
  559. <<<<<<< HEAD
  560. =======
  561. $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=%d";
  562. $template = db_fetch_object(db_query($sql, $variables['template_id']));
  563. $template->template_array = unserialize($template->template_array);
  564. $variables['template'] = $template;
  565. >>>>>>> 6.x-0.4-dev
  566. }
  567. /**
  568. * Implements hook_job_describe_args()
  569. * Specifically to make viewing past tripal jobs more readable for jobs registered by this module
  570. *
  571. * @params $callback
  572. * The callback passed into tripal_add_job()
  573. * @param $args
  574. * The arguements passed into tripal_add_job()
  575. * @return
  576. * An array where keys are the human readable headers describing each arguement
  577. * and the value is the aguement passed in after formatting
  578. */
  579. function tripal_bulk_loader_job_describe_args($callback, $args) {
  580. $new_args = array();
  581. if ($callback == 'tripal_bulk_loader_load_data') {
  582. //1st arg is the nid for a bulk loader node
  583. $node = node_load($args[0]);
  584. $new_args['Bulk Loading Job'] = l($node->title, 'node/' . $args[0]);
  585. return $new_args;
  586. }
  587. }