Save migration file.

@param string $filePath  Name of migration file
@param string $migration Migration code
504250
protected function saveMigrationFile($filePath, $migration)
    {
        $this->getOutput()->writeln(sprintf('Generate migration file: %s', $filePath));
        file_put_contents($filePath, $migration);
    }
22608
protected function runMigrationByPaths($migrationPaths, $command)
    {
        $app = $this->mockApplication();

        $this->validateMigrationPaths($migrationPaths);

        /* @todo: since version 2.0.12 you may also specify an array of migration paths. */
        foreach ($migrationPaths as $migrationPath) {
            $migrateController = $this->buildMigration($app);
            $migrateController->migrationPath = $migrationPath;

            $this->runMigration($migrateController, $command);
        }

        $this->destroyApplication();
    }
1367146
public function down(Migration $migration, $loadFromFile = false)
    {
        if ($loadFromFile) {
            $this->fileRepository->loadSql($migration);
        } else {
            $this->dbRepository->loadSql($migration);
        }

        $func = function () use ($migration) {
            $this->_processMigrationSql($migration->getDown());
            $this->dbRepository->delete($migration);
        };

        $this->_processMigration($migration, $func);
    }
1295690
public function saveFile($filePath, $fileContent)
    {
        if (false === is_dir(dirname($filePath))) {
            mkdir(dirname($filePath), 0755);
        }

        return file_put_contents($filePath, $fileContent);
    }
470204
public function remove($migrationName) {
		$list = $this->getList(false);
		unset($list[$migrationName]);
		$this->writeMigrations($list);
	}
1217319
protected function markMigration($migrationName, $fileName)
    {
        $this->getOutput()->writeln('Mark migration');

        /* @var Adapter\AdapterInterface $adapter */
        $adapter = $this->settings['adapter'];

        /* @var $manager Manager */
        $manager = $this->settings['manager'];

        $envName = $this->settings['environment'];

        /* @var $env Environment */
        $env = $manager->getEnvironment($envName);
        $schemaTableName = $env->getSchemaTableName();

        /* @var $pdo \PDO */
        $pdo = $this->settings['adapter'];

        // Get version from filename prefix
        $version = explode('_', $fileName)[0];

        // Record it in the database
        $time = time();
        $startTime = date('Y-m-d H:i:s', $time);
        $endTime = date('Y-m-d H:i:s', $time);
        $breakpoint = 0;

        $sql = sprintf(
            "INSERT INTO %s (%s, %s, %s, %s, %s) VALUES ('%s', '%s', '%s', '%s', %s);",
            $schemaTableName,
            $adapter->quoteColumnName('version'),
            $adapter->quoteColumnName('migration_name'),
            $adapter->quoteColumnName('start_time'),
            $adapter->quoteColumnName('end_time'),
            $adapter->quoteColumnName('breakpoint'),
            $version,
            substr($migrationName, 0, 100),
            $startTime,
            $endTime,
            $breakpoint
        );

        $pdo->query($sql);
    }
1202977
public function save(File $file, $preparedPath)
    {
        if (false === ($i = array_search($preparedPath, $this->preparedPaths))) {
            throw new \RuntimeException("{$preparedPath} is not prepared by the filemanager");
        }
        unset($this->preparedPaths[$i]);
        $existed = $this->fs->exists($preparedPath);
        @$this->fs->remove($preparedPath);

        try {
            $this->dispatchEvent($existed ? ResourceEvent::REPLACED : ResourceEvent::CREATED, $preparedPath);
            $file->move(dirname($preparedPath), basename($preparedPath));
        } catch (FileException $fileException) {
            throw new FileException(
                $fileException->getMessage() . "\n(hint: check the 'upload_max_filesize' in php.ini)",
                0,
                $fileException
            );
        }
    }
487380
public function saveToFile($filePath,$format = 'csvforexcel')
    {
        $this->format(Format::get($format));
        $this->run();

        $this->data->saveToFile($filePath);

        return true;
    }
83680
private function writeMigration($name, $eventObjectTable, $actionTiming, $event)
    {
        $file = pathinfo($this->creator->write(
            $name,
            $eventObjectTable,
            $actionTiming,
            $event,
            $this->getMigrationPath()
        ), PATHINFO_FILENAME);

        $this->line("<info>Created Migration:</info> {$file}");
    }
1042060
public function move($file, $filePath)
	{
 		$this->buildDirectory($filePath);
 		$this->moveFile($file, $filePath);
        $this->setPermissions($filePath, $this->attachedFile->override_file_permissions);
	}
