class AvailableVariablesUpdater (View source)

Constants

FLAG_NONE

Operation flag: no operations.

FLAG_SIMULATE

Operation flag: only simulate operations, don't persist anything.

FLAG_REMOVE_INVALID

Operation flag: delete invalid values.

FLAG_REMOVE_DUPLICATED

Operation flag: delete duplicated values.

FLAG_REMOVE_UNUSED

Operation flag: delete values present in the database but not in any preset.

FLAG_ADD

Operation flag: add values present in presets but not in the database.

FLAG_UPDATE

Operation flag: update values present in presets and in the database, but with wrong definition.

Properties

protected Connection $db

The database connection.

protected Repository $config

The application configuration repository.

private string[]|true[]|null $ignoredValues

The list of values to be ignored (array keys are the variable names, array values are the value class name, or true for any class).

Methods

__construct(Connection $db, Repository $config)

Initialize the instance.

Result[]
fixThemes(int $flags)

Fix the values of every page theme.

fixTheme(Theme $theme, int $flags)

Fix the values of a page theme.

string[]|true[]
getIgnoredValues()

Get the list of values to be ignored.

$this
setIgnoredValues(array $value)

Set the list of values to be ignored.

bool
shouldIgnoreValue(Value $value)

Check if a value should be ignored.

Generator|string[]
listValueListIDs(Theme $theme)

Get the list of the IDs of the currently used variable lists and the associated preset.

buildThemeValueList(Theme $theme, array $presets, string $presetHandle, Result $fixResult)

Build the list of all the style values defined by a theme.

Value[]|string[]
listValues(int $valueListID)

List all the values of a list of a variables.

Value|string
unserializeValue(string $serializedValue)

Unserialize a serialized Style Customizer value.

int
addValue(int $valueListID, Value $value)

Save a new variable to the database.

updateValue(int $valueID, Value $value)

Update a value saved in the database.

deleteValue(int $valueID)

Remove a value from the database.

Value[]
processInvalid(array $currentValues, Result $fixResult, bool $delete, bool $simulate)

Process the list of values, filtering out the invalid ones.

