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
 
 $unescapeNewlines = false
 
 $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...
 
 parseBoolean ($value)
 Parse boolean value from string. More...
 
 associateLicensesWithMetadata ($cpPk, $licenses, $groupId=null)
 Associate licenses with a phrase, writing per-mapping metadata. More...
 
 associateLicenseNames ($cpPk, $licenseNames, $removing, $groupId=null)
 Legacy flat-format helper: split a license-name string/array and delegate to associateLicensesWithMetadata() so the two formats share one lookup/insert path. More...
 
 splitLicenseNames ($licenseNames)
 Split a delimited license-name string on the first separator found. More...
 

Detailed Description

Import custom text phrases from CSV/JSON.

Definition at line 26 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 73 of file CustomTextImport.php.

Member Function Documentation

◆ associateLicenseNames()

Fossology\Lib\Application\CustomTextImport::associateLicenseNames (   $cpPk,
  $licenseNames,
  $removing,
  $groupId = null 
)
private

Legacy flat-format helper: split a license-name string/array and delegate to associateLicensesWithMetadata() so the two formats share one lookup/insert path.

Parameters
int$cpPkcustom phrase PK
string | array$licenseNamesComma/semicolon/pipe separated names, or an array of names
bool$removing
int | null$groupId
Returns
array{inserted:int,failed:string[]}

Definition at line 497 of file CustomTextImport.php.

◆ associateLicensesWithMetadata()

Fossology\Lib\Application\CustomTextImport::associateLicensesWithMetadata (   $cpPk,
  $licenses,
  $groupId = null 
)
private

Associate licenses with a phrase, writing per-mapping metadata.

Looks licenses up by shortname within the importing group, so group-scoped candidate licenses resolve too (see LicenseDao::getLicenseByCondition()). An already-mapped license is counted as 'skipped', never 'inserted', so a caller can tell a real import apart from a no-op re-import of the same file.

Parameters
int$cpPkcustom phrase PK
array$licensesentries with shortname, removing, comment, reportinfo, acknowledgement
int | null$groupIdGroup to resolve candidate licenses against
Returns
array{inserted:int,skipped:int,failed:string[]}

Definition at line 436 of file CustomTextImport.php.

◆ 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 145 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 105 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 119 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 541 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 188 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 237 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 339 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 409 of file CustomTextImport.php.

◆ setDelimiter()

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

Update the delimiter.

Parameters
string$delimiterNew delimiter to use.

Definition at line 84 of file CustomTextImport.php.

◆ setEnclosure()

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

Update the enclosure.

Parameters
string$enclosureNew enclosure to use.

Definition at line 93 of file CustomTextImport.php.

◆ splitLicenseNames()

Fossology\Lib\Application\CustomTextImport::splitLicenseNames (   $licenseNames)
private

Split a delimited license-name string on the first separator found.

Parameters
string$licenseNames
Returns
string[]

Definition at line 525 of file CustomTextImport.php.

Member Data Documentation

◆ $alias

array Fossology\Lib\Application\CustomTextImport::$alias
protected
Initial value:
= array(
'text' => array('text', 'Text'),
'is_active' => array('is_active', 'Is Active', 'active'),
'created_by' => array('created_by', 'Created By', 'user_name'),
'group' => array('group', 'Group', 'group_name'),
'license_shortname' => array('license_shortname', 'License Shortname'),
'removing' => array('removing', 'Removing'),
'comment' => array('comment', 'Comment'),
'reportinfo' => array('reportinfo', 'License Text'),
'acknowledgement' => array('acknowledgement', 'Acknowledgement'),
'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 CSV headers

Definition at line 53 of file CustomTextImport.php.

◆ $dbManager

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

DB manager to use

Definition at line 30 of file CustomTextImport.php.

◆ $delimiter

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

Delimiter used in CSV

Definition at line 38 of file CustomTextImport.php.

◆ $enclosure

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

Enclosure used in CSV

Definition at line 41 of file CustomTextImport.php.

◆ $headrow

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

Header of CSV

Definition at line 44 of file CustomTextImport.php.

◆ $unescapeNewlines

bool Fossology\Lib\Application\CustomTextImport::$unescapeNewlines = false
protected

True for a CSV row, where real newlines were flattened to a literal '
' on export. JSON is never unescaped: it carries real newlines as-is.

Definition at line 50 of file CustomTextImport.php.

◆ $userDao

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

User DAO to use

Definition at line 33 of file CustomTextImport.php.


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