October\Rain\Database\Replicator

Overview

Replicator service to duplicating and replicating model records


Protected Properties

protected Model $model

model context

protected bool $isDuplicating

isDuplicating the record or just returning a non-existing instance

protected bool $isMultisite

isMultisite context

protected array $associationMap

associationMap from original record to newly created record


Public Methods

public __construct()

public __construct($model): void

public duplicate()

public duplicate(array|null $except = null): static 

duplicate replicates a model with special multisite duplication logic. To avoid duplication of has many relations, the logic only propagates relations on the parent model since they are shared via site_root_id beyond this point.

public replicate()

public replicate(array|null $except = null): static 

replicate replicates the model into a new, non-existing instance, including replicating relations.

Protected Methods

protected isRelationReplicable()

protected isRelationReplicable($name): bool 

isRelationReplicable determines whether the specified relation should be replicated when replicateWithRelations() is called instead of save() on the model. Default: true.

protected mapAssociation()

protected mapAssociation($currentModel, $replicatedModel): void

mapAssociation is an internal method that keeps a record of what records were created and their associated source, the following format is used:

[FromModel::id] => [FromModel, ToModel]

protected replicateRelationInternal()

protected replicateRelationInternal($relationObject, $models): void

replicateRelationInternal on the model instance with the supplied ones

protected replicateRelationsInternal()

protected replicateRelationsInternal($except = null): void

protected updateTreeAssociations()

protected updateTreeAssociations(): void

updateTreeAssociations sets new parents on the replicated records