Documentation

WordUploadService

Service class for importing words/terms from files or text input.

Handles parsing and importing terms in various formats (CSV, TSV, hash-delimited).

Tags
category

Lwt

author

HugoFara hugo.farajallah@protonmail.com

license

Unlicense http://unlicense.org/

link
https://hugofara.github.io/lwt/docs/php/
since
3.0.0

Table of Contents

Constants

BATCH_SIZE  = 500
Maximum number of rows to insert in a single batch.

Methods

countImportedTerms()  : int
Count imported terms.
createTempFile()  : string
Create a temporary file from text input.
getDelimiter()  : string
Get delimiter character from tab type.
getImportedTerms()  : array<string|int, mixed>
Get imported terms for display.
getLanguageData()  : array<string|int, mixed>|null
Get language data for a specific language.
getLastWordUpdate()  : string|null
Get the last word status change timestamp.
getSqlDelimiter()  : string
Get delimiter for SQL LOAD DATA statement.
handleMultiwords()  : void
Handle multi-word expressions after import.
importComplete()  : void
Import terms with complete processing (handles tags, overwrite modes).
importSimple()  : void
Import terms using simple import (no tags, no overwrite).
importTagsOnly()  : void
Import tags only (no terms).
isLocalInfileEnabled()  : bool
Check if local infile is enabled in MySQL and PHP.
isRightToLeft()  : bool
Get right-to-left setting for a language.
linkWordsToTextItems()  : void
Link imported words to text items.
parseColumnMapping()  : array{columns: array, fields: array{txt: int, tr: int, ro: int, se: int, tl: int}}
Parse column mapping from request.
cleanupTempTables()  : void
Cleanup temporary tables.
executeMainImportQuery()  : void
Execute the main import/update query based on overwrite mode.
executeSimpleImportBatch()  : void
Execute a batch insert for simple import.
executeTempTableBatch()  : void
Execute a batch insert for temp table import.
handleTagsImport()  : void
Handle tags import.
handleTranslationMerge()  : void
Handle translation merging for overwrite modes 4 and 5.
importSimpleWithLoadData()  : void
Import terms using LOAD DATA LOCAL INFILE.
importSimpleWithPHP()  : void
Import terms using PHP parsing (fallback when LOAD DATA not available).
initTempTables()  : void
Initialize temporary tables for import.
loadDataToTempTable()  : void
Load data into temporary table using LOAD DATA.
loadDataToTempTableWithPHP()  : void
Load data into temporary table using PHP (fallback).

Constants

BATCH_SIZE

Maximum number of rows to insert in a single batch.

private mixed BATCH_SIZE = 500

Keeps memory usage reasonable for large imports.

Methods

countImportedTerms()

Count imported terms.

public countImportedTerms(string $lastUpdate) : int
Parameters
$lastUpdate : string

Last update timestamp

Return values
int

Number of imported terms

createTempFile()

Create a temporary file from text input.

public createTempFile(string $content) : string
Parameters
$content : string

Text content to write

Return values
string

Path to temporary file

getDelimiter()

Get delimiter character from tab type.

public getDelimiter(string $tabType) : string
Parameters
$tabType : string

Tab type (c, t, h)

Return values
string

Delimiter character

getImportedTerms()

Get imported terms for display.

public getImportedTerms(string $lastUpdate, int $offset, int $limit) : array<string|int, mixed>
Parameters
$lastUpdate : string

Last update timestamp

$offset : int

Offset for pagination

$limit : int

Limit for pagination

Return values
array<string|int, mixed>

Imported terms data

getLanguageData()

Get language data for a specific language.

public getLanguageData(int $langId) : array<string|int, mixed>|null
Parameters
$langId : int

Language ID

Return values
array<string|int, mixed>|null

Language data or null if not found

getLastWordUpdate()

Get the last word status change timestamp.

public getLastWordUpdate() : string|null
Return values
string|null

Last update timestamp

getSqlDelimiter()

Get delimiter for SQL LOAD DATA statement.

public getSqlDelimiter(string $tabType) : string
Parameters
$tabType : string

Tab type (c, t, h)

Return values
string

SQL delimiter string

handleMultiwords()

Handle multi-word expressions after import.

public handleMultiwords(int $langId, string $lastUpdate) : void
Parameters
$langId : int

Language ID

$lastUpdate : string

Last update timestamp

importComplete()

Import terms with complete processing (handles tags, overwrite modes).

public importComplete(int $langId, array{txt: int, tr: int, ro: int, se: int, tl: int} $fields, string $columnsClause, string $delimiter, string $fileName, int $status, int $overwrite, bool $ignoreFirst, string $translDelim, string $tabType) : void
Parameters
$langId : int

Language ID

$fields : array{txt: int, tr: int, ro: int, se: int, tl: int}

Field indexes

$columnsClause : string

SQL columns clause

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$status : int

Word status

$overwrite : int

Overwrite mode

$ignoreFirst : bool

Ignore first line

$translDelim : string

Translation delimiter

$tabType : string

Tab type (c, t, h)

importSimple()

Import terms using simple import (no tags, no overwrite).

public importSimple(int $langId, array{txt: int, tr: int, ro: int, se: int, tl?: int} $fields, string $columnsClause, string $delimiter, string $fileName, int $status, bool $ignoreFirst) : void
Parameters
$langId : int

Language ID

$fields : array{txt: int, tr: int, ro: int, se: int, tl?: int}

Field indexes

$columnsClause : string

