tripal_bulk_loader.module 22 KB

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