MMOframework
Why AI Playground Libraries Developers Agency
FR EN
Build a project live
Index

DataSync

MMO\admin\helpers · 1 symbol · generated 30 Nov 2026

class

DataSync

DataSync.php:35

Keeps what a site writes while it runs -- its data, its keys, the files sent from its backoffice: a target's sync.paths, its shared paths by default (Target::syncPolicy) -- the same on the target and in the project here, in either direction.

class MMO\admin\helpers\DataSync
Namespace
MMO\admin\helpers
**What changed, and where.** Each sync records, per file, the sha256 it left on each side (`.mmo/sync/{target}.json`, in the project), and a copy of the version both sides then held when it is a text (`.mmo/sync/{target}/base/`, for [`DataMerge`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataMerge.md#datamerge)'s three-way merge). [`compare`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-compare) reads both sides again and tells, per file, who changed it since: [`SAME`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-same), [`TARGET`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-target) (the site), [`LOCAL`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-local) (here) or [`BOTH`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-both). Never synced: a file only one side has is that side's, a file both have differently is [`BOTH`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-both). **Portable both ways.** What is transferred goes through [`PortableContent`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/PortableContent.md#portablecontent) first: the target's urls and folders, and this machine's, are written relative, so a page saved in production links to images that load here too. **Nothing is lost on the target.** A push first archives the files it replaces or removes in `{folder}/deploy/data-backups/{stamp}.tar.gz`, holds the target's deployment lock, and moves each file into place (a rename: the site reads the old file or the new one, never half of one). **The live release too.** [`releaseChanges`](https://mmoframework.fr/en/documentation/mmo.admin/php/helpers/DataSync.md#datasync-releasechanges) compares the files of the release the site runs with the artifact it was shipped from: what was edited on the server in place, which the next release replaces.
$sync = new DataSync($context, '/home/me/dev/acme', ['http://localhost/acme/www/']); foreach ($sync->compare() as $entry) {echo $entry['status'], ' ', $entry['path'], "\n";} $sync->pull(['db/pages.json' => $sync->fetch(['db/pages.json'])['db/pages.json']]);

Index

BASE_LIMITa base copy is kept for a text up to this size: the three-way merge of something larger is no one's job
BOTHchanged on both sides: to merge, or one side to choose
LOCALchanged here since the last sync: to push
SAMEthe same on both sides
SUMMARY_FILEShow many files of a status a summary lists: a site never synced lists every file, and a page shows the counts
TARGETchanged on the target since the last sync: to pull
context readonly
full readonly
localUrls
machinePaths
owned
portable
project readonly
remote
repositories
scratch
sha
state
stateFolder
tracked
baseOf($filename)
cleanup()Remove this run's temporary files: what was downloaded holds the site's data.
compare($only)Who changed what since the last sync.
debugName()
fetch($paths)Download the target's versions of files, as they are there.
fetchRelease($paths)Download files of the live release, as they are there.
getBase($path)
getBaseFolder()
getDatabaseFiles()
getLastSync()
getMachinePaths()
getRoots()
getState()
getStateFilename()
getStateFolder()
installLocal($path, $source)Put a file in place here: a rename, with the rights of the file it replaces (the web server writes it).
isSynced($path)
local()
makePortable($path, $filename)Make a copy of a file portable, saying what still looks absolute in it.
Overall($counts) static
policy()
portable()
publish($files)Write versions here, and on the target: what a merge decided, or the local ones (push).
pull($files)Write the target's versions here, made portable, and remember both sides hold them.
push($paths)Upload the local versions to the target.
reading($command)Run a command on the target that only reads, even in a dry run (the runner lets only a few through).
readRemote($command)Run a command on the target whose output may be long, and read that output through a file.
record($path, $local, $remote, $content)Remember that both sides now hold the same version of $path.
recordDatabase($name, $mode)Remember that a database server was pulled here or pushed there whole (data-pull, data-push): no file of it is compared, so this is all a status can say of it.
releaseChanges($artifact)What was changed on the target in the release it runs: its files compared with the artifact it was shipped from.
remote()
remoteFilename($path)
remoteSums($paths)
removeLocal($path)
restoreDatabase($repository, $versions, $here)Put a database's files on the target through its own restore: a dump made here of these versions, restored over the target's, its other files kept (no drop).
saveState()Write the state down: once per run, after everything was recorded.
scratch()
scratchShell()
sha()
stamp()
Status($local, $remote, $base) static
summary($entries, $releaseChanges)Where a target stands against this machine's copy, as a page or a script reads it: what compare found, counted and summed up in one word, the files that differ (each saying whether it is a dat…
unsafe($command)Run a command on the target even in a dry run: the temporary files of a reading, never the site's.
upload($files)Put files in place on the target, archiving what they replace first, under the target's deployment lock.
__construct($context, $project, $localUrls, $stateFolder, $tracked, $repositories, $full)
__destruct()

Constants6

BASE_LIMIT

a base copy is kept for a text up to this size: the three-way merge of something larger is no one's job

const BASE_LIMIT = 5242880

BOTH

changed on both sides: to merge, or one side to choose

const BOTH = 'both'

LOCAL

changed here since the last sync: to push

const LOCAL = 'local'

SAME

the same on both sides

const SAME = 'same'

SUMMARY_FILES

how many files of a status a summary lists: a site never synced lists every file, and a page shows the counts

const SUMMARY_FILES = 200

TARGET

changed on the target since the last sync: to pull

const TARGET = 'target'

Properties14

context

readonly
readonly MMO\admin\helpers\Context $context
Type
Context

full

readonly
readonly bool $full
Type
bool

localUrls

protected array $localUrls
Type
array

machinePaths

protected ?array $machinePaths = null
Type
null | array

owned

protected ?array $owned = null
Type
null | array

portable

protected ?MMO\admin\helpers\PortableContent $portable = null
Type
null | PortableContent

project

readonly
readonly string $project
Type
string

remote

protected ?array $remote = null
Type
null | array

repositories

protected array $repositories
Type
array

scratch

protected ?string $scratch = null
Type
null | string

state

protected ?array $state = null
Type
null | array

stateFolder

protected ?string $stateFolder
Type
null | string

tracked

protected array $tracked
Type
array

Methods46

baseOf($filename)

DataSync.php:171
protected function baseOf(string $filename): ?string
$filenamestring
returnsnull | stringthe content of $filename to keep as a base: a small file only, a database is never read whole

cleanup()

DataSync.php:775

Remove this run's temporary files: what was downloaded holds the site's data.

function cleanup(): void
returnsvoid

compare($only)

DataSync.php:308

Who changed what since the last sync.

function compare(?array $only = null): array
$only = nullnull | arraythese paths, or the folders they are in (null: every synced file)
returnsarraystring, status: string, local: ?string, remote: ?string, synced: bool}> every file of either side, SAME included; synced: whether it was ever synced

fetch($paths)

DataSync.php:431

Download the target's versions of files, as they are there.

function fetch(array $paths): array
$pathsarray
returnsarraystring> path => a local copy (in a temporary folder, removed by cleanup), for the files the target has

fetchRelease($paths)

DataSync.php:738

Download files of the live release, as they are there.

function fetchRelease(array $paths): array
$pathsarrayrelease-relative
returnsarraystring> path => a local copy

getBase($path)

DataSync.php:139
function getBase(string $path): ?string
$pathstring
returnsnull | stringthe version both sides held at the last sync, in its portable form; null when none is kept

getDatabaseFiles()

DataSync.php:86
function getDatabaseFiles(): array
returnsarrayint> the synced files that are a database's -- path => its index in $repositories: a database of files whose root is this project's (its dumps name the files as the paths here do)

getLastSync()

DataSync.php:136
function getLastSync(): ?string
returnsnull | stringwhen the last sync of this target was, or null: never

getMachinePaths()

DataSync.php:194
function getMachinePaths(): array
returnsarraythe folders of the project that are this machine's, never the site's data, whatever the paths say: each database's dumps (its getBackupFolder()), the jobs' state (mmo.core's JobStore), mmo.admin's .mmo/

getRoots()

DataSync.php:217
function getRoots(): array
returnsarraythe sync paths to read: an optional one is not even listed without a full copy (it is the heavy one)

getState()

DataSync.php:111
function getState(): array
returnsarrayat: when the last sync was (null: never); files: path => {local, remote, at}; databases: name => {at, mode}

installLocal($path, $source)

DataSync.php:676

Put a file in place here: a rename, with the rights of the file it replaces (the web server writes it).

protected function installLocal(string $path, string $source): void
$pathstring
$sourcestring
returnsvoid

isSynced($path)

DataSync.php:223
function isSynced(string $path): bool
$pathstring
returnsboolwhether $path is kept: one of the sync paths, or in one, and no exclusion matches it

local()

DataSync.php:246
function local(): array
returnsarraystring> path => sha256 of every synced file here

makePortable($path, $filename)

DataSync.php:415

Make a copy of a file portable, saying what still looks absolute in it.

protected function makePortable(string $path, string $filename): void
$pathstringits path, for the message
$filenamestringthe copy, rewritten in place
returnsvoid

Overall($counts)

staticDataSync.php:370
static function Overall(array $counts): string
$countsarray
returnsstringsynced, or what is to be done: TARGET (pull), LOCAL (push), BOTH (merge: both sides changed, a file each or the same file)

portable()

DataSync.php:396
function portable(): MMO\admin\helpers\PortableContent
returnsPortableContentthe target's urls and folders, and this machine's, made relative

publish($files)

DataSync.php:518

Write versions here, and on the target: what a merge decided, or the local ones (push).

function publish(array $files): void
$filesarray
returnsvoid

pull($files)

DataSync.php:490

Write the target's versions here, made portable, and remember both sides hold them.

function pull(array $files): void
$filesarray
returnsvoid

push($paths)

DataSync.php:568

Upload the local versions to the target.

function push(array $paths): void
$pathsarraywhat to push: a path absent here is removed there
returnsvoid

reading($command)

DataSync.php:822

Run a command on the target that only reads, even in a dry run (the runner lets only a few through).

protected function reading(string $command): MMO\core\server\ShellResult
$commandstring
returnsShellResult

readRemote($command)

DataSync.php:801

Run a command on the target whose output may be long, and read that output through a file.

protected function readRemote(string $command): string
$commandstring
returnsstring

record($path, $local, $remote, $content)

DataSync.php:152

Remember that both sides now hold the same version of $path.

function record(string $path, ?string $local, ?string $remote, ?string $content = null): void
$pathstring
$localnull | stringits sha256 here (null: it exists on neither side)
$remotenull | stringits sha256 on the target
$content = nullnull | stringthe version, portable, kept as the base of the next merge when it is a small text
returnsvoid

recordDatabase($name, $mode)

DataSync.php:127

Remember that a database server was pulled here or pushed there whole (data-pull, data-push): no file of it is compared, so this is all a status can say of it. Written at once, the files' last sync left as it is.

function recordDatabase(string $name, string $mode): void
$namestringthe database's name (the target's database)
$modestringpull or push
returnsvoid

releaseChanges($artifact)

DataSync.php:701

What was changed on the target in the release it runs: its files compared with the artifact it was shipped from.

function releaseChanges(?string $artifact): ?array
$artifactnull | stringthe artifact of the live release, here (the build folder keeps it); null: unknown
returnsnull | arraystring>|null path => modified, added or deleted; null when the artifact is not here

remote()

DataSync.php:282
function remote(): array
returnsarraystring> path => sha256 of every synced file on the target, read once

remoteFilename($path)

DataSync.php:274
function remoteFilename(string $path): string
$pathstringa release-relative path
returnsstringwhere it is on the target: in shared/ when it is shared, else in the live release

remoteSums($paths)

DataSync.php:550
function remoteSums(array $paths): array
$pathsarray
returnsarraystring> path => its sha256 on the target, for the files it has

restoreDatabase($repository, $versions, $here)

DataSync.php:658

Put a database's files on the target through its own restore: a dump made here of these versions, restored over the target's, its other files kept (no drop).

protected function restoreDatabase( MMO\core\interfaces\iBackupRepository $repository, array $versions, bool $here = false ): void
$repositoryiBackupRepository
$versionsarray
$here = falseboolrestore it in this project rather than on the target
returnsvoid

saveState()

DataSync.php:176

Write the state down: once per run, after everything was recorded.

function saveState(): void
returnsvoid

scratch()

DataSync.php:763
function scratch(): string
returnsstringthis run's temporary folder here, readable by its owner only

scratchShell()

DataSync.php:772
function scratchShell(): MMO\core\server\ShellRunner
returnsShellRunnercommands on this machine's temporary files: run in a dry run too, they change nothing of the site's

stamp()

DataSync.php:783
protected function stamp(): string
returnsstringa name for this run's files on the target: when, and by whom

summary($entries, $releaseChanges)

DataSync.php:344

Where a target stands against this machine's copy, as a page or a script reads it: what compare found, counted and summed up in one word, the files that differ (each saying whether it is a database's), the live release's edited files, and the database servers -- which no file holds: when each was last pulled or pushed.