SQL columns clause

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$status : int

Word status

$ignoreFirst : bool

Ignore first line

importTagsOnly()

Import tags only (no terms).

public importTagsOnly(array{tl: int} $fields, string $tabType, string $fileName, bool $ignoreFirst) : void
Parameters
$fields : array{tl: int}

Field indexes

$tabType : string

Tab type (c, t, h)

$fileName : string

Path to input file

$ignoreFirst : bool

Ignore first line

isLocalInfileEnabled()

Check if local infile is enabled in MySQL and PHP.

public isLocalInfileEnabled() : bool

Note: Even if MySQL server has local_infile enabled, PHP might not allow it. We check both the server setting and the PHP mysqli setting.

Return values
bool

True if local_infile is enabled on both server and client

isRightToLeft()

Get right-to-left setting for a language.

public isRightToLeft(int $langId) : bool
Parameters
$langId : int

Language ID

Return values
bool

True if language is RTL

linkWordsToTextItems()

Link imported words to text items.

public linkWordsToTextItems() : void

parseColumnMapping()

Parse column mapping from request.

public parseColumnMapping(array<string|int, mixed> $columns, bool $removeSpaces) : array{columns: array, fields: array{txt: int, tr: int, ro: int, se: int, tl: int}}
Parameters
$columns : array<string|int, mixed>

Column assignments from form (Col1-Col5)

$removeSpaces : bool

Whether language removes spaces

Return values
array{columns: array, fields: array{txt: int, tr: int, ro: int, se: int, tl: int}}

cleanupTempTables()

Cleanup temporary tables.

private cleanupTempTables() : void

executeMainImportQuery()

Execute the main import/update query based on overwrite mode.

private executeMainImportQuery(int $langId, array<string|int, mixed> $fields, int $status, int $overwrite) : void
Parameters
$langId : int

Language ID

$fields : array<string|int, mixed>

Field indexes

$status : int

Word status

$overwrite : int

Overwrite mode (0-5)

executeSimpleImportBatch()

Execute a batch insert for simple import.

private executeSimpleImportBatch(array<int, array<int, int|string>> $rows, array{txt: int, tr: int, ro: int, se: int, tl?: int} $fields) : void
Parameters
$rows : array<int, array<int, int|string>>

Array of row data

$fields : array{txt: int, tr: int, ro: int, se: int, tl?: int}

Field indexes

executeTempTableBatch()

Execute a batch insert for temp table import.

private executeTempTableBatch(array<int, array<int, string>> $rows, array{txt: int, tr: int, ro: int, se: int, tl: int} $fields) : void
Parameters
$rows : array<int, array<int, string>>

Array of row data

$fields : array{txt: int, tr: int, ro: int, se: int, tl: int}

Field indexes

handleTagsImport()

Handle tags import.

private handleTagsImport(int $langId) : void
Parameters
$langId : int

Language ID

handleTranslationMerge()

Handle translation merging for overwrite modes 4 and 5.

private handleTranslationMerge(int $langId, string $translDelim, string $tabType) : void
Parameters
$langId : int

Language ID

$translDelim : string

Translation delimiter from import

$tabType : string

Tab type (c, t, h)

importSimpleWithLoadData()

Import terms using LOAD DATA LOCAL INFILE.

private importSimpleWithLoadData(int $langId, bool $removeSpaces, string $columnsClause, string $delimiter, string $fileName, int $status, bool $ignoreFirst) : void
Parameters
$langId : int

Language ID

$removeSpaces : bool

Whether to remove spaces

$columnsClause : string

SQL columns clause

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$status : int

Word status

$ignoreFirst : bool

Ignore first line

importSimpleWithPHP()

Import terms using PHP parsing (fallback when LOAD DATA not available).

private importSimpleWithPHP(int $langId, array{txt: int, tr: int, ro: int, se: int, tl?: int} $fields, bool $removeSpaces, string $delimiter, string $fileName, int $status, bool $ignoreFirst) : void

Uses chunked batch inserts to handle large files without excessive memory.

Parameters
$langId : int

Language ID

$fields : array{txt: int, tr: int, ro: int, se: int, tl?: int}

Field indexes

$removeSpaces : bool

Whether to remove spaces

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$status : int

Word status

$ignoreFirst : bool

Ignore first line

initTempTables()

Initialize temporary tables for import.

private initTempTables() : void

loadDataToTempTable()

Load data into temporary table using LOAD DATA.

private loadDataToTempTable(bool $removeSpaces, array<string|int, mixed> $fields, string $columnsClause, string $delimiter, string $fileName, bool $ignoreFirst) : void
Parameters
$removeSpaces : bool

Whether to remove spaces

$fields : array<string|int, mixed>

Field indexes

$columnsClause : string

SQL columns clause

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$ignoreFirst : bool

Ignore first line

loadDataToTempTableWithPHP()

Load data into temporary table using PHP (fallback).

private loadDataToTempTableWithPHP(bool $removeSpaces, array{txt: int, tr: int, ro: int, se: int, tl: int} $fields, string $delimiter, string $fileName, bool $ignoreFirst) : void

Uses chunked batch inserts to handle large files without excessive memory.

Parameters
$removeSpaces : bool

Whether to remove spaces

$fields : array{txt: int, tr: int, ro: int, se: int, tl: int}

Field indexes

$delimiter : string

Field delimiter

$fileName : string

Path to input file

$ignoreFirst : bool

Ignore first line


        
On this page

Search results