vB_Xml_Import_Widget
extends vB_Xml_Import
in package
Table of Contents
- OPTION_ADDSPECIFICWIDGETS = 32
- OPTION_ADDWIDGETS = 8
- OPTION_IGNOREMISSINGPARENTS = 4
- OPTION_IGNOREMISSINGROUTES = 2
- OPTION_OVERWRITE = 1
- OPTION_OVERWRITECOLUMN = 16
- TYPE_CHANNEL = 'channels'
- TYPE_PAGE = 'pages'
- TYPE_PAGETEMPLATE = 'pageTemplates'
- TYPE_ROUTE = 'routes'
- TYPE_SCREENLAYOUT = 'screenLayouts'
- TYPE_THEME = 'themes'
- TYPE_WIDGET = 'widgets'
- WIDGETGUID_ABSTRACT_GLOBAL = 'vbulletin-abstractwidget-global'
- Widget GUIDs
- $db : vB_dB_Assertor
- $importedElements : array<string|int, mixed>
- $options : int
- $overwriteColumn : string
- Column to overwrite, if OPTION_OVERWRITECOLUMN is set
- $parsedXML : array<string|int, mixed>
- $productid : mixed
- $derivedWidgets : array<string|int, mixed>
- Array of derived widgets (after inheritance)
- $insertedWidgetIds : array<string|int, mixed>
- Array of widgetids that were newly inserted (as opposed to updated) in this import
- $widgets : array<string|int, mixed>
- Array of widget info for all widgets
- $widgetsByGuid : array<string|int, mixed>
- Map of widget info. Key is widget GUID, value is a reference to widget in $this->widgets.
- __construct() : mixed
- __serialize() : mixed
- __sleep() : mixed
- __unserialize() : mixed
- __wakeup() : mixed
- getDerivedWidgets() : array<string|int, mixed>
- Returns the derived widgets.
- getImportedId() : int
- Returns the id for an imported element
- importFromFile() : mixed
- Imports objects from the specified filepath
- importFromParsedXML() : mixed
- Imports objects from parsed XML starting at the base of the relevant objects.
- parseFile() : mixed
- setOptions() : mixed
- setOverwriteColumn() : mixed
- Sets the column to overwrite, if OPTION_OVERWRITECOLUMN is set
- getAllWidgetData() : array<string|int, mixed>
- Gets all widget info from database, ready for the inheritance process
- getXmlList() : The
- Get a list from the parsed xml array
- getXmlWidgetData() : array<string|int, mixed>
- Normalizes and returns widget data from XML
- import() : mixed
- Imports the data from the XML file into the database
- replacePhrasePlaceholdersInArray() : array<string|int, mixed>
- If an array value is of the form "phrase:<phrasevarname>" replace it with the actual phrase.
- setImportedId() : mixed
- Stores an imported element with the new id
- arrayMergeRecursive() : array<string|int, mixed>
- Creates an array containing all the key/value pairs from $array1 and $array2.
- buildDerivedWidgets() : array<string|int, mixed>
- Applies widget inheritance and builds the final "derived" widgets
- checkParentage() : array<string|int, mixed>
- Checks widget parentage for vBulletin widgets and adds the default global Parent if missing.
- checkWidgetParentidAndAlterTable() : mixed
- getTableColumnsToImport() : array<string|int, mixed>
- Returns an array of column names which should be populated in the import
- getWidgetByGuid() : array<string|int, mixed>|null
- Returns the widget info for the passed widget GUID.
- normalizeDefinitions() : array<string|int, mixed>
- Normalizes the defintions array in each widget record and ensures that each definition is keyed by the defintion name.
- saveConfigItems() : mixed
- Saves widget config items. Removes previous widgetdefinition records and replaces them with the new data.
- saveWidgets() : array<string|int, mixed>
- Inserts or updates the widgets in the database. Adds the widget ID to the passed array of widgets and returns it.
- updateInstanceAdminConfigs() : mixed
- Updates widgetinstance.adminconfig. Removes any values that no longer exist, Inserts the default value for any new/non-existing values in the config items.
- updateWidgetParentids() : array<string|int, mixed>
- Sets/updates widget parentids based on the parentguid
- verifyWidgetInheritanceRules() : mixed
- Asserts that widget inheritance rules are followed.
Constants
OPTION_ADDSPECIFICWIDGETS
public
mixed
OPTION_ADDSPECIFICWIDGETS
= 32
OPTION_ADDWIDGETS
public
mixed
OPTION_ADDWIDGETS
= 8
OPTION_IGNOREMISSINGPARENTS
public
mixed
OPTION_IGNOREMISSINGPARENTS
= 4
OPTION_IGNOREMISSINGROUTES
public
mixed
OPTION_IGNOREMISSINGROUTES
= 2
OPTION_OVERWRITE
public
mixed
OPTION_OVERWRITE
= 1
OPTION_OVERWRITECOLUMN
public
mixed
OPTION_OVERWRITECOLUMN
= 16
TYPE_CHANNEL
public
mixed
TYPE_CHANNEL
= 'channels'
TYPE_PAGE
public
mixed
TYPE_PAGE
= 'pages'
TYPE_PAGETEMPLATE
public
mixed
TYPE_PAGETEMPLATE
= 'pageTemplates'
TYPE_ROUTE
public
mixed
TYPE_ROUTE
= 'routes'
TYPE_SCREENLAYOUT
public
mixed
TYPE_SCREENLAYOUT
= 'screenLayouts'
TYPE_THEME
public
mixed
TYPE_THEME
= 'themes'
TYPE_WIDGET
public
mixed
TYPE_WIDGET
= 'widgets'
WIDGETGUID_ABSTRACT_GLOBAL
Widget GUIDs
public
mixed
WIDGETGUID_ABSTRACT_GLOBAL
= 'vbulletin-abstractwidget-global'
Properties
$db
protected
vB_dB_Assertor
$db
$importedElements
protected
static array<string|int, mixed>
$importedElements
$options
protected
int
$options
$overwriteColumn
Column to overwrite, if OPTION_OVERWRITECOLUMN is set
protected
string
$overwriteColumn
= ''
$parsedXML
protected
array<string|int, mixed>
$parsedXML
$productid
protected
mixed
$productid
$derivedWidgets
Array of derived widgets (after inheritance)
private
array<string|int, mixed>
$derivedWidgets
= array()
$insertedWidgetIds
Array of widgetids that were newly inserted (as opposed to updated) in this import
private
array<string|int, mixed>
$insertedWidgetIds
= array()
$widgets
Array of widget info for all widgets
private
array<string|int, mixed>
$widgets
= array()
$widgetsByGuid
Map of widget info. Key is widget GUID, value is a reference to widget in $this->widgets.
private
array<string|int, mixed>
$widgetsByGuid
=
ull
Should be accessed via getWidgetByGuid()
Methods
__construct()
public
__construct([mixed $productid = 'vbulletin' ][, mixed $options = 9 ]) : mixed
Parameters
- $productid : mixed = 'vbulletin'
- $options : mixed = 9
Return values
mixed —__serialize()
public
__serialize() : mixed
Return values
mixed —__sleep()
public
__sleep() : mixed
Return values
mixed —__unserialize()
public
__unserialize(mixed $serialized) : mixed
Parameters
- $serialized : mixed
Return values
mixed —__wakeup()
public
__wakeup() : mixed
Return values
mixed —getDerivedWidgets()
Returns the derived widgets.
public
getDerivedWidgets() : array<string|int, mixed>
WARNING: Only intended for use by unit tests. Do not use in any other context
Return values
array<string|int, mixed> —Derived widgets
getImportedId()
Returns the id for an imported element
public
static getImportedId(string $type[, string $guid = NULL ]) : int
Parameters
- $type : string
- $guid : string = NULL
Return values
int —importFromFile()
Imports objects from the specified filepath
public
importFromFile(string $filepath[, string $guid = false ]) : mixed
Parameters
- $filepath : string
- $guid : string = false
-
Only import the record associated with this guid
Return values
mixed —importFromParsedXML()
Imports objects from parsed XML starting at the base of the relevant objects.
public
importFromParsedXML(array<string|int, mixed> $parsedXML) : mixed
Parameters
- $parsedXML : array<string|int, mixed>
Return values
mixed —parseFile()
public
static parseFile(mixed $filepath) : mixed
Parameters
- $filepath : mixed
Return values
mixed —setOptions()
public
setOptions(mixed $options) : mixed
Parameters
- $options : mixed
Return values
mixed —setOverwriteColumn()
Sets the column to overwrite, if OPTION_OVERWRITECOLUMN is set
public
setOverwriteColumn(mixed $column) : mixed
Parameters
- $column : mixed
Return values
mixed —getAllWidgetData()
Gets all widget info from database, ready for the inheritance process
protected
getAllWidgetData() : array<string|int, mixed>
Return values
array<string|int, mixed> —Widget data
getXmlList()
Get a list from the parsed xml array
protected
getXmlList(array<string|int, mixed> $parentxml, string $listname) : The
A common way to format lists in xml is
The problem is a single item is ambiguous
It could be a one element list or it could be a scalar child -- we only know from the context of the data, which the parser doesn't know. Our parser assumes that it is a scalar value unless there are multiple tags with the same name. Therefor so the first is rendered as:
tag['subtag'] = [0 => $element, 1 => $element]
While the second is:
tag['subtag'] = $element.
Rather than handle each list element as a special case if there is only one item in the xml, this function will examine the element passed and if it isn't a 0 indexed array as expect will wrap the single element in an array() call. The first case is not affected and the second is converted to tag['subtag'] = array(0 => $element), which is what we'd actually expect.
This is why we should use JSON.
Parameters
- $parentxml : array<string|int, mixed>
-
-- The parsed XML array containing the list. This must be the direct parent of the lsit
- $listname : string
-
-- The tag name for the list values
Return values
The —list properly regularized to a numerically indexed array.
getXmlWidgetData()
Normalizes and returns widget data from XML
protected
getXmlWidgetData() : array<string|int, mixed>
Return values
array<string|int, mixed> —Widget data
import()
Imports the data from the XML file into the database
protected
import() : mixed
Return values
mixed —replacePhrasePlaceholdersInArray()
If an array value is of the form "phrase:<phrasevarname>" replace it with the actual phrase.
protected
replacePhrasePlaceholdersInArray(array<string|int, mixed> $array) : array<string|int, mixed>
Parameters
- $array : array<string|int, mixed>
Return values
array<string|int, mixed> —The array with phrases replaced.
setImportedId()
Stores an imported element with the new id
protected
static setImportedId(string $type, string $guid, mixed $newid) : mixed
Parameters
- $type : string
- $guid : string
- $newid : mixed
Return values
mixed —arrayMergeRecursive()
Creates an array containing all the key/value pairs from $array1 and $array2.
private
arrayMergeRecursive(mixed $array1, mixed $array2, mixed $removeArray) : array<string|int, mixed>
If the same key is found in both arrays, AND the value is a non-array type, the value from $array2 will overwrite the value from $array1. If the value is an array, this function is called recursively to merge the arrays. Any items that are not set in $removeArray, will be removed from $array2.
NOTE: This function does not have the same behavior as PHP's array_merge_recursive() or array_replace_recursive().
Parameters
- $array1 : mixed
- $array2 : mixed
- $removeArray : mixed
Return values
array<string|int, mixed> —Merged array
buildDerivedWidgets()
Applies widget inheritance and builds the final "derived" widgets
private
buildDerivedWidgets(mixed $widgets, mixed $xmlWidgets) : array<string|int, mixed>
Parameters
- $widgets : mixed
- $xmlWidgets : mixed
Return values
array<string|int, mixed> —Array of derived widgets
checkParentage()
Checks widget parentage for vBulletin widgets and adds the default global Parent if missing.
private
checkParentage(mixed $widgets, mixed $xmlWidgets) : array<string|int, mixed>
Parameters
- $widgets : mixed
- $xmlWidgets : mixed
Return values
array<string|int, mixed> —The array of widget data, with the parentguid added where missing
checkWidgetParentidAndAlterTable()
private
checkWidgetParentidAndAlterTable() : mixed
Return values
mixed —getTableColumnsToImport()
Returns an array of column names which should be populated in the import
private
getTableColumnsToImport(mixed $tableName) : array<string|int, mixed>
Parameters
- $tableName : mixed
Return values
array<string|int, mixed> —List of column names
getWidgetByGuid()
Returns the widget info for the passed widget GUID.
private
getWidgetByGuid(mixed $guid) : array<string|int, mixed>|null
Parameters
- $guid : mixed
Return values
array<string|int, mixed>|null —Array of widget info or null if the widget doesn't exist
normalizeDefinitions()
Normalizes the defintions array in each widget record and ensures that each definition is keyed by the defintion name.
private
normalizeDefinitions(mixed $widgets) : array<string|int, mixed>
Parameters
- $widgets : mixed
Return values
array<string|int, mixed> —Array of widgets with the defintion item in each widget normalized.
saveConfigItems()
Saves widget config items. Removes previous widgetdefinition records and replaces them with the new data.
private
saveConfigItems(mixed $widgets) : mixed
Parameters
- $widgets : mixed
Return values
mixed —saveWidgets()
Inserts or updates the widgets in the database. Adds the widget ID to the passed array of widgets and returns it.
private
saveWidgets(mixed $widgets[, mixed $addProductId = true ]) : array<string|int, mixed>
Parameters
- $widgets : mixed
- $addProductId : mixed = true
Return values
array<string|int, mixed> —The passed array of widgets with a new 'widgetid' element and indexed by widget ID.
updateInstanceAdminConfigs()
Updates widgetinstance.adminconfig. Removes any values that no longer exist, Inserts the default value for any new/non-existing values in the config items.
private
updateInstanceAdminConfigs(mixed $widgets) : mixed
Parameters
- $widgets : mixed
Return values
mixed —updateWidgetParentids()
Sets/updates widget parentids based on the parentguid
private
updateWidgetParentids(mixed $widgets) : array<string|int, mixed>
Parameters
- $widgets : mixed
Return values
array<string|int, mixed> —The passed array of widgets with a new 'parentid' element.
verifyWidgetInheritanceRules()
Asserts that widget inheritance rules are followed.
private
verifyWidgetInheritanceRules(mixed $widgets) : mixed
Parameters
- $widgets : mixed