PHP Class VersionPress\Synchronizers\Synchronizer

Synchronizer does work that is kind of opposite to the ones of storages but with one major difference: while storages usually add or delete entities one by one or by small amounts, synchronizer usually operates over all entities or some subset (see $entitiesToSynchronize). Synchronizers are run by the {@link VersionPress\Synchronizers\SynchronizationProcess}.
Show file Open project: versionpress/versionpress Class Usage Examples

Protected Properties

Property Type Description
$database VersionPress\Database\Database
$entities array | null

Public Methods

Method Description
__construct ( Storage $storage, Database $database, EntityInfo $entityInfo, DbSchemaInfo $dbSchemaInfo, VpidRepository $vpidRepository, AbsoluteUrlReplacer $urlReplacer, ShortcodesReplacer $shortcodesReplacer, TableSchemaStorage $tableSchemaStorage )
reset ( ) Resets values persisted for the multipass processing.
synchronize ( string $task, array $entitiesToSynchronize = null ) : string[] Synchronizes entities from storage to the database. It generally only works with tracked entities, i.e. the ignored (untracked) rows in the database are left untouched. The rows corresponding to tracked entities are usually in sync with the storage after this method is done. It may happen that the synchronizer cannot synchronize everything in the first pass. Because of this, the synchronize method takes a task for sychronization (usually "everything" for the first pass) and returns a list of tasks that aren't done yet. It's up to the SynchronizationProcess to call the synchronize method again with this tasks when the previous pass is done.

Protected Methods

Method Description
buildCreateQuery ( $entity )
computeColumnValues ( ) Specific entities might contain ignored colums, which values should be computed on synchronizing process e.g. posts.

Private Methods

Method Description
addOrUpdateEntities ( )
buildUpdateQuery ( $updateData )
buildUpdateQueryForEntityWithGeneratedVpid ( $updateData )
buildUpdateQueryForEntityWithNaturalVpid ( $updateData )
cleanCache ( ) Cleans caches specified in schema.yml.
createEntityInDatabase ( $entity )
createIdentifierRecord ( $vpid, $id )
createTable ( ) --------------------------------------
deleteEntitiesWhichAreNotInStorage ( )
entityContainsComputedValues ( )
existsInDatabase ( $vpid )
fixMnReferences ( )
fixReferences ( ) --------------------------------------
getAllVpIdsUsedInReferences ( $referencesToSave ) : array
getExistingMnReferences ( ) : array
getIdsForVpIds ( $referencesToUpdate )
idMapContainsAllVpIds ( $idMap, $vpIds )
loadEntitiesFromStorage ( ) : array Loads entities from storage. For full synchronization it loads all entities. For selective synchronization it loads only entities from $this->entitiesToSynchronize.
maybeInit ( )
maybeStripMetaEntities ( array $entities ) : array Strips meta entities from their parents. Called after entities have been loaded from storage.
restoreShortcodesInAllEntities ( )
updateDatabase ( ) Adds, updates and deletes rows in the database
updateEntityInDatabase ( $entity )

Method Details

__construct() public method

public __construct ( Storage $storage, Database $database, EntityInfo $entityInfo, DbSchemaInfo $dbSchemaInfo, VpidRepository $vpidRepository, AbsoluteUrlReplacer $urlReplacer, ShortcodesReplacer $shortcodesReplacer, TableSchemaStorage $tableSchemaStorage )
$storage VersionPress\Storages\Storage Specific Synchronizers will use specific storage types, see SynchronizerFactory
$database VersionPress\Database\Database
$entityInfo VersionPress\Database\EntityInfo
$dbSchemaInfo VersionPress\Database\DbSchemaInfo
$vpidRepository VersionPress\Database\VpidRepository
$urlReplacer VersionPress\Utils\AbsoluteUrlReplacer
$shortcodesReplacer VersionPress\Database\ShortcodesReplacer
$tableSchemaStorage VersionPress\Database\TableSchemaStorage

buildCreateQuery() protected method

protected buildCreateQuery ( $entity )

computeColumnValues() protected method

Specific entities might contain ignored colums, which values should be computed on synchronizing process e.g. posts.
protected computeColumnValues ( )

reset() public method

Useful for tests.
public reset ( )

synchronize() public method

If the $entitiesToSynchronize is null, the synchronizer will synchronize all entities. If it's an array, the synchronizer will synchronize only those entities.
public synchronize ( string $task, array $entitiesToSynchronize = null ) : string[]
$task string
$entitiesToSynchronize array List of VPIDs and their possible parents {@see \SynchronizationProcess::synchronize()}
return string[]

Property Details

$database protected property

protected Database,VersionPress\Database $database
return VersionPress\Database\Database

$entities protected property

protected array|null $entities
return array | null