FOSSology  4.7.1
Open Source License Compliance by Open Source Software
Fossology\Lib\Application\CustomTextImport Class Reference

Import custom text phrases from CSV/JSON. More...

Collaboration diagram for Fossology\Lib\Application\CustomTextImport:
Collaboration graph

Public Member Functions

 __construct (DbManager $dbManager, UserDao $userDao, LicenseDao $licenseDao=null)
 
 setDelimiter ($delimiter=',')
 Update the delimiter. More...
 
 setEnclosure ($enclosure='"')
 Update the enclosure. More...
 
 handleFile ($filename, $fileExtension)
 Read the CSV/JSON file and import it. More...
 
 importJsonData ($data, string &$msg)
 Import JSON data directly. More...
 

Protected Attributes

 $dbManager
 
 $userDao
 
 $licenseDao
 
 $delimiter = ','
 
 $enclosure = '"'
 
 $headrow = null
 
 $alias
 

Private Member Functions

 handleJsonFile ($filename)
 Handle JSON file import. More...
 
 handleCsvFile ($filename)
 Handle CSV file import. More...
 
 importPhrases ($data)
 Import phrases from data array. More...
 
 importSinglePhrase ($phraseData)
 Import a single phrase. More...
 
 mapHeaders ($data)
 Map CSV headers to standard field names. More...
 
 normalizeBulkExportValues ($mapped)
 Normalize values from bulk text export format. More...
 
 parseBoolean ($value)
 Parse boolean value from string. More...
 
 associateLicenses ($cpPk, $licenseNames, $removing=false, $allowCreate=false)
 
 isValidLicenseShortname ($shortname)
 Validate a license shortname before auto-creating it. More...
 

Detailed Description

Import custom text phrases from CSV/JSON.

Definition at line 27 of file CustomTextImport.php.

Constructor & Destructor Documentation

◆ __construct()

Fossology\Lib\Application\CustomTextImport::__construct ( DbManager  $dbManager,
UserDao  $userDao,
LicenseDao  $licenseDao = null 
)
Parameters
DbManager$dbManager
UserDao$userDao
LicenseDao$licenseDaoFalls back to DI container when null.

Definition at line 64 of file CustomTextImport.php.

Member Function Documentation

◆ handleCsvFile()

Fossology\Lib\Application\CustomTextImport::handleCsvFile (   $filename)
private

Handle CSV file import.

Parameters
string$filenameLocation of the CSV file.
Returns
string message

Definition at line 134 of file CustomTextImport.php.

◆ handleFile()

Fossology\Lib\Application\CustomTextImport::handleFile (   $filename,
  $fileExtension 
)

Read the CSV/JSON file and import it.

Parameters
string$filenameLocation of the file.
string$fileExtensionFile extension (csv or json)
Returns
string message Error message, if any. Otherwise Read file: <count> phrases on success.

Definition at line 96 of file CustomTextImport.php.

◆ handleJsonFile()

Fossology\Lib\Application\CustomTextImport::handleJsonFile (   $filename)
private

Handle JSON file import.

Parameters
string$filenameLocation of the JSON file.
Returns
string message

Definition at line 110 of file CustomTextImport.php.

◆ importJsonData()

Fossology\Lib\Application\CustomTextImport::importJsonData (   $data,
string &  $msg 
)

Import JSON data directly.

Parameters
array$dataDecoded JSON array
string$msgPopulated with the result message
Returns
string Result message

Definition at line 469 of file CustomTextImport.php.

◆ importPhrases()

Fossology\Lib\Application\CustomTextImport::importPhrases (   $data)
private

Import phrases from data array.

Parameters
array$dataArray of phrase data
Returns
string message

Definition at line 175 of file CustomTextImport.php.

◆ importSinglePhrase()

Fossology\Lib\Application\CustomTextImport::importSinglePhrase (   $phraseData)
private

Import a single phrase.

Parameters
array$phraseDataPhrase data
Returns
array Result with success flag and message

Definition at line 206 of file CustomTextImport.php.

◆ isValidLicenseShortname()

Fossology\Lib\Application\CustomTextImport::isValidLicenseShortname (   $shortname)
private

Validate a license shortname before auto-creating it.

Parameters
string$shortnameLicense shortname to validate
Returns
bool True if valid, false otherwise

Definition at line 443 of file CustomTextImport.php.

◆ mapHeaders()

Fossology\Lib\Application\CustomTextImport::mapHeaders (   $data)
private

Map CSV headers to standard field names.

Parameters
array$dataRow data
Returns
array Mapped data

Definition at line 288 of file CustomTextImport.php.

◆ normalizeBulkExportValues()

Fossology\Lib\Application\CustomTextImport::normalizeBulkExportValues (   $mapped)
private

Normalize values from bulk text export format.

The bulk text export produces arrays (JSON) or pipe-separated strings (CSV) for acknowledgements and comments. This method joins them into single strings suitable for the custom_phrase table. It also restores literal '\n' escape sequences (produced by the bulk CSV exporter) back to real newlines in the text field.

Parameters
array$mappedMapped data
Returns
array Normalized data

Definition at line 319 of file CustomTextImport.php.

◆ parseBoolean()

Fossology\Lib\Application\CustomTextImport::parseBoolean (   $value)
private

Parse boolean value from string.

Parameters
string$valueString value
Returns
bool Boolean value

Definition at line 347 of file CustomTextImport.php.

◆ setDelimiter()

Fossology\Lib\Application\CustomTextImport::setDelimiter (   $delimiter = ',')

Update the delimiter.

Parameters
string$delimiterNew delimiter to use.

Definition at line 75 of file CustomTextImport.php.

◆ setEnclosure()

Fossology\Lib\Application\CustomTextImport::setEnclosure (   $enclosure = '"')

Update the enclosure.

Parameters
string$enclosureNew enclosure to use.

Definition at line 84 of file CustomTextImport.php.

Member Data Documentation

◆ $alias

array Fossology\Lib\Application\CustomTextImport::$alias
protected
Initial value:
= array(
'text'=>array('text','Text'),
'acknowledgement'=>array('acknowledgement','Acknowledgement','acknowledgements'),
'comments'=>array('comments','Comments'),
'is_active'=>array('is_active','Is Active','active'),
'created_by'=>array('created_by','Created By','user_name'),
'group'=>array('group','Group','group_name'),
'licenses_to_add'=>array('licenses_to_add','Licenses To Add','add_licenses'),
'licenses_to_remove'=>array('licenses_to_remove','Licenses To Remove','remove_licenses')
)

Alias for headers

Definition at line 48 of file CustomTextImport.php.

◆ $dbManager

DbManager Fossology\Lib\Application\CustomTextImport::$dbManager
protected

DB manager to use

Definition at line 31 of file CustomTextImport.php.

◆ $delimiter

string Fossology\Lib\Application\CustomTextImport::$delimiter = ','
protected

Delimiter used in CSV

Definition at line 39 of file CustomTextImport.php.

◆ $enclosure

string Fossology\Lib\Application\CustomTextImport::$enclosure = '"'
protected

Enclosure used in CSV

Definition at line 42 of file CustomTextImport.php.

◆ $headrow

null array Fossology\Lib\Application\CustomTextImport::$headrow = null
protected

Header of CSV

Definition at line 45 of file CustomTextImport.php.

◆ $userDao

UserDao Fossology\Lib\Application\CustomTextImport::$userDao
protected

User DAO to use

Definition at line 34 of file CustomTextImport.php.


The documentation for this class was generated from the following file: