PHPackages                             bvisonl/sync-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bvisonl/sync-bundle

ActiveSymfony-bundle[Utility &amp; Helpers](/categories/utility)

bvisonl/sync-bundle
===================

Symfony NTISyncBundle

1.4.0(4y ago)062MITPHP

Since Dec 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/bvisonl/SyncBundle)[ Packagist](https://packagist.org/packages/bvisonl/sync-bundle)[ RSS](/packages/bvisonl-sync-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (1)Versions (11)Used By (0)

NTISyncBundle
=============

[](#ntisyncbundle)

### Installation

[](#installation)

1. Install the bundle using composer:

    ```
    $ composer require nti/sync-bundle "dev-master"

    ```
2. Add the bundle configuration to the AppKernel

    ```
    public function registerBundles()
    {
        $bundles = array(
            ...
            new NTI\SyncBundle\NTISyncBundle(),
            ...
        );
    }

    ```
3. Update the database schema

    ```
    $ php app/console doctrine:schema:update

    ```
4. Add the routes to your `routing.yml`

    ```
    ...
    nti_sync:
        resource: "@NTISyncBundle/Resources/config/routing.yml"

    ```

Requirements
------------

[](#requirements)

Below are a list of things that need to be considered in order to implement this bundle:

1. Any Entity that needs to be taken into account during the synchronization process must have the `@NTI\SyncEntity` annotation at the class level.
2. `ManyToOne` relationships that should alter the last synchronization timestamp of their parents should use the annotation `@NTI\SyncParent(getter="[Getter Name]")` (see example below for more information).
3. Entities to be synced must have a repository implementing the `SyncRepositoryInterface` (see below for more information).
4. The mapping `SyncMapping` needs to be configured foreach entity as it is the list used as reference for the lookup.
5. The `SyncState` should be created for each mapping. This can be done with this query after creating all the `SyncMapping`: ```
    `INSERT INTO nti_sync_state(mapping_id, timestamp) SELECT id, 0  FROM sync_nti_mapping;`

    ```
6. If the entity is going to be synched FROM the client, then a service must be defined in the `SyncMapping` database entry. Also, this method needs to implement the interface `SyncServiceInterface`.

Tracking Changes
----------------

[](#tracking-changes)

The way that the bundle tracks changes in the synchronization is as follows:

1. The bundle has a `DoctrineEventListener` listening to the `onFlush` event.
2. Once the event is fired, the bundle will grab every entitty that has the `@NTI\SyncEntity` annotation.
3. If the entity has a `SyncMapping` defined, the system will update the `last_timestamp` field of this mapping to the current `time()`.
4. If the entity has a method called `setLastTimestamp()` it will be called with the `time()` as a parameter and the changes will be recomputed or computed.
5. All the properties of the entity will be examined in search for a property that contains the annotation `@NTI\SyncParent(getter="[Getter Name]")`. If found, the getter will be called, if the result is an object that also has the `@NTI\SyncEntity`, it will be processed again starting from point #3. This process occurrs recursively.

Configuration
-------------

[](#configuration)

Below is the default configuration for the bundle. In case you need to modify the defaults this would go in your `config.yml`:

```
nti_sync:
  deletes:

    # Identifier to use when an item gets deleted. This would go in your `deletes` section as shown below
    identifier_getter: "getId"

```

Class Examples
--------------

[](#class-examples)

```
```
