private function migrateData($legacySaveFile)
    {
        $data = $this->readJson($legacySaveFile);

        if (null === $data) {
            unlink($legacySaveFile);
            return null;
        }

        //lets check if the data is in the old format
        if (!isset($data['completed_exercises']) || !isset($data['current_exercise'])) {
            unlink($legacySaveFile);
            return null;
        }

        $completedExercises = $data['completed_exercises'];
        $availableExercises = $this->exerciseRepository->getAllNames();

        //check to see if this old data represents THIS workshop
        //if not we bail
        foreach ($completedExercises as $completedExercise) {
            if (!in_array($completedExercise, $availableExercises)) {
                return null;
            }
        }

        $userState = new UserState($data['completed_exercises'], $data['current_exercise']);
        $this->serialize($userState);

        unlink($legacySaveFile);
        return $userState;
    }
private function migrateData($legacySaveFile)
    {
        $data = $this->readJson($legacySaveFile);

        if (null === $data) {
            unlink($legacySaveFile);
            return null;
        }

        //lets check if the data is in the old format
        if (!isset($data['completed_exercises']) || !isset($data['current_exercise'])) {
            unlink($legacySaveFile);
            return null;
        }

        $completedExercises = $data['completed_exercises'];
        $availableExercises = $this->exerciseRepository->getAllNames();

        //check to see if this old data represents THIS workshop
        //if not we bail
        foreach ($completedExercises as $completedExercise) {
            if (!in_array($completedExercise, $availableExercises)) {
                return null;
            }
        }

        $userState = new UserState($data['completed_exercises'], $data['current_exercise']);
        $this->serialize($userState);

        unlink($legacySaveFile);
        return $userState;
    }
private function migrateData ( $ legacySaveFile ) { $ data = $ this -> readJson ( $ legacySaveFile ) ; if ( null === $ data ) { unlink ( $ legacySaveFile ) ; return null ; } //lets check if the data is in the old format if ( ! isset ( $ data [ 'completed_exercises' ] ) || ! isset ( $ data [ 'current_exercise' ] ) ) { unlink ( $ legacySaveFile ) ; return null ; } $ completedExercises = $ data [ 'completed_exercises' ] ; $ availableExercises = $ this -> exerciseRepository -> getAllNames ( ) ; //check to see if this old data represents THIS workshop //if not we bail foreach ( $ completedExercises as $ completedExercise ) { if ( ! in_array ( $ completedExercise , $ availableExercises ) ) { return null ; } } $ userState = new UserState ( $ data [ 'completed_exercises' ] , $ data [ 'current_exercise' ] ) ; $ this -> serialize ( $ userState ) ; unlink ( $ legacySaveFile ) ; return $ userState ; }
On early versions of the workshop the save data was not namespaced
and therefore it was impossible to have data for more than one workshop
at the same time. Therefore we must try to migrate that data in to the new namespaced
format in order to preserve users save data.

We can only migrate data when using the workshop the data was originally saved from.

@param string $legacySaveFile
@return null|UserState
On early versions of the workshop the save data was not namespaced and therefore it was impossible to have data for more than one workshop at the same time . Therefore we must try to migrate that data in to the new namespaced format in order to preserve users save data .