class LabelTreeImport extends Import

Properties

protected string $path

Path to the directory with the import files.

from  Import
protected Collection|null $importLabelTrees

Caches the decoded label tree import file.

protected UserImport|null $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

in Import at line 23
__construct(string $path)

Create a new instance.

Parameters

string $path

Path to the directory with the import files.

in Import at line 33
bool filesMatch()

Check if this import matches to the given import files.

Return Value

bool

in Import at line 48
validateFiles()

Check if the files of this import are valid.

Exceptions

Exception

at line 191
protected array expectedFiles()

The files expected by this import.

Return Value

array

in Import at line 70
protected array files()

Get the basename of each file of this import.

Return Value

array

at line 202
protected validateFile(string $basename)

Validate a file of this import.

Parameters

string $basename

Basename of the file.

Exceptions

Exception

in Import at line 96
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

in Import at line 122
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

in Import at line 146
protected Collection 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 line 41
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 line 78
Collection getImportLabelTrees()

Get the contents of the label tree import file.

Return Value

Collection

at line 92
Collection getLabelTreeImportCandidates()

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

Return Value

Collection

at line 108
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 line 183
Collection getUserImportCandidates()

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

Return Value

Collection

at line 229
protected UserImport getUserImport()

Get the user import instance that belongs to this import.

Return Value

UserImport

at line 245
protected Collection 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 line 278
protected array 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 line 302
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 line 325
protected array 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 line 344
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 line 376
protected Collection 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 line 403
protected array 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 line 442
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 line 465
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.