Value[]
deleteDuplicated(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Delete the duplicated values.

Value[]
deleteUnused(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Delete the unused values.

bool
isValueUnused(Value $value, ValueList $themeValueList, Result $fixResult)

Check if a value is not used.

Value[]
updateCurrentValues(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Check if some values needs to be updated.

Value|null
buildUpdatedValue(Value $value, ValueList $themeValueList)

Create a new Value instance, if it needs to be fixed.

TypeValue|null
buildUpdatedTypeValue(TypeValue $value, ValueList $themeValueList)

Create a new TypeValue instance, if it needs to be fixed.

Value[]
addNewValues(array $currentValues, ValueList $themeValueList, int $valueListID, Result $fixResult, bool $simulate)

Check if some values needs to be added.

bool
shouldAddValue(Value $presetValue, array $currentValues)

Check if a value found in a preset should be added to the currently used values.

bool
areValuesForTheSameVariable(Value|mixed $value1, Value|mixed $value2)

Check if two variables are the values of the same variable.

Details

__construct(Connection $db, Repository $config)

Initialize the instance.

Parameters

Connection $db
Repository $config

Result[] fixThemes(int $flags)

Fix the values of every page theme.

Parameters

int $flags

A combination of the values of the FLAG_... constants.

Return Value

Result[]

array keys are the theme handles, array values are the result of the fixTheme() method

See also

AvailableVariablesUpdater::fixTheme

Result fixTheme(Theme $theme, int $flags)

Fix the values of a page theme.

Parameters

Theme $theme
int $flags

A combination of the values of the FLAG_... constants.

Return Value

Result

protected string[]|true[] getIgnoredValues()

Get the list of values to be ignored.

Return Value

string[]|true[]

array keys are the variable names, array values are the value class name, or true for any class

protected $this setIgnoredValues(array $value)

Set the list of values to be ignored.

Parameters

array $value

array keys are the variable names, array values are the value class name, or true for any class

Return Value

$this

protected bool shouldIgnoreValue(Value $value)

Check if a value should be ignored.

Parameters

Value $value

Return Value

bool

protected Generator|string[] listValueListIDs(Theme $theme)

Get the list of the IDs of the currently used variable lists and the associated preset.

Parameters

Theme $theme

Return Value

Generator|string[]

keys are the value list IDs, values are the preset name (empty string if none)

protected ValueList buildThemeValueList(Theme $theme, array $presets, string $presetHandle, Result $fixResult)

Build the list of all the style values defined by a theme.

Parameters

Theme $theme
array $presets

the presets provided by the theme (the default one should be the first one)

string $presetHandle

The handle of the preferred preset (empty string if not available)

Result $fixResult

Return Value

ValueList

protected Value[]|string[] listValues(int $valueListID)

List all the values of a list of a variables.

Parameters

int $valueListID

Return Value

Value[]|string[]

keys are the value IDs; in case of errors, values are strings

protected Value|string unserializeValue(string $serializedValue)

Unserialize a serialized Style Customizer value.

Parameters

string $serializedValue

Return Value

Value|string

Returns a string in case of errors

protected int addValue(int $valueListID, Value $value)

Save a new variable to the database.

Parameters

int $valueListID

The associated list ID

Value $value

Return Value

int

the ID of the newly created record

protected updateValue(int $valueID, Value $value)

Update a value saved in the database.

Parameters

int $valueID

the ID of the value

Value $value

protected deleteValue(int $valueID)

Remove a value from the database.

Parameters

int $valueID

the ID of the value to be removed

protected Value[] processInvalid(array $currentValues, Result $fixResult, bool $delete, bool $simulate)

Process the list of values, filtering out the invalid ones.

Parameters

array $currentValues

keys are the value IDs; in case of errors, values are strings

Result $fixResult
bool $delete
bool $simulate

Return Value

Value[]

keys are the value IDs

protected Value[] deleteDuplicated(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Delete the duplicated values.

Parameters

array $currentValues

keys are the value IDs

ValueList $themeValueList
Result $fixResult
bool $simulate

Return Value

Value[]

keys are the value IDs

protected Value[] deleteUnused(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Delete the unused values.

Parameters

array $currentValues

keys are the value IDs

ValueList $themeValueList
Result $fixResult
bool $simulate

Return Value

Value[]

keys are the value IDs

protected bool isValueUnused(Value $value, ValueList $themeValueList, Result $fixResult)

Check if a value is not used.

Parameters

Value $value
ValueList $themeValueList
Result $fixResult

Return Value

bool

protected Value[] updateCurrentValues(array $currentValues, ValueList $themeValueList, Result $fixResult, bool $simulate)

Check if some values needs to be updated.

Parameters

array $currentValues

keys are the value IDs

ValueList $themeValueList
Result $fixResult
bool $simulate

Return Value

Value[]

keys are the value IDs

protected Value|null buildUpdatedValue(Value $value, ValueList $themeValueList)

Create a new Value instance, if it needs to be fixed.

Parameters

Value $value
ValueList $themeValueList

Return Value

Value|null

NULL if the value doesn't need to be fixed

protected TypeValue|null buildUpdatedTypeValue(TypeValue $value, ValueList $themeValueList)

Create a new TypeValue instance, if it needs to be fixed.

Parameters

TypeValue $value
ValueList $themeValueList

Return Value

TypeValue|null

NULL if the value doesn't need to be fixed

protected Value[] addNewValues(array $currentValues, ValueList $themeValueList, int $valueListID, Result $fixResult, bool $simulate)

Check if some values needs to be added.

Parameters

array $currentValues

keys are the value IDs

ValueList $themeValueList
int $valueListID
Result $fixResult
bool $simulate

Return Value

Value[]

$currentValues keys are the value IDs

protected bool shouldAddValue(Value $presetValue, array $currentValues)

Check if a value found in a preset should be added to the currently used values.

Parameters

Value $presetValue
array $currentValues

Return Value

bool

protected bool areValuesForTheSameVariable(Value|mixed $value1, Value|mixed $value2)

Check if two variables are the values of the same variable.

Parameters

Value|mixed $value1
Value|mixed $value2

Return Value

bool