function summary(array $entries, ?array $releaseChanges = null): array
$entriesarraycompare
$releaseChanges = nullnull | array
returnsarraystring, lastSync: ?string, counts: array<string, int>, files: list<array{path: string, status: string, database: bool}>, more: int, release: ?array{changed: int, files: array<string, string>}, databases: array<string, ?array{at: string, mode: string}>} status: synced (nothing differs), TARGET (to pull), LOCAL (to push), BOTH (to merge)

unsafe($command)

DataSync.php:836

Run a command on the target even in a dry run: the temporary files of a reading, never the site's.

protected function unsafe(string $command): void
$commandstring
returnsvoid
throws

upload($files)

DataSync.php:583

Put files in place on the target, archiving what they replace first, under the target's deployment lock.

protected function upload(array $files): void
$filesarray
returnsvoid
throws

__construct($context, $project, $localUrls, $stateFolder, $tracked, $repositories, $full)

DataSync.php:66
function __construct( MMO\admin\helpers\Context $context, string $project, array $localUrls = [], ?string $stateFolder = null, array $tracked = [], array $repositories = [], bool $full = false )
$contextContextthe target, its shell and its lock
$projectstringthe project's folder here: where each path of a release is
$localUrls = []arraythis machine's urls of the application, made relative too
$stateFolder = nullnull | stringwhere the state of the syncs is kept (null: the project's .mmo/sync)
$tracked = []arraythe project's files git tracks, never synced
$repositories = []arraythe application's databases, getDatabaseFiles
$full = falsebool$full