This method migrates an old store to a new store.
It does however validate that the environment is valid
before adding it to the store.

@param string $oldStore Is the path to the old store

@return array of new environments
195836
protected function migrateEnvironments($oldStore)
    {
        $currentStore = $this->getFileName();   //As a local cache
        if (false == file_exists($oldStore)) {
            $this->printLn("Old store not found at {$oldStore}", 'error');
        } else {
            $this->printLn("Old store found {$oldStore}");
        }
        $this->setFileName($oldStore);
        $this->loadEnvironments();
        $this->printLn("Old environments loaded");
        $oldEnvironments = $this->getEnvironments();
        $this->setFileName($currentStore);
        $this->loadEnvironments();
        foreach ($oldEnvironments as $oldEnvironment) {
            /*
             * Doing it this way validates the environment exists
             * before adding them to the store
             */
            $this->createEnvironment($oldEnvironment);
        }
        $this->save();
        $this->printLn("Old environments appended onto current store");
        $this->getEnvironments();
    }
990398
public static function load() : MigrationStore
    {
        if (is_null(self::$instance)) {
            self::$instance = new MigrationStore(Connection::get());
        }

        return self::$instance;
    }
635935
public function getAllEnvironmentsSorted(?callable $sorter = null)
    {
        $environments = $this->findAll();

        if ($sorter) {
            usort($environments, $sorter);
        } else {
            usort($environments, $this->environmentSorter());
        }

        return $environments;
    }
1309744
protected function getListCollectionStore()
    {
        if (empty($this->data_store['store_id'])) {
            return array();
        }

        $conditions = array(
            'status' => 1,
            'store_id' => $this->data_store['store_id']
        );

        $collections = (array) $this->collection->getList($conditions);

        $list = array();
        foreach ($collections as $collection) {
            $list[$collection['type']][$collection['collection_id']] = $collection;
        }

        return $list;
    }
979443
public function merge(array $data)
    {
        $oldStorage = $this->storage;
        $this->storage = array_merge($this->storage, $data);

        return $oldStorage;
    }
1263
def run_migration(data, version_start, version_end):
    """"""
    items = []
    if version_start == 1 and version_end == 2:
        for item in data['accounts']:
            items.append(v2.upgrade(item))

    if version_start == 2 and version_end == 1:
        for item in data:
            items.append(v2.downgrade(item))
        items = {'accounts': items}
    return items
1069843
public function getDefaultCacheStore(): ?Store
    {
        // We do not know what store is desired. Therefore,
        // the safest bet is to obtain the default
        $manager = Cache::getFacadeRoot();
        if (isset($manager)) {
            /** @var Repository $repository */
            $repository = $manager->store();
            return $repository->getStore();
        }
        return $manager;
    }
1152051
public function getCacheStore(): ?Store
    {
        if (!$this->hasCacheStore()) {
            $this->setCacheStore($this->getDefaultCacheStore());
        }
        return $this->cacheStore;
    }
1144934
public function setStore( &$store ) {
		if ( ! $this->isValidStore( $store ) ) {
			return;
		}

		$this->store = &$store;

		if ( ! isset( $this->store[ $this->store_key ] ) ) {
			$this->store[ $this->store_key ] = [
				static::CURRENT_KEY => [],
				static::NEXT_KEY => [],
			];
		}

		$this->flashed = $store[ $this->store_key ];
	}
873542
public function getMigrate($env = null, $target = null)
    {
        $command = ['migrate'];
        if ($env ?: $this->hasOption('environment')) {
            $command += ['-e' => $env ?: $this->getOption('environment')];
        }
        if ($this->hasOption('configuration')) {
            $command += ['-c' => $this->getOption('configuration')];
        }
        if ($this->hasOption('parser')) {
            $command += ['-p' => $this->getOption('parser')];
        }
        if ($target) {
            $command += ['-t' => $target];
        }

        return $this->executeRun($command);
    }
530836
protected function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = $this->merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
1161766
private function initStores($storeIds)
    {
        if (!is_array($storeIds)) {
            $storeIds = explode(',', $storeIds);
        }

        $availableStores = $this->storeManager->getStores(true);

        foreach ($availableStores as $availableStore) {
            if (in_array($availableStore->getId(), $storeIds)) {
                $this->storeIds[$availableStore->getId()] = $availableStore;
            }
        }

        return $this;
    }
1347198
public static function move($oldName, $newName, $context = null)
    {
        return self::rename($oldName, $newName, $context);
    }
362823
protected function mergeConfigs(array $old, array $new) : array
    {
      foreach ($new as $key => $val) {
        if (!array_key_exists($key, $old) || !is_array($old[$key]) || !is_array($val)) {
          $old[$key] = $val;
          continue;
        }

        if (is_int($key)) {
          $old[] = $val;
          continue;
        }

        $old[$key] = $this->mergeConfigs($old[$key], $val);
      }

      return $old;
    }
1293064
public function upgradeDatabase()
    {
        $this->refreshEntities([
            OneAssociation::class,
            ManyAssociation::class,
            AssociationEntry::class,
            Entry::class,
            Entry\Association::class,
        ]);

        // Migrate data from old entries table to new
        if ($this->connection->tableExists('ExpressEntityAssociationSelectedEntries')) {
            $this->connection->transactional(function ($db) {
                $r = $db->query('select * from ExpressEntityAssociationSelectedEntries');
                while ($row = $r->fetchRow()) {
                    $db->insert('ExpressEntityAssociationEntries', [
                        'association_id' => $row['id'], 'exEntryID' => $row['exSelectedEntryID']
                    ]);
                }
                $this->connection->Execute('alter table ExpressEntityAssociationSelectedEntries rename _ExpressEntityAssociationSelectedEntries');
            });
        }

    }
595653
public function join($secondStore,$matching)
    {
        $dstore = new DataStore;
        // join with other datasource to produce new one with above condition
        $firstKeys = array_keys($matching);
        $secondKeys = array_values($matching);
        
        
        $firstMaps = $this->_mapKeyIndex($this->rows, $firstKeys);
        $secondMaps = $this->_mapKeyIndex($secondStore->all(), $secondKeys);
        
        foreach ($firstMaps as $key=>$indices) {
            if (isset($secondMaps[$key])) {
                foreach ($indices as $i) {
                    foreach ($secondMaps[$key] as $j) {
                        $dstore->push(
                            array_merge(
                                $this->rows[$i],
                                $secondStore->get($j)
                            )
                        );
                    }
                }
            }
        }

        $columnMeta = array_merge($this->metaData["columns"], $secondStore->meta()["columns"]);
        $dstore->meta(array("columns"=>$columnMeta));
        return $dstore;
    }
1060678
public function recursivelyFindAndReplaceExecutableCode($old)
    {
        if ($this->isArray($old)) {
            return collect($old)->map(function ($item) {
                return $this->recursivelyFindAndReplaceExecutableCode($item);
            });
        }

        $new = $this->replaceContents($old);

        if ($new !== $old) {
            $this->replaced++;
        }

        return $new;
    }