Importer
in package
Uses
GetServiceTrait
VuFind CSV importer configuration
Tags
Table of Contents
- $configBaseDir : string
- Base path for loading .ini files
- $serviceLocator : ContainerInterface
- Service manager
- __construct() : mixed
- Constructor
- getService() : T
- Retrieve a service
- save() : string
- Save a CSV file to the Solr index using the specified configuration.
- adjustEncoding() : array<string|int, mixed>
- Fix the character encoding of a CSV line (if necessary).
- applyCallbacks() : array<string|int, string>
- Recursively apply callback functions to a value.
- collectValuesFromLine() : array<string|int, mixed>
- Collect field-specific values from a CSV input line. Returns an array mapping field name to value array.
- getConfiguration() : ImporterConfig
- Load and set up the configuration object.
- injectCallbackDependencies() : void
- Inject dependencies into the callback, if necessary.
- processCallback() : array<string|int, string>
- Apply a single callback to a single value.
- processConfiguration() : ImporterConfig
- Determine the list of fields that will be loaded.
- processHeader() : void
- Process the header row, and generate a configuration.
- processValues() : array<string|int, string>
- Process the values from a single column of a CSV.
- writeData() : string
- Write a batch of JSON data to Solr.
Properties
$configBaseDir
Base path for loading .ini files
protected
string
$configBaseDir
$serviceLocator
Service manager
protected
ContainerInterface
$serviceLocator
Methods
__construct()
Constructor
public
__construct(ServiceLocatorInterface $sm[, array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $sm : ServiceLocatorInterface
-
Service manager
- $options : array<string|int, mixed> = []
-
Configuration options
Return values
mixed —getService()
Retrieve a service
public
getService(class-string<\VuFind\Service\T> $name) : T
Parameters
- $name : class-string<\VuFind\Service\T>
-
Name of service to retrieve
Tags
Return values
T —save()
Save a CSV file to the Solr index using the specified configuration.
public
save(string $csvFile, string $iniFile[, string $index = 'Solr' ][, bool $testMode = false ]) : string
Parameters
- $csvFile : string
-
CSV file to load.
- $iniFile : string
-
INI file.
- $index : string = 'Solr'
-
Solr index to use.
- $testMode : bool = false
-
Are we in test-only mode?
Tags
Return values
string —Output for test mode
adjustEncoding()
Fix the character encoding of a CSV line (if necessary).
protected
adjustEncoding(array<string|int, mixed> $line, string $encoding) : array<string|int, mixed>
Parameters
- $line : array<string|int, mixed>
-
Input from CSV
- $encoding : string
-
Encoding of $line
Return values
array<string|int, mixed> —Input re-encoded as UTF-8 (if not already in UTF-8)
applyCallbacks()
Recursively apply callback functions to a value.
protected
applyCallbacks(string $value, array<string|int, string> $callbacks, array<string|int, mixed> $fieldValues) : array<string|int, string>
Parameters
- $value : string
-
Value to process
- $callbacks : array<string|int, string>
-
List of callback functions
- $fieldValues : array<string|int, mixed>
-
Field values processed so far
Return values
array<string|int, string> —collectValuesFromLine()
Collect field-specific values from a CSV input line. Returns an array mapping field name to value array.
protected
collectValuesFromLine(array<string|int, mixed> $line, ImporterConfig $config) : array<string|int, mixed>
Parameters
- $line : array<string|int, mixed>
-
Line to process.
- $config : ImporterConfig
-
Configuration object.
Return values
array<string|int, mixed> —getConfiguration()
Load and set up the configuration object.
protected
getConfiguration(string $iniFile, resource $in) : ImporterConfig
Parameters
- $iniFile : string
-
Name of .ini file to load
- $in : resource
-
File handle to input file
Tags
Return values
ImporterConfig —injectCallbackDependencies()
Inject dependencies into the callback, if necessary.
protected
injectCallbackDependencies(string $callable) : void
Parameters
- $callable : string
-
Callback function
Return values
void —processCallback()
Apply a single callback to a single value.
protected
processCallback(string $callback, string $value, array<string|int, mixed> $fieldValues) : array<string|int, string>
Parameters
- $callback : string
-
Callback string from config
- $value : string
-
Value to process
- $fieldValues : array<string|int, mixed>
-
Field values processed so far
Return values
array<string|int, string> —processConfiguration()
Determine the list of fields that will be loaded.
protected
processConfiguration(array<string|int, mixed> $options, resource $in) : ImporterConfig
Parameters
- $options : array<string|int, mixed>
-
Configuration
- $in : resource
-
File handle to input file
Tags
Return values
ImporterConfig —processHeader()
Process the header row, and generate a configuration.
protected
processHeader(ImporterConfig $config, resource $in, string $mode) : void
Parameters
- $config : ImporterConfig
-
Configuration to be updated
- $in : resource
-
File handle to CSV
- $mode : string
-
Header processing mode (fields/none/skip)
Return values
void —processValues()
Process the values from a single column of a CSV.
protected
processValues(array<string|int, string> $values, array<string|int, mixed> $fieldConfig, array<string|int, mixed> $fieldValues) : array<string|int, string>
Parameters
- $values : array<string|int, string>
-
Values to process
- $fieldConfig : array<string|int, mixed>
-
Configuration to apply to values
- $fieldValues : array<string|int, mixed>
-
Field values processed so far
Return values
array<string|int, string> —writeData()
Write a batch of JSON data to Solr.
protected
writeData(array<string|int, mixed> $data, string $index, bool $testMode) : string
Parameters
- $data : array<string|int, mixed>
-
Data to write
- $index : string
-
Target Solr index
- $testMode : bool
-
Are we in test mode?
Return values
string —Test mode output (if applicable) or empty string