예제 #1
0
 public function testFindAndUpdateState()
 {
     // This is a new entity collection
     $state = new SyncState('book');
     $state->setLastValue(42);
     $this->gateway->updateState($state);
     $newState = $this->gateway->findStateByEntityName('book');
     $this->assertEquals(42, $newState->getLastValue());
     $newState->setLastValue(777);
     $this->gateway->updateState($newState);
     $newestState = $this->gateway->findStateByEntityName('book');
     $this->assertEquals(777, $newestState->getLastValue());
 }
예제 #2
0
 /**
  * Process the resulting entity data collection retrieved by a service adapter.
  * Test if any dependencies do exist and retrieve those dependencies if they haven't
  * been yet retrieved
  *
  * @param SyncState                           $state
  * @param \Vespolina\Sync\Entity\EntityData[] $entitiesData
  */
 protected function processEntityDataCollection(SyncState $state, array $entitiesData)
 {
     if (count($entitiesData) == 0) {
         return;
     }
     foreach ($entitiesData as $entityData) {
         $resolved = true;
         // If an entity requires dependencies, initiate dependency resolving
         // Depending on the configuration it will be resolved immediately or delayed
         if ($unresolvedDependencies = $entityData->getUnresolvedDependencies()) {
             $resolved = $this->processEntityDataCollectionDependencies($entityData, $unresolvedDependencies);
         }
         if (true == $resolved) {
             // Transform the entity data into a real entity
             $localEntity = $this->transformEntityData($entityData);
         } else {
             // Add to queue
             $this->gateway->updateEntityData($entityData);
         }
     }
     // Get the last entity
     $lastEntityData = end($entitiesData);
     $state->setLastValue($lastEntityData->getEntityId());
     // TODO: use config
 }