$analysis_id))->fetchObject(); $to_sync[$analysis_id] = $analysis->name; } } // submit the job the tripal job manager if ($do_all) { tripal_add_job('Sync all analyses', 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid); } else{ foreach ($to_sync as $analysis_id => $name) { $job_args[0] = $analysis_id; tripal_add_job("Sync analysis: $name", 'tripal_analysis', 'tripal_analysis_sync_analyses', $job_args, $user->uid); } } } // ------------------------------------- // Submit the Cleanup Job if selected if ($form_state['values']['op'] == t('Clean up orphaned analyses')) { tripal_add_job('Cleanup orphaned analyses', 'tripal_analysis', 'tripal_analyses_cleanup', $job_args, $user->uid); } } /** * The "Clean-up orphaned analysis & nodes" Form * * @param $form * The administrative form as it is currently * * @return * A form API array describing an administrative form * * @ingroup tripal_analysis */ function get_tripal_analysis_admin_form_cleanup_set(&$form) { $form['cleanup'] = array( '#type' => 'fieldset', '#title' => t('Clean Up') ); $form['cleanup']['description'] = array( '#markup' => t("With Drupal and chado residing in different databases " . "it is possible that nodes in Drupal and analyses in Chado become " . "\"orphaned\". This can occur if an analysis node in Drupal is " . "deleted but the corresponding chado analysis is not and/or vice " . "versa. Click the button below to resolve these discrepancies."), '#weight' => 1, ); $form['cleanup']['button'] = array( '#type' => 'submit', '#value' => t('Clean up orphaned analyses'), '#weight' => 2, ); } /** * The "sync Analysis in chado with drupal" form * * @param $form * The administrative form as it is currently * * @return * A form API array describing an administrative form * * @ingroup tripal_analysis */ function get_tripal_analysis_admin_form_sync_set(&$form) { // define the fieldsets $form['sync'] = array( '#type' => 'fieldset', '#title' => t('Sync Analyses') ); // before proceeding check to see if we have any // currently processing jobs. If so, we don't want // to give the opportunity to sync analyses $active_jobs = FALSE; if (tripal_get_module_active_jobs('tripal_analysis')) { $active_jobs = TRUE; } if (!$active_jobs) { // get the list of analyses $sql = "SELECT * FROM {analysis} ORDER BY name"; $ana_rset = chado_query($sql); // if we've added any analyses to the list that can be synced // then we want to build the form components to allow the user // to select one or all of them. Otherwise, just present // a message stating that all analyses are currently synced. $ana_boxes = array(); $added = 0; while ($analysis = $ana_rset->fetchObject()) { // check to see if the analysis is already present as a node in drupal. // if so, then skip it. $sql = "SELECT * FROM {chado_analysis} WHERE analysis_id = :analysis_id"; if (!db_query($sql, array(':analysis_id' => $analysis->analysis_id))->fetchObject()) { $ana_boxes[$analysis->analysis_id] = "$analysis->name"; $added++; } } // if we have analyses we need to add to the checkbox then // build that form element if ($added > 0) { $ana_boxes['all'] = "All analyses"; $form['sync']['analyses'] = array( '#title' => t('Available analyses'), '#type' => t('checkboxes'), '#description' => t("Check the analyses you want to sync. Drupal " . "content will be created for each of the analyses listed above. " . "Select 'All analyses' to sync all of them."), '#required' => FALSE, '#prefix' => '