Tripal v1.0 (6.x-1.0)
|
00001 <?php 00002 00011 function tripal_bulk_loader_admin_template() { 00012 $output = ''; 00013 00014 $output .= '<br /><h3>Quick Links:</h3>'; 00015 $output .= '<ul>' 00016 . '<li>' 00017 . t('<a href="@link">Configure settings</a>', 00018 array('@link' => url('admin/tripal/tripal_bulk_loader_template/configure'))) 00019 . '</li>' 00020 . '<li>' 00021 . t('List <a href="@link">Bulk Loader Jobs</a>', 00022 array('@link' => url('admin/tripal/tripal_bulk_loader_template/jobs'))) 00023 . '</li>' 00024 . '<li>' 00025 . t('List <a href="@link">Manage Templates</a>', 00026 array('@link' => url('admin/tripal/tripal_bulk_loader_template/manage_templates'))) 00027 . '</li>' 00028 . '<ul>' 00029 . '<li>' 00030 . t('<a href="@create">Create</a> a new template', 00031 array('@create' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/create'))) 00032 . '</li>' 00033 . '<li>' 00034 . t('<a href="@edit">Edit</a> an existing template', 00035 array('@edit' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/edit'))) 00036 . '</li>' 00037 . '<li>' 00038 . t('<a href="@delete">Delete</a> an existing template', 00039 array('@delete' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/delete'))) 00040 . '</li>' 00041 . '<li>' 00042 . t('<a href="@import">Import</a> a new template', 00043 array('@import' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/import'))) 00044 . '</li>' 00045 . '<li>' 00046 . t('<a href="@export">Export</a> an existing template', 00047 array('@export' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/export'))) 00048 . '</li>' 00049 . '</ul>' 00050 . '</ul>'; 00051 00052 $output .= '<h3>Module Description:</h3>'; 00053 $output .= '<p>This module provides the ability to create loading templates for any tab-delimited ' 00054 . 'data file allowing it to be loaded into chado. The Loading Templates are a direct mapping ' 00055 . 'between the columns in your file and the columns in chado tables. As such to use this tool ' 00056 . 'you need to be very familar with the chado schema -See ' 00057 . l(t('Chado -Getting Started'), 'http://gmod.org/wiki/Chado_-_Getting_Started') 00058 . '. The ability to add constants and specify foreign key contraints is also provided ' 00059 . 'in order for the loader to fill chado columns which may be required but are not specified ' 00060 . 'in your input file.</p>'; 00061 $output .= '<br />'; 00062 00063 $output .= '<h3>Setup Instructions</h3>'; 00064 $output .= '<p>After intallation of the bulk loader module, the following tasks should be performed:</p>'; 00065 $output .= '<ol>'; 00066 $output .= '<li><b>Install Theme:</b> In order for Bulk Loading pages to be displayed correctly, ' 00067 .'the contents of the Tripal Bulk Loader theme directory ([drupal root]/sites/all/modules/tripal/tripal_bulk_loader/theme) ' 00068 .'should be moved to the base directory of the Tripal theme ([drupal root]/sites/all/themes/tripal). ' 00069 .'Finally the drupal cache should be cleared for the new theme to take effect -navigate to admin/settings/performance ' 00070 .'and click the Clear Cached Data button.</li>'; 00071 $output .= '</ol>'; 00072 00073 return $output; 00074 } 00075 00079 function tripal_bulk_loader_admin_manage_templates() { 00080 $output = ''; 00081 00082 $output .= '<br /><h3>Quick Links:</h3>'; 00083 $output .= '<ul>' 00084 . '<li>' 00085 . t('<a href="@create">Create</a> a new template', 00086 array('@create' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/create'))) 00087 . '</li>' 00088 . '<li>' 00089 . t('<a href="@edit">Edit</a> an existing template', 00090 array('@edit' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/edit'))) 00091 . '</li>' 00092 . '<li>' 00093 . t('<a href="@delete">Delete</a> an existing template', 00094 array('@delete' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/delete'))) 00095 . '</li>' 00096 . '<li>' 00097 . t('<a href="@import">Import</a> a new template', 00098 array('@import' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/import'))) 00099 . '</li>' 00100 . '<li>' 00101 . t('<a href="@export">Export</a> an existing template', 00102 array('@export' => url('admin/tripal/tripal_bulk_loader_template/manage_templates/export'))) 00103 . '</li>' 00104 . '</ul>'; 00105 00106 $output .= '<p>' . t('Templates, as the term is used for this module, refer to plans 00107 describing how the columns in the data file supplied to a bulk loading job map to tables 00108 and fields in chado. Templates are created independently of bulk loading jobs so that 00109 they can be re-used. Thus you only need one template to load any number of files of the 00110 same format.') . '</p>'; 00111 00112 00113 00114 return $output; 00115 } 00116 00120 function tripal_bulk_loader_admin_jobs() { 00121 $output = ''; 00122 $num_jobs_per_page = 50; 00123 00124 $output .= '<p>' . t('Jobs are not automatically submitted to the tripal jobs management 00125 system when they are first created. Any jobs listed below with a status of "Initialized" 00126 will not have a Job ID until you go to the bulk loader page and submit the job.') . '</p>'; 00127 00128 $header = array( 00129 array('data' => 'Job ID', 'field' => 'job_id', 'sort' => 'DESC'), 00130 array('data' => 'Name', 'field' => 'loader_name'), 00131 array('data' => 'Template', 'field' => 'template_name'), 00132 array('data' => 'Status', 'field' => 'job_status'), 00133 array('data' => 'Progress', 'field' => 'progress'), 00134 ''); 00135 $rows = array(); 00136 $resource = pager_query("SELECT n.*, t.name as template_name, j.progress 00137 FROM {tripal_bulk_loader} n 00138 LEFT JOIN {tripal_bulk_loader_template} t ON cast(n.template_id as integer) = t.template_id 00139 LEFT JOIN {tripal_jobs} j ON n.job_id = j.job_id" 00140 . tablesort_sql($header), 00141 $num_jobs_per_page); 00142 while ($n = db_fetch_object($resource)) { 00143 $rows[] = array( 00144 l($n->job_id, 'admin/tripal/tripal_jobs/view/' . $n->job_id), 00145 l($n->loader_name, 'node/' . $n->nid), 00146 l($n->template_name, 'admin/tripal/tripal_bulk_loader_template/manage_templates/edit', array('query' => 'template_id=' . $n->template_id)), 00147 $n->job_status, 00148 ($n->progress) ? $n->progress . '%' : '', 00149 l('View', 'node/' . $n->nid) . ' | ' . l('Edit', 'node/' . $n->nid . '/edit') 00150 ); 00151 } 00152 $output .= theme_table($header, $rows); 00153 00154 $output .= theme('pager'); 00155 00156 return $output; 00157 } 00158 00167 function tripal_bulk_loader_configuration_form($form_state = NULL) { 00168 $form = array(); 00169 00170 $form['space'] = array( 00171 '#type' => 'fieldset', 00172 '#title' => t('Enable/Disable Functionality'), 00173 ); 00174 00175 $form['space']['keep_track_inserted'] = array( 00176 '#type' => 'checkbox', 00177 '#title' => t('Keep track of inserted record IDs'), 00178 '#description' => t('This enables the ability to revert an entire loading job even if ' 00179 .'it completed successfully. Furthermore, it displays the number of records ' 00180 .'successfully inserted into each table.'), 00181 '#default_value' => variable_get('tripal_bulk_loader_keep_track_inserted', FALSE), 00182 ); 00183 00184 $form['speed'] = array( 00185 '#type' => 'fieldset', 00186 '#title' => t('Possible Speed Improvements'), 00187 ); 00188 00189 $form['speed']['prepare'] = array( 00190 '#type' => 'checkbox', 00191 '#title' => t('Use Prepared Statements'), 00192 '#description' => t('SQL Prepared Statements allow for SQL queries which will be run ' 00193 .'many times to be parsed, rewritten and planned only once rather then every time ' 00194 .'the query is run. In the case of the bulk loader, this ensures that planning only ' 00195 .'occurs once for each "record" in your bulk loading template.'), 00196 '#default_value' => variable_get('tripal_bulk_loader_prepare', TRUE), 00197 ); 00198 00199 $form['speed']['disable_triggers'] = array( 00200 '#type' => 'checkbox', 00201 '#title' => t('Delay Constraint Checking during loading job.'), 00202 '#description' => t('This delays the constraint checking until the end of the 00203 loading proccess.'), 00204 '#default_value' => variable_get('tripal_bulk_loader_disable_triggers', TRUE), 00205 ); 00206 00207 $form['speed']['no_validate'] = array( 00208 '#type' => 'checkbox', 00209 '#title' => t('Skip Validation at the Tripal Core API level'), 00210 '#description' => t('If an error is encountered, the Tripal core API will try 00211 to provide informative error messages. With this turned off, you will not benifit 00212 from these more informative error messages; however, your job will load faster 00213 since it doesn\'t have to do the additional checking before inserting.'), 00214 '#default_value' => variable_get('tripal_bulk_loader_skip_validation', FALSE), 00215 ); 00216 00217 $form['speed']['transactions'] = array( 00218 '#type' => 'radios', 00219 '#title' => t('Transaction Rollback when an error is encountered'), 00220 '#options' => array( 00221 'all' => t('Rollback the last constant set.' 00222 .'<div class="description"If you added more then one constant set then the 00223 successfully loaded constant sets will not be rolled back. However, once an error 00224 is encountered no further constant sets will be loaded either.</div>'), 00225 'row' => t('Only Rollback the last line of the input file.' 00226 .'<div class="description">This option may allow you to restart the job after 00227 fixing the error (manual intervention needed).</div>'), 00228 'none' => t('Do not use transactions<div class="description">This is not recommended.</div>') 00229 ), 00230 '#default_value' => variable_get('tripal_bulk_loader_transactions', 'row') 00231 ); 00232 00233 $form['speed']['lock'] = array( 00234 '#type' => 'radios', 00235 '#title' => t('Lock Type'), 00236 '#description' => t('The type of lock used by the bulk loading jobs. The lock is ' 00237 .'acquired at the beginning of the job and kept till the end. A lock of the type ' 00238 .'selected will be acquired for every table being inserted into.'), 00239 '#options' => array( 00240 'ROW EXCLUSIVE' => t('ROW EXCLUSIVE: The default lock type for insert queries.'), 00241 'EXCLUSIVE' => t('EXCLUSIVE: Only Select Queries can access the table.'), 00242 'ACCESS EXCLUSIVE' => t('ACCESS EXCLUSIVE: No other queries can access the table.'), 00243 ), 00244 '#default_value' => variable_get('tripal_bulk_loader_lock', 'ROW EXCLUSIVE'), 00245 ); 00246 00247 $form['submit1'] = array( 00248 '#type' => 'submit', 00249 '#value' => t('Save') 00250 ); 00251 00252 return $form; 00253 } 00254 00258 function tripal_bulk_loader_configuration_form_submit($form, $form_state) { 00259 00260 variable_set('tripal_bulk_loader_prepare', $form_state['values']['prepare']); 00261 variable_set('tripal_bulk_loader_disable_triggers', $form_state['values']['disable_triggers']); 00262 variable_set('tripal_bulk_loader_skip_validation', $form_state['values']['no_validate']); 00263 variable_set('tripal_bulk_loader_transactions', $form_state['values']['transactions']); 00264 variable_set('tripal_bulk_loader_lock', $form_state['values']['lock']); 00265 00266 variable_set('tripal_bulk_loader_keep_track_inserted', $form_state['values']['keep_track_inserted']); 00267 00268 }