예제 #1
0
 /**
  * @param Zend_Console_Getopt|null $po_opts
  * @return bool
  */
 public static function reload_ulan_records($po_opts = null)
 {
     require_once __CA_MODELS_DIR__ . '/ca_data_importers.php';
     if (!($vs_mapping = $po_opts->getOption('mapping'))) {
         CLIUtils::addError("\t\tNo mapping found. Please use the -m parameter to specify a ULAN mapping.");
         return false;
     }
     if (!ca_data_importers::mappingExists($vs_mapping)) {
         CLIUtils::addError("\t\tMapping {$vs_mapping} does not exist");
         return false;
     }
     $vs_log_dir = $po_opts->getOption('log');
     $vn_log_level = CLIUtils::getLogLevel($po_opts);
     $o_db = new Db();
     $qr_items = $o_db->query("\n\t\t\t\tSELECT DISTINCT source FROM ca_data_import_events WHERE type_code = 'ULAN'\n\t\t\t");
     $va_sources = array();
     while ($qr_items->nextRow()) {
         $vs_source = $qr_items->get('source');
         if (!isURL($vs_source)) {
             continue;
         }
         if (!preg_match("/http\\:\\/\\/vocab\\.getty\\.edu\\/ulan\\//", $vs_source)) {
             continue;
         }
         $va_sources[] = $vs_source;
     }
     ca_data_importers::importDataFromSource(join(',', $va_sources), $vs_mapping, array('format' => 'ULAN', 'showCLIProgressBar' => true, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level));
     return true;
 }
예제 #2
0
 public static function export_data($po_opts = null)
 {
     require_once __CA_MODELS_DIR__ . "/ca_data_exporters.php";
     $vs_search = $po_opts->getOption('search');
     $vs_id = $po_opts->getOption('id');
     $vb_rdf = (bool) $po_opts->getOption('rdf');
     if (!$vb_rdf && !$vs_search && !$vs_id) {
         print _t('You must specify either an idno or a search expression to select a record or record set for export or activate RDF mode.') . "\n";
         return false;
     }
     if (!($vs_filename = $po_opts->getOption('file'))) {
         print _t('You must specify a file to write export output to.') . "\n";
         return false;
     }
     if (@file_put_contents($vs_filename, "") === false) {
         // probably a permission error
         print _t("Can't write to file %1. Check the permissions.", $vs_filename) . "\n";
         return false;
     }
     $vs_log_dir = $po_opts->getOption('log');
     $vn_log_level = CLIUtils::getLogLevel($po_opts);
     // RDF mode
     if ($vb_rdf) {
         if (!($vs_config = $po_opts->getOption('config'))) {
             print _t('You must specify a configuration file that contains the export definition for the RDF mode.') . "\n";
             return false;
         }
         // test config syntax
         if (!Configuration::load($vs_config)) {
             print _t('Syntax error in configuration file %s.', $vs_config) . "\n";
             return false;
         }
         if (ca_data_exporters::exportRDFMode($vs_config, $vs_filename, array('showCLIProgressBar' => true, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level))) {
             print _t("Exported data to %1", CLIUtils::textWithColor($vs_filename, 'yellow'));
             return true;
         } else {
             print _t("Could not run RDF mode export") . "\n";
             return false;
         }
     }
     // Search or ID mode
     if (!($vs_mapping = $po_opts->getOption('mapping'))) {
         print _t('You must specify a mapping for export.') . "\n";
         return false;
     }
     if (!ca_data_exporters::loadExporterByCode($vs_mapping)) {
         print _t('Mapping %1 does not exist', $vs_mapping) . "\n";
         return false;
     }
     if (sizeof($va_errors = ca_data_exporters::checkMapping($vs_mapping)) > 0) {
         print _t("Mapping %1 has errors: %2", $vs_mapping, join("; ", $va_errors)) . "\n";
         return false;
     }
     if ($vs_search) {
         if (!ca_data_exporters::exportRecordsFromSearchExpression($vs_mapping, $vs_search, $vs_filename, array('showCLIProgressBar' => true, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level))) {
             print _t("Could not export mapping %1", $vs_mapping) . "\n";
             return false;
         } else {
             print _t("Exported data to %1", $vs_filename) . "\n";
         }
     } else {
         if ($vs_id) {
             if ($vs_export = ca_data_exporters::exportRecord($vs_mapping, $vs_id, array('singleRecord' => true, 'logDirectory' => $vs_log_dir, 'logLevel' => $vn_log_level))) {
                 file_put_contents($vs_filename, $vs_export);
                 print _t("Exported data to %1", CLIUtils::textWithColor($vs_filename, 'yellow'));
             } else {
                 print _t("Could not export mapping %1", $vs_mapping) . "\n";
                 return false;
             }
         }
     }
 }