/** * Create outgoing sync objects(s) from local changes or for re-routing * * Make one or more sync objects depending on the context of this change * - The sync re-routing logic is in here * - $origin is the server the change came from if set * - $private is the owner's server if set */ public static function create($crud, $fields, $origin, $private = false) { $server = LigminchaGlobalServer::getCurrent(); // Origin is set if this change is the result of a received foreign sync object if ($origin) { // This is the only condition for which re-routing ever occurs if ($server->isMaster && $private === false) { // Create targetted sync objects for all except self and origin foreach (LigminchaGlobalServer::select() as $s) { if ($s->id != $server->id && $s->id != $origin) { new LigminchaGlobalSync($crud, $fields, $s); } } } } else { // If this is the master, then targets depend whether its private or not if ($server->isMaster) { // If private then we just have a single targetted sync object to the owner if ($private) { new LigminchaGlobalSync($crud, $fields, $private); } else { foreach (LigminchaGlobalServer::select() as $s) { if ($s->id != $server->id) { new LigminchaGlobalSync($crud, $fields, $s); } } } } else { new LigminchaGlobalSync($crud, $fields, LigminchaGlobalServer::getMaster()); } } }