public function transform($rec) { global $mab_field_map; $r = array(); foreach ($mab_field_map as $field => $items) { foreach ($items as $item) { if ($this->fieldPrefix) { $item = fieldPrefix + $item; } if (!empty($rec[$item])) { if (is_array($rec[$item])) { if (empty($r[$field])) { $r[$field] = $rec[$item]; } else { $r[$field] = array_merge($r[$field], $rec[$item]); } } else { $r[$field][] = $rec[$item]; } break; } } } foreach ($r as $f => $values) { if (count($values) == 0) { unset($r[$f]); } elseif (count($values) == 1) { $r[$f] = MAB2RecordTransformer::mangleValue($values[0]); } else { $values = array_unique($values); $values = array_map(array('MAB2RecordTransformer', 'mangleValue'), $values); $r[$f] = join(', ', $values); } } return $r; }
public function execute() { global $wgDataTransclusionSources; $this->debug = $this->hasOption('debug'); $this->noblob = $this->hasOption('noblob'); $recursive = $this->hasOption('recursive'); $limit = (int) $this->getOption('limit'); $this->recordSeparator = $this->getOption('record-separator'); $this->multiRecord = $this->recordSeparator || $this->hasOption('multi-record'); $this->idListField = $this->getOption('id-list-field'); $this->idListFile = $this->getOption('id-list-file'); $this->idList = null; $src = $this->mArgs[0]; $dir = $this->mArgs[1]; if (!isset($wgDataTransclusionSources[$src])) { throw new MWException("unknown transclusion data source '{$src}', not found in \$wgDataTransclusionSources"); } $this->output("using settings for data transclusion source \"{$src}\".\n"); $this->source = DataTransclusionHandler::getDataSource($src); if (!$this->source instanceof DBDataTransclusionSource) { throw new MWException("bad data source '{$src}': not compatible with DBDataTransclusionSource"); } $this->blob_table = $this->mArgs[2]; $this->index_table = $this->mArgs[3]; if ($this->hasOption('prefix')) { $prefix = $this->getOption("prefix"); $this->blob_table = $prefix . $this->blob_table; $this->index_table = $prefix . $this->index_table; } else { $db = wfGetDB(DB_MASTER); # we'll need the master anyway later $this->blob_table = $db->tableName($this->blob_table); $this->index_table = $db->tableName($this->index_table); } if (!$this->debug) { $this->output("using tables {$this->blob_table} and {$this->index_table}.\n"); if ($this->hasOption('create')) { $this->output("creating tables if neccessary.\n"); $this->createTables($this->blob_table, $this->index_table); } if ($this->hasOption('truncate')) { $this->output("truncating tables.\n"); $this->truncateTables($this->blob_table, $this->index_table); } } $this->id_map = array(); foreach ($this->source->keyFields as $key) { $this->id_map[$key] = MAB2RecordTransformer::getMABFields($key); if (!$this->id_map[$key]) { $this->error("unknown key field '{$key}', no MAB fields mapped.\n"); } } if ($this->idListFile) { $this->output("loading id list from {$this->idListFile}.\n"); $this->idList = $this->loadList($this->idListFile, $this->idListField); if ($this->idList === false) { $this->error("failed to load id list from {$this->idListFile}.\n"); return; } } if ($this->idList && $this->idListField) { $this->output("filtering by {$this->idListField} from {$this->idListFile}.\n"); } $dir = "php://stdin"; if (is_dir($dir)) { $this->importDir($dir, $recursive, $limit); } else { $this->importMabFile($dir); } }