private function compareCacheAndSqlEntities(bool $doRefresh) : array
    {
        // If there was an issue grabbing all entities in cache, null will be returned
        $unkeyedCacheEntities = $this->cacheDataMapper->getAll();

        if ($unkeyedCacheEntities === null) {
            $unkeyedCacheEntities = [];
        }

        $cacheEntities = $this->keyEntityArray($unkeyedCacheEntities);
        $sqlEntities = $this->keyEntityArray($this->sqlDataMapper->getAll());
        $unsyncedEntities = [
            'missing' => [],
            'differing' => [],
            'additional' => []
        ];

        // Compare the entities in the SQL database to those in cache
        foreach ($sqlEntities as $sqlId => $sqlEntity) {
            if (isset($cacheEntities[$sqlId])) {
                // The entity appears in cache
                $cacheEntity = $cacheEntities[$sqlId];

                if ($sqlEntity != $cacheEntity) {
                    $unsyncedEntities['differing'][] = $sqlEntity;

                    if ($doRefresh) {
                        // Sync the entity in cache with the one in SQL
                        $this->cacheDataMapper->delete($cacheEntity);
                        $this->cacheDataMapper->add($sqlEntity);
                    }
                }
            } else {
                // The entity was not in cache
                $unsyncedEntities['missing'][] = $sqlEntity;

                if ($doRefresh) {
                    // Add the entity to cache
                    $this->cacheDataMapper->add($sqlEntity);
                }
            }
        }

        // Find entities that only appear in cache
        $cacheOnlyIds = array_diff(array_keys($cacheEntities), array_keys($sqlEntities));

        foreach ($cacheOnlyIds as $entityId) {
            $cacheEntity = $cacheEntities[$entityId];
            $unsyncedEntities['additional'][] = $cacheEntity;

            if ($doRefresh) {
                // Remove the entity that only appears in cache
                $this->cacheDataMapper->delete($cacheEntity);
            }
        }

        return $unsyncedEntities;
    }
private function compareCacheAndSqlEntities(bool $doRefresh) : array
    {
        // If there was an issue grabbing all entities in cache, null will be returned
        $unkeyedCacheEntities = $this->cacheDataMapper->getAll();

        if ($unkeyedCacheEntities === null) {
            $unkeyedCacheEntities = [];
        }

        $cacheEntities = $this->keyEntityArray($unkeyedCacheEntities);
        $sqlEntities = $this->keyEntityArray($this->sqlDataMapper->getAll());
        $unsyncedEntities = [
            'missing' => [],
            'differing' => [],
            'additional' => []
        ];

        // Compare the entities in the SQL database to those in cache
        foreach ($sqlEntities as $sqlId => $sqlEntity) {
            if (isset($cacheEntities[$sqlId])) {
                // The entity appears in cache
                $cacheEntity = $cacheEntities[$sqlId];

                if ($sqlEntity != $cacheEntity) {
                    $unsyncedEntities['differing'][] = $sqlEntity;

                    if ($doRefresh) {
                        // Sync the entity in cache with the one in SQL
                        $this->cacheDataMapper->delete($cacheEntity);
                        $this->cacheDataMapper->add($sqlEntity);
                    }
                }
            } else {
                // The entity was not in cache
                $unsyncedEntities['missing'][] = $sqlEntity;

                if ($doRefresh) {
                    // Add the entity to cache
                    $this->cacheDataMapper->add($sqlEntity);
                }
            }
        }

        // Find entities that only appear in cache
        $cacheOnlyIds = array_diff(array_keys($cacheEntities), array_keys($sqlEntities));

        foreach ($cacheOnlyIds as $entityId) {
            $cacheEntity = $cacheEntities[$entityId];
            $unsyncedEntities['additional'][] = $cacheEntity;

            if ($doRefresh) {
                // Remove the entity that only appears in cache
                $this->cacheDataMapper->delete($cacheEntity);
            }
        }

        return $unsyncedEntities;
    }
private function compareCacheAndSqlEntities ( bool $ doRefresh ) : array { // If there was an issue grabbing all entities in cache, null will be returned $ unkeyedCacheEntities = $ this -> cacheDataMapper -> getAll ( ) ; if ( $ unkeyedCacheEntities === null ) { $ unkeyedCacheEntities = [ ] ; } $ cacheEntities = $ this -> keyEntityArray ( $ unkeyedCacheEntities ) ; $ sqlEntities = $ this -> keyEntityArray ( $ this -> sqlDataMapper -> getAll ( ) ) ; $ unsyncedEntities = [ 'missing' => [ ] , 'differing' => [ ] , 'additional' => [ ] ] ; // Compare the entities in the SQL database to those in cache foreach ( $ sqlEntities as $ sqlId => $ sqlEntity ) { if ( isset ( $ cacheEntities [ $ sqlId ] ) ) { // The entity appears in cache $ cacheEntity = $ cacheEntities [ $ sqlId ] ; if ( $ sqlEntity != $ cacheEntity ) { $ unsyncedEntities [ 'differing' ] [ ] = $ sqlEntity ; if ( $ doRefresh ) { // Sync the entity in cache with the one in SQL $ this -> cacheDataMapper -> delete ( $ cacheEntity ) ; $ this -> cacheDataMapper -> add ( $ sqlEntity ) ; } } } else { // The entity was not in cache $ unsyncedEntities [ 'missing' ] [ ] = $ sqlEntity ; if ( $ doRefresh ) { // Add the entity to cache $ this -> cacheDataMapper -> add ( $ sqlEntity ) ; } } } // Find entities that only appear in cache $ cacheOnlyIds = array_diff ( array_keys ( $ cacheEntities ) , array_keys ( $ sqlEntities ) ) ; foreach ( $ cacheOnlyIds as $ entityId ) { $ cacheEntity = $ cacheEntities [ $ entityId ] ; $ unsyncedEntities [ 'additional' ] [ ] = $ cacheEntity ; if ( $ doRefresh ) { // Remove the entity that only appears in cache $ this -> cacheDataMapper -> delete ( $ cacheEntity ) ; } } return $ unsyncedEntities ; }
Does the comparison of entities in cache to entities in the SQL database
Also performs refresh if the user chooses to do so

@param bool $doRefresh Whether or not to refresh any unsynced entities
@return object[] The list of entities that were not already synced
The "missing" list contains the entities that were not in cache
The "differing" list contains the entities in cache that were not the same as SQL
The "additional" list contains entities in cache that were not at all in SQL
@throws OrmException Thrown if there was an error getting the unsynced entities
Does the comparison of entities in cache to entities in the SQL database Also performs refresh if the user chooses to do so