/[drupal]/contributions/modules/import/import.module
ViewVC logotype

Diff of /contributions/modules/import/import.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.19, Wed Apr 8 21:42:11 2009 UTC revision 1.20, Wed Apr 8 23:33:18 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: import.module,v 1.18 2008/10/31 18:14:27 cyberswat Exp $  // $Id: import.module,v 1.19 2009/04/08 21:42:11 cyberswat Exp $
3    
4  /**  /**
5   * invokes hook_import()   * invokes hook_import()
# Line 69  function import_stage($args) { Line 69  function import_stage($args) {
69   */   */
70  function import_pass($data, $msg='') {  function import_pass($data, $msg='') {
71    db_query("INSERT INTO {import_pass} VALUES('%s', '%s')", $data->impid, $data->type);    db_query("INSERT INTO {import_pass} VALUES('%s', '%s')", $data->impid, $data->type);
72    db_query("DELETE from {import} where impid = '%s'", $data->impid);    db_query("DELETE from {import} where impid = '%s' AND type = '%s'", $data->impid,  $data->type);
73  }  }
74    
75  /**  /**
# Line 83  function import_pass($data, $msg='') { Line 83  function import_pass($data, $msg='') {
83   */   */
84  function import_fail($data, $msg='') {  function import_fail($data, $msg='') {
85    db_query("INSERT INTO {import_fail} VALUES('%s','%s','%s')", $data->impid, $data->type, $msg);    db_query("INSERT INTO {import_fail} VALUES('%s','%s','%s')", $data->impid, $data->type, $msg);
86    db_query("DELETE from {import} where impid = '%s'", $data->impid);    db_query("DELETE from {import} where impid = '%s' AND type = '%s'", $data->impid,  $data->type);
87  }  }
88    
89  /**  /**
# Line 95  function import_admin_form() { Line 95  function import_admin_form() {
95      '#value' => t('Stage Data for Import'),      '#value' => t('Stage Data for Import'),
96      '#executes_submit_callback' => TRUE      '#executes_submit_callback' => TRUE
97    );    );
98    $form['process'] = array(  
99      '#type' => 'button',    // only display the import buttons if there is something staged for import
100      '#value' => t('Process Import'),    $import = db_query("SELECT DISTINCT type from {import}");
101      '#executes_submit_callback' => TRUE    $types = array();
102    );    while ($row = db_fetch_object($import)) {
103        $types[] = $row->type;
104      }
105      if (count($types) > 0) {
106        foreach ($types as $type) {
107          $form['process_'. $type] = array(
108            '#type' => 'button',
109            '#value' => t('Process') .' '. $type,
110            '#executes_submit_callback' => TRUE
111          );
112        }
113      }
114    return $form;    return $form;
115  }  }
116    
# Line 107  function import_admin_form() { Line 118  function import_admin_form() {
118   * Submit handler for the import_admin_form   * Submit handler for the import_admin_form
119   */   */
120  function import_admin_form_submit($form, &$form_state) {  function import_admin_form_submit($form, &$form_state) {
121    $import = db_fetch_object(db_query("SELECT count(impid) as total FROM {import}"));  
122    if ($form_state['clicked_button']['#value'] == t('Stage Data for Import')) {    if ($form_state['clicked_button']['#value'] == t('Stage Data for Import')) {
123      import_stage_import();      import_stage_import();
124      $import = db_fetch_object(db_query("SELECT count(impid) as total FROM {import}"));      $import = db_fetch_object(db_query("SELECT count(impid) as total FROM {import}"));
125      drupal_set_message(t('%total items are staged for Import', array('%total' => $import->total)));      drupal_set_message(t('%total items are staged for Import', array('%total' => $import->total)));
126    }    }
127    elseif ($form_state['clicked_button']['#value'] == t('Process Import')) {    else {
128        $type_array = explode(' ', $form_state['clicked_button']['#value']);
129        $type = array_pop($type_array);
130        $import = db_fetch_object(db_query("SELECT count(impid) as total FROM {import} WHERE type = '%s'", $type));
131      if($import->total > 0) {      if($import->total > 0) {
132        $operations = array();        $operations = array();
133        $result = db_query("Select impid, type from {import}");        $result = db_query("Select impid, type from {import} WHERE type = '%s'", $type);
134        while ($row = db_fetch_object($result)) {        while ($row = db_fetch_object($result)) {
135           $operations[] = array('import_process_import', array($row));           $operations[] = array('import_process_import', array($row));
136        }        }
137        $batch = array(        $batch = array(
138          'operations' => $operations,          'operations' => $operations,
139          'title' => t('Importing'),          'title' => t('Importing'),
140          'init_message' => t('Import is starting to process %total items', array('%total' => $import->total)),          'init_message' => t('Import is starting to process %total %type items', array('%total' => $import->total, '%type' => $type)),
141          'progress_message' => t('Processed @current out of @total.'),          'progress_message' => t('Processed @current out of @total.'),
142          'error_message' => t('Import has encountered an error.'),          'error_message' => t('Import has encountered an error.'),
143        );        );

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

  ViewVC Help
Powered by ViewVC 1.1.2