LimeSurvey API - Master branch

Update_700 extends DatabaseUpdateBase
in package

Base class for database migration, inspired by Yii.

Tags
SuppressWarnings

(PHPMD.ExcessiveClassComplexity)

Table of Contents

Properties

$db  : CDbConnection
$insertansProcessedSids  : array<string|int, mixed>
$newVersion  : int
$options  : string
$questionCodes  : mixed
$scriptMapping  : mixed

Methods

__construct()  : mixed
adjustShowCreateTable()  : mixed
deleteRankingAnswers()  : string
Cleanup for ranking answers
deleteTranslatedRankingAnswers()  : string
Cleanup for ranking answers
doPreparations()  : mixed
getFieldsFromTableScript()  : mixed
getFieldsScript()  : mixed
getResponsesScript()  : mixed
getTimingScript()  : mixed
getVersion()  : int
Get db version number based on class name, e.g. 123 for Update_123
insertRankingSubquestions()  : string
Creating subquestions for ranking instead of its answers
insertRankingSubquestionsL10ns()  : string
Creating subquestions for ranking instead of its answers
safeUp()  : void
Runs up() wrapped in a transaction.
showCreateTable()  : mixed
up()  : mixed
This is the function that must be implemented by the child classes.
updateRankingAnswerOrderAttribute()  : string
Updates ranking question attributes from answer_order to subquestion_order
convertLegacyInsertans()  : string
Convert legacy INSERTANS tags to modern question code references.
convertSurveyInsertans()  : mixed
Convert INSERTANS tags and fix SGQA references in all text fields of a survey.
createOldFieldMap()  : array<string|int, mixed>
This function generates an array containing the fieldcode, and matching data in the same order as the activate script
fixText()  : bool
Fixes textual data, replacing old fieldname representation with new fieldname representation. We don't save the record even if changed here, because outside of the method we may want to do additional things
handleInsertans()  : bool
Applies convertLegacyInsertans() to the specified fields of a record.
updateVersion()  : mixed
Sets DBVersion in settings global to $this->newVersion Last thing that happens before transaction commit in every update.

Properties

$insertansProcessedSids

protected array<string|int, mixed> $insertansProcessedSids = []

Survey IDs that have already been processed for INSERTANS conversion

$questionCodes

protected mixed $questionCodes = []

Methods

__construct()

public __construct(CDbConnection $connection, string $options) : mixed
Parameters
$connection : CDbConnection
$options : string

Specific database options like ENGINE=INNODB etc

adjustShowCreateTable()

public adjustShowCreateTable(array<string|int, mixed> $script, string $tableName) : mixed
Parameters
$script : array<string|int, mixed>
$tableName : string

deleteRankingAnswers()

Cleanup for ranking answers

public deleteRankingAnswers() : string
Return values
string

deleteTranslatedRankingAnswers()

Cleanup for ranking answers

public deleteTranslatedRankingAnswers() : string
Return values
string

doPreparations()

public doPreparations() : mixed

getFieldsFromTableScript()

public getFieldsFromTableScript(mixed $tableName) : mixed
Parameters
$tableName : mixed

getFieldsScript()

public getFieldsScript() : mixed

getResponsesScript()

public getResponsesScript() : mixed

getTimingScript()

public getTimingScript() : mixed

getVersion()

Get db version number based on class name, e.g. 123 for Update_123

public getVersion() : int
Return values
int

insertRankingSubquestions()

Creating subquestions for ranking instead of its answers

public insertRankingSubquestions() : string
Return values
string

insertRankingSubquestionsL10ns()

Creating subquestions for ranking instead of its answers

public insertRankingSubquestionsL10ns() : string
Return values
string

safeUp()

Runs up() wrapped in a transaction.

public safeUp() : void

Will rollback transaction and re-throw exception at failure.

Tags
throws
Throwable

showCreateTable()

public showCreateTable(string $tableName) : mixed
Parameters
$tableName : string

up()

This is the function that must be implemented by the child classes.

public up() : mixed
Tags
SuppressWarnings

(PHPMD.ExcessiveMethodLength)

updateRankingAnswerOrderAttribute()

