コード例 #1
0
 /**
  * Import metadata using a mapping
  *
  * @param RequestHTTP $po_request The current request
  * @param string $ps_source A path to a file or directory of files to import
  * @param string $ps_importer The code of the importer (mapping) to use
  * @param string $ps_input_format The format of the source data
  * @param array $pa_options
  *		progressCallback =
  *		reportCallback = 
  *		sendMail = 
  *		dryRun = 
  *		importAllDatasets = 
  *		log = log directory path
  *		logLevel = KLogger constant for minimum log level to record. Default is KLogger::INFO. Constants are, in descending order of shrillness:
  *			KLogger::EMERG = Emergency messages (system is unusable)
  *			KLogger::ALERT = Alert messages (action must be taken immediately)
  *			KLogger::CRIT = Critical conditions
  *			KLogger::ERR = Error conditions
  *			KLogger::WARN = Warnings
  *			KLogger::NOTICE = Notices (normal but significant conditions)
  *			KLogger::INFO = Informational messages
  *			KLogger::DEBUG = Debugging messages
  */
 public static function importMetadata($po_request, $ps_source, $ps_importer, $ps_input_format, $pa_options = null)
 {
     $va_errors = $va_noticed = array();
     $vn_start_time = time();
     $o_config = Configuration::load();
     if (!ca_data_importers::mappingExists($ps_importer)) {
         $va_errors['general'] = array('idno' => "*", 'label' => "*", 'errors' => array(_t('Importer %1 does not exist', $ps_importer)), 'status' => 'ERROR');
         return false;
     }
     $vs_log_dir = caGetOption('log', $pa_options, null);
     $vs_log_level = caGetOption('logLevel', $pa_options, "INFO");
     $vb_import_all_datasets = caGetOption('importAllDatasets', $pa_options, false);
     $vb_dry_run = caGetOption('dryRun', $pa_options, false);
     $vn_log_level = BatchProcessor::_logLevelStringToNumber($vs_log_level);
     if (!isURL($ps_source) && is_dir($ps_source)) {
         $va_sources = caGetDirectoryContentsAsList($ps_source, true, false, false, false);
     } else {
         $va_sources = array($ps_source);
     }
     $vn_file_num = 0;
     foreach ($va_sources as $vs_source) {
         $vn_file_num++;
         if (!ca_data_importers::importDataFromSource($vs_source, $ps_importer, array('fileNumber' => $vn_file_num, 'numberOfFiles' => sizeof($va_sources), 'logDirectory' => $o_config->get('batch_metadata_import_log_directory'), 'request' => $po_request, 'format' => $ps_input_format, 'showCLIProgressBar' => false, 'useNcurses' => false, 'progressCallback' => isset($pa_options['progressCallback']) ? $pa_options['progressCallback'] : null, 'reportCallback' => isset($pa_options['reportCallback']) ? $pa_options['reportCallback'] : null, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level, 'dryRun' => $vb_dry_run, 'importAllDatasets' => $vb_import_all_datasets))) {
             $va_errors['general'][] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Could not import source %1", $ps_source)), 'status' => 'ERROR');
             return false;
         } else {
             $va_notices['general'][] = array('idno' => "*", 'label' => "*", 'errors' => array(_t("Imported data from source %1", $ps_source)), 'status' => 'SUCCESS');
             //return true;
         }
     }
     $vn_elapsed_time = time() - $vn_start_time;
     if (isset($pa_options['sendMail']) && $pa_options['sendMail']) {
         if ($vs_email = trim($po_request->user->get('email'))) {
             caSendMessageUsingView($po_request, array($vs_email => $po_request->user->get('fname') . ' ' . $po_request->user->get('lname')), __CA_ADMIN_EMAIL__, _t('[%1] Batch metadata import completed', $po_request->config->get('app_display_name')), 'batch_metadata_import_completed.tpl', array('notices' => $va_notices, 'errors' => $va_errors, 'numErrors' => sizeof($va_errors), 'numProcessed' => sizeof($va_notices), 'subjectNameSingular' => _t('row'), 'subjectNamePlural' => _t('rows'), 'startedOn' => caGetLocalizedDate($vn_start_time), 'completedOn' => caGetLocalizedDate(time()), 'elapsedTime' => caFormatInterval($vn_elapsed_time)));
         }
     }
     if (isset($pa_options['sendSMS']) && $pa_options['sendSMS']) {
         SMS::send($po_request->getUserID(), _t("[%1] Metadata import processing for begun at %2 is complete", $po_request->config->get('app_display_name'), caGetLocalizedDate($vn_start_time)));
     }
     return array('errors' => $va_errors, 'notices' => $va_notices, 'processing_time' => caFormatInterval($vn_elapsed_time));
 }