616445
private function _processMigration(Migration $migration, callable $command)
    {
        if ($migration->isTransaction()) {
            $this->getDbRepository()->getAdapter()->transaction($command);
        } else {
            if ($this->logger) {
                $this->logger->alert('NO TRANSACTION!');
            }
            $command();
        }
    }
1071034
protected function loadMigrationsFrom($paths): void
    {
        $options = \is_array($paths) ? $paths : ['--path' => $paths];

        if (isset($options['--realpath']) && \is_string($options['--realpath'])) {
            $options['--path'] = [$options['--realpath']];
        }

        $options['--realpath'] = true;

        $migrator = new MigrateProcessor($this, $options);
        $migrator->up();

        $this->beforeApplicationDestroyed(function () use ($migrator) {
            $migrator->rollback();
        });
    }
514689
public function move($file, $filePath)
	{
 		$this->getS3Client()->putObject(['Bucket' => $this->getBucket(), 'Key' => $filePath, 'SourceFile' => $file, 'ContentType' => $this->attachedFile->contentType(), 'ACL' => $this->attachedFile->ACL]);
	}
1198567
public function migrate($diffVersion = false) {
		
		$migrations      = new \DirectoryIterator(__DIR__."/../../migrations/");
		$migrationsValid = array();
		
		foreach ($migrations as $migration) {
			$filename = $migration->getFilename();
			if (!$migration->isDot() && $migration->isFile() && ($filename[0] != "_")) {
				$migrationsValid[] = $filename;
			}
		}
		
		asort($migrationsValid);
		
		foreach ($migrationsValid as $filename) {
			
			$basePath        = __DIR__."/../../../";
			$migrationData   = json_decode(file_get_contents(__DIR__."/../../migrations/".$filename));
			$checkType       = $migrationData->checkType;
			$sourcePath      = ($checkType == "fileExists") ? $basePath.$migrationData->sourcePath : $basePath.$migrationData->sourcePath.DIRECTORY_SEPARATOR;
			$destinationPath = ($checkType == "fileExists") ? $basePath.$migrationData->destinationPath : $basePath.$migrationData->destinationPath.DIRECTORY_SEPARATOR;
			
			if ($checkType == "dirEmpty") {
				
				$emptyDir = true;
				$objects  = new \DirectoryIterator($destinationPath);
				foreach ($objects as $object) {
					if (!$object->isDot() && ($object->getFilename() != "README") && ($object->getFilename() != ".DS_Store")) {
						$emptyDir = false;
					}
				}
				
				if ($emptyDir) {
					$this->runMigration($filename, $sourcePath, $destinationPath, false);
				}
				
			} else if ($checkType == "dirExists") {
				
				if (!is_dir($destinationPath)) {
					mkdir($destinationPath);
				}
				
			} else if ($checkType == "fileExists") {
				
				if (!file_exists($destinationPath)) {
					$this->runMigration($filename, $sourcePath, $destinationPath, true);
				}
				
			} else if (($checkType == "versionDiffDir") && $diffVersion) {
				
				// make sure the destination path exists
				if (!is_dir($destinationPath)) {
					mkdir($destinationPath);
				}
				
				$this->runMigration($filename, $sourcePath, $destinationPath, false);
				
			} else if (($checkType == "versionDiffFile") && $diffVersion) {
				
				$this->runMigration($filename, $sourcePath, $destinationPath, true);
				
			} else {
				
				print "pattern Lab doesn't recognize a checkType of ".$checkType.". The migrator class is pretty thin at the moment.\n";
				exit;
				
			}
			
		}
		
	}
576174
public function save($filePath = null) {
		
		// Determine the correct file path.
		$filePath = ($filePath == null) ? $this->configFilePath : $filePath;
		
		// Store the file
		file_put_contents ( $filePath, $this->getConfigFileText () );
	}
878341
protected function writeMigration($name)
    {
        $path = $this->getMigrationPath();

        if($file = pathinfo($this->creator->create($name, $path, $this->migrations), PATHINFO_FILENAME)){

            $this->line("<info>Created Migration:</info> $file");
        } else{

            $this->error("<info>Nothing to migrate.</info>");
        }
    }
763669
public function newMigration()
    {
        $fileName = (isset($this->arguments[1])) ? $this->arguments[1] : null;
        $this->migrateManager->newMigration($fileName);
    }