Updates ranking question attributes from answer_order to subquestion_order

public updateRankingAnswerOrderAttribute() : string
Return values
string

convertLegacyInsertans()

Convert legacy INSERTANS tags to modern question code references.

protected convertLegacyInsertans(string $text, array<string|int, mixed> $questionCodesByQid) : string

The result is wrapped in curly braces only when the source tag also used curly braces.

When the QID+suffix boundary is ambiguous (e.g. purely numeric suffixes in array questions like {INSERTANS:136212X36X10921}), the function progressively tries shorter QID values until a known QID is found, treating the remainder as suffix.

Parameters
$text : string

The text containing INSERTANS tags

$questionCodesByQid : array<string|int, mixed>

Mapping of QID => question title

Tags
SuppressWarnings

(PHPMD.ExcessiveMethodLength)

Return values
string

The text with INSERTANS tags converted to qcode.shown format

convertSurveyInsertans()

Convert INSERTANS tags and fix SGQA references in all text fields of a survey.

protected convertSurveyInsertans(int|string $sid, array<string|int, Question$questions[, array<string|int, mixed> $fieldNames = [] ][, array<string|int, mixed> $additionalNames = [] ][, bool $guardRelevance = false ]) : mixed

Loads all relevant entities (QuestionL10n, QuestionGroupL10n, SurveyLanguageSetting, Conditions, Assessments, QuotaLanguageSettings, DefaultValueL10n, AnswerL10n) and applies handleInsertans() plus optional fixText() replacements, then saves changed records.

Parameters
$sid : int|string

The survey ID

$questions : array<string|int, Question>

The survey's questions (with answers eager-loaded)

$fieldNames : array<string|int, mixed> = []

SGQA→new field name map for fixText (may be empty)

$additionalNames : array<string|int, mixed> = []

SGQA→Q{qid} map for fixText (may be empty)

$guardRelevance : bool = false

When true, skip saving Question entities with relevance field if the question's survey relation is missing (active survey guard)

Tags
SuppressWarnings

(PHPMD.ExcessiveMethodLength)

createOldFieldMap()

This function generates an array containing the fieldcode, and matching data in the same order as the activate script

protected createOldFieldMap(Survey $survey[, string $style = 'short' ][, bool|null $force_refresh = false ][, bool|int $questionid = false ][, string $sLanguage = '' ][, array<string|int, mixed> &$aDuplicateQIDs = array() ]) : array<string|int, mixed>
Parameters
$survey : Survey

Survey ActiveRecord model

$style : string = 'short'

'short' (default) or 'full' - full creates extra information like default values

$force_refresh : bool|null = false
  • Forces to really refresh the array, not just take the session copy
$questionid : bool|int = false

Limit to a certain qid only (for question preview) - default is false

$sLanguage : string = ''

The language to use

$aDuplicateQIDs : array<string|int, mixed> = array()
Tags
SuppressWarnings

(PHPMD.ExcessiveMethodLength)

Return values
array<string|int, mixed>

fixText()

Fixes textual data, replacing old fieldname representation with new fieldname representation. We don't save the record even if changed here, because outside of the method we may want to do additional things

protected fixText(LSActiveRecord &$record, mixed $fields, mixed $replacements) : bool
Parameters
$record : LSActiveRecord

the record whose fields are to be fixed

$fields : mixed

the fields that need to be fixed for the record

$replacements : mixed

the mapping of old fieldnames and new fieldnames

Return values
bool

whether the record has changed and is likely to be saved

handleInsertans()

Applies convertLegacyInsertans() to the specified fields of a record.

protected handleInsertans(LSActiveRecord &$record, array<string|int, mixed> $fields, int|string $sid) : bool
Parameters
$record : LSActiveRecord

the record whose fields are to be converted

$fields : array<string|int, mixed>

the field names where INSERTANS tags may occur

$sid : int|string

the survey ID (used to lazy-load question codes)

Return values
bool

whether the record was changed

updateVersion()

Sets DBVersion in settings global to $this->newVersion Last thing that happens before transaction commit in every update.

private updateVersion() : mixed

        
On this page

Search results