class LabelTreeImport extendsImport

Properties

protectedstring $path Path to the directory with the import files. from Import
protectedCollection $importLabelTrees Caches the decoded label tree import file.
protectedUserImport $userImport The user import instance that belongs to this import.

Methods

__construct(string$path)

Create a new instance.

from Import
bool
filesMatch()

Check if this import matches to the given import files.

from Import
validateFiles()

Check if the files of this import are valid.

from Import
array
expectedFiles()

The files expected by this import.

array
files()

Get the basename of each file of this import.

from Import
validateFile(string$basename)

Validate a file of this import.

expectKeysInJson(string$file,array$expectation,bool$array =true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

from Import
expectColumnsInCsv(string$file,array$expectation)

Validates a CSV file to contain the expected columns.

from Import
Collection
collectJson(string$file)

Read a JSON file containing an array and wrap it in a Laravel collection.

from Import
array
perform(array$onlyTrees =null,array$onlyLabels =null,array$nameConflictResolution =[],array$parentConflictResolution =[])

Perform the import.

Collection
getImportLabelTrees()

Get the contents of the label tree import file.

Collection
getLabelTreeImportCandidates()

Get label trees that can be imported and don't already exist.

Collection
getLabelImportCandidates()

Get labels of existing label trees that can be imported.

Collection
getUserImportCandidates()

Get users who might be implicitly imported along with a label tree.

getUserImport()

Get the user import instance that belongs to this import.

Collection
getInsertLabelTrees(array|null$onlyTrees)

Get the array that can be used to insert the label trees that should be imported.

array
insertLabelTrees(Collection$trees)

Insert label trees that should be imported in the database.

insertLabelTreeVersions(Collection$insertTrees,array$labelTreeIdMap)

Create label tree versions for imported versioned label trees.

array
getInsertUserIds(Collection$trees)

Get IDs of label tree admins that should be imported.

attachLabelTreeMembers(Collection$trees,array$labelTreeIdMap,array$userIdMap)

Attach members to imported label trees.

Collection
getInsertLabels(array|null$onlyLabels,array$labelTreeIdMap)

Get the array that can be used to insert the labels that should be imported.

array
insertLabels(Collection$labels,array$labelTreeIdMap)

Insert labels that should be imported in the database.

updateInsertedLabelParentIds(Collection$labels,array$labelIdMap)

Update/set the parent_id of imported labels.

mergeLabels(Collection$mergeLabels,array$nameConflictResolution,array$parentConflictResolution,array$labelIdMap)

Merge conflicts between import labels and existing labels.

Details

inImportat line23
__construct(string$path)

Create a new instance.

Parameters

string $path Path to the directory with the import files.

inImportat line33
bool filesMatch()

Check if this import matches to the given import files.

Return Value

bool

inImportat line48
validateFiles()

Check if the files of this import are valid.

Exceptions

Exception If any of the import files is invalid.

at line193
protectedarray expectedFiles()

The files expected by this import.

Return Value

array

inImportat line70
protectedarray files()

Get the basename of each file of this import.

Return Value

array

at line204
protected validateFile(string$basename)

Validate a file of this import.

Parameters

string $basename Basename of the file.

Exceptions

Exception If the file is invalid.

inImportat line98
protected expectKeysInJson(string$file,array$expectation,bool$array =true)

Validates a JSON file to contain an array of objects, each of which has all the expected keys.

Parameters

string $file File name under $this->path
array $expectation Expected keys.
bool $array Specifies if the file to validate contains an array or not.

Exceptions

Exception If keys are missing.

inImportat line124
protected expectColumnsInCsv(string$file,array$expectation)

Validates a CSV file to contain the expected columns.

Parameters

string $file File name under $this->path
array $expectation Expected columns.

Exceptions

Exception If columns are missing.

inImportat line148
protectedCollection collectJson(string$file)

Read a JSON file containing an array and wrap it in a Laravel collection.

Parameters

string $file File name under $this->path

Return Value

Collection

at line42
array perform(array$onlyTrees =null,array$onlyLabels =null,array$nameConflictResolution =[],array$parentConflictResolution =[])

Perform the import.

Parameters

array $onlyTrees IDs of the label tree import candidates to limit the import to.
array $onlyLabels IDs of the label import candidates to limit the import to.
array $nameConflictResolution Array mapping label IDs to 'import' or 'existing' for how to resolve name conflicts.
array $parentConflictResolution Array mapping label IDs to 'import' or 'existing' for how to resolve parent conflicts.

Return Value

array Array containing 'labelTrees', 'labels' and 'users', mapping external IDs (from the import file) to IDs of the database.

at line81
Collection getImportLabelTrees()

Get the contents of the label tree import file.

Return Value

Collection

at line95
Collection getLabelTreeImportCandidates()

Get label trees that can be imported and don't already exist.

Return Value

Collection

at line111
Collection getLabelImportCandidates()

Get labels of existing label trees that can be imported.

If an import label exists but has a conflicting name or parent_id, it will get the additional conflicting_name and/or conflicting_parent_id attributes.

Return Value

Collection

at line185
Collection getUserImportCandidates()

Get users who might be implicitly imported along with a label tree.

Return Value

Collection

at line231
protectedUserImport getUserImport()

Get the user import instance that belongs to this import.

Return Value

UserImport

at line247
protectedCollection getInsertLabelTrees(array|null$onlyTrees)

Get the array that can be used to insert the label trees that should be imported.

Parameters

array|null $onlyTrees IDs of the label tree import candidates to limit the import to

Return Value

Collection

at line285
protectedarray insertLabelTrees(Collection$trees)

Insert label trees that should be imported in the database.

Parameters

Collection $trees Label trees to insert.

Return Value

array Map of import label tree IDs to existing label tree IDs.

at line309
protected insertLabelTreeVersions(Collection$insertTrees,array$labelTreeIdMap)

Create label tree versions for imported versioned label trees.

Parameters

Collection $insertTrees Label trees that have been imported.
array $labelTreeIdMap Map of import label trees to existing label trees.

at line333
protectedarray getInsertUserIds(Collection$trees)

Get IDs of label tree admins that should be imported.

Parameters

Collection $trees Label trees that have been imported.

Return Value

array

at line354
protected attachLabelTreeMembers(Collection$trees,array$labelTreeIdMap,array$userIdMap)

Attach members to imported label trees.

Parameters

Collection $trees Imported label trees
array $labelTreeIdMap Map of import label trees to existing label trees.
array $userIdMap Map of import users to existing users.

at line388
protectedCollection getInsertLabels(array|null$onlyLabels,array$labelTreeIdMap)

Get the array that can be used to insert the labels that should be imported.

Parameters

array|null $onlyLabels IDs of the label import candidates to limit the import to.
array $labelTreeIdMap Map of import label tree IDs to existing label tree IDs.

Return Value

Collection

at line417
protectedarray insertLabels(Collection$labels,array$labelTreeIdMap)

Insert labels that should be imported in the database.

Parameters

Collection $labels The labels to insert
array $labelTreeIdMap Map of import label tree IDs to existing label tree IDs

Return Value

array Map of import label IDs to existing label IDs.

at line456
protected updateInsertedLabelParentIds(Collection$labels,array$labelIdMap)

Update/set the parent_id of imported labels.

Parameters

Collection $labels Labels to update the parent_id of.
array $labelIdMap Map of import label IDs to existing label IDs.

at line478
protected mergeLabels(Collection$mergeLabels,array$nameConflictResolution,array$parentConflictResolution,array$labelIdMap)

Merge conflicts between import labels and existing labels.

Parameters

Collection $mergeLabels Import labels to merge.
array $nameConflictResolution
array $parentConflictResolution
array $labelIdMap Map of import label IDs to existing label IDs.