Create project migration

@access private
@param string $name
@return string $path
512136
private function create_project_migration($name) {
		$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);

		$datetime = date('Ymd_His');
		$filename = $datetime . '_' . strtolower($name) . '.php';
		$classname = 'Migration_' . $datetime . '_' . ucfirst($name);

		$template = file_get_contents(__DIR__ . '/../template/migration.php');
		$template = str_replace('%%namespace%%', '', $template);
		$template = str_replace('%%classname%%', $classname, $template);
		file_put_contents(\Skeleton\Database\Migration\Config::$migration_directory . '/' . $filename, $template);
		return \Skeleton\Database\Migration\Config::$migration_directory . '/' . $filename;
	}
400411
public function child($name)
    {
        $path = $this->normalize($name);

        $this->append($path);

        return $this;
    }
1335123
private function create_package_migration($name) {
		list($packagename, $name) = explode('/', $name);

		$skeleton_packages = \Skeleton\Core\Skeleton::get_all();
		$package = null;
		foreach ($skeleton_packages as $skeleton_package) {
			if ($skeleton_package->name == $packagename) {
				$package = $skeleton_package;
			}
		}

		if ($package === null) {
			throw new \Exception('Package ' . $packagename . ' not found');
		}

		if (!file_exists($package->migration_path)) {
			mkdir($package->migration_path);
		}

		$name = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), $name);

		$datetime = date('Ymd_His');
		$filename = $datetime . '_' . strtolower($name) . '.php';
		$classname = 'Migration_' . $datetime . '_' . ucfirst($name);

		$namespace_parts = explode('-', $package->name);
		foreach ($namespace_parts as $key => $namespace_part) {
			$namespace_parts[$key] = ucfirst($namespace_part);
		}
		$namespace = implode('\\', $namespace_parts);

		$template = file_get_contents(__DIR__ . '/../template/migration.php');
		$template = str_replace('%%namespace%%', 'namespace ' . $namespace . ';' . "\n", $template);
		$template = str_replace('%%classname%%', $classname, $template);
		file_put_contents($package->migration_path . '/' . $filename, $template);
		return $package->migration_path . '/' . $filename;
	}
381839
protected function getMigrationFile($name, $path = false)
    {
        $path = $path ? $path : $this->migrationPath;
        return $path . DIRECTORY_SEPARATOR . $name . '.php';
    }
1296897
public function rename($name)
    {
        $newPath = sys_get_temp_dir() . "/$name";
        $ret = rename($this->path(), $newPath);
        $this->path = $newPath;

        return $ret;
    }
492948
protected function _mkfile($path, $name) {
		return $this->make($path, $name, 'text/plain') ? $this->_joinPath($path, $name) : false;
	}
551624
private function migrate($name, $params = [])
    {
        $generator = new TemplateGenerator();
        $generator->setContent(file_get_contents($name));

        return $generator->generate($params);
    }
173283
public static function createMigration(string $name): void
    {
        $directory = Application::getApplicationPath('migrations');

        if (!is_dir($directory)) {
            Directory::mkdir($directory, 0755);
        }

        $timestamp = time();
        $className = Util::camelCase($name, null, false);
        $phpClassName = "Migration_{$timestamp}_{$className}";
        $fileName = "{$timestamp}_{$className}.php";
        $fullPath = Application::getApplicationPath("migrations/{$fileName}");

        $migrationFileContent = file_get_contents(__DIR__ . '/MigrationTemplate.php');
        $migrationFileContent = str_replace('templateClassName', $phpClassName, $migrationFileContent);
        $migrationFileContent = str_replace('templateClassGenerated', date('r'), $migrationFileContent);

        if (file_put_contents($fullPath, $migrationFileContent) === false) {
            throw new Application\Exception("Unable to write to migration file on path={$fullPath}");
        }

        Log::info("Created DB migration with name: {$name}");
        Log::info("You may now open application/migrations/{$fileName} and add your migration code");
    }
560033
public function _($name = null)
    {
        if (isset($name)) {
            $this->path[] = $name;
        }
        $client = new static($this->host, $this->headers);
        $client->setPath($this->path);
        $client->setCurlOptions($this->curlOptions);
        $client->setRetryOnLimit($this->retryOnLimit);
        $this->path = [];

        return $client;
    }
601005
public function createCommand($name)
    {
        $startTimestamp = time();

        #######################
        #     Build Paths     #
        #######################

        $basePath = $this->getStashEntryPath($name);

        $databaseDestination = $basePath . '/database.sql';
        $persistentDestination = $basePath . '/persistent/';

        FileUtils::createDirectoryRecursively($basePath);

        #######################
        # Check Configuration #
        #######################

        $this->checkConfiguration();

        ##################
        # Define Secrets #
        ##################

        $this->addSecret($this->databaseConfiguration['user']);
        $this->addSecret($this->databaseConfiguration['password']);

        ######################
        #  Write Manifest    #
        ######################
        $this->renderHeadLine('Write Manifest');
        $presetName = $this->configurationService->getCurrentPreset();
        $presetConfiguration = $this->configurationService->getCurrentConfiguration();
        $cloneTimestamp = $this->configurationService->getMostRecentCloneTimeStamp();
        $stashTimestamp = time();

        $this->writeStashEntryManifest($name, [
            'preset' => [
                'name' => $presetName,
                'configuration' => $presetConfiguration
            ],
            'cloned_at' => $cloneTimestamp,
            'stashed_at' => $stashTimestamp
        ]);

        ######################
        #  Backup Database   #
        ######################

        $this->renderHeadLine('Backup Database');
        $this->executeLocalShellCommand(
            'mysqldump --single-transaction --add-drop-table --host="%s" --user="%s" --password="%s" %s > %s',
            [
                $this->databaseConfiguration['host'],
                $this->databaseConfiguration['user'],
                $this->databaseConfiguration['password'],
                $this->databaseConfiguration['dbname'],
                $databaseDestination
            ]
        );

        ###############################
        # Backup Persistent Resources #
        ###############################

        $this->renderHeadLine('Backup Persistent Resources');
        $this->executeLocalShellCommand(
            'cp -al %s %s',
            [
                FLOW_PATH_ROOT . 'Data/Persistent',
                $persistentDestination
            ]
        );

        #################
        # Final Message #
        #################

        $endTimestamp = time();
        $duration = $endTimestamp - $startTimestamp;

        $this->renderHeadLine('Done');
        $this->renderLine('Successfuly stashed %s in %s seconds', [$name, $duration]);
    }
662660
public function createDirectory($name)
    {
        // We're not allowing dots
        if ('.' == $name || '..' == $name) {
            throw new DAV\Exception\Forbidden('Permission denied to . and ..');
        }
        $newPath = $this->path.'/'.$name;
        mkdir($newPath);
        clearstatcache(true, $newPath);
    }
1157014
public function createMigration($name, $templateName, array $replace = [], $subDir = '')
    {
        $targetDir = $this->dir;
        $subDir = trim(str_replace('\\', '/', $subDir), '/');
        if ($subDir) {
            $targetDir .= '/' . $subDir;
        }

        $this->files->createDirIfItDoesNotExist($targetDir);

        $fileName = $this->constructFileName($name);
        $className = $this->getMigrationClassNameByFileName($fileName);
        $templateName = $this->templates->selectTemplate($templateName);

        $template = $this->files->getContent($this->templates->getTemplatePath($templateName));
        $template = $this->replacePlaceholdersInTemplate($template, array_merge($replace, ['className' => $className]));

        $this->files->putContent($targetDir.'/'.$fileName.'.php', $template);

        return $fileName;
    }
758227
protected function getDestenationFile($name, $path)
    {
        if (!empty($path)) {
            $path = Helpers::getPathWithSlash(ucfirst($path));
        }

        return app_path(Config::getModelsPath($path . $name . '.php'));
    }
634405
public function actionCreate( $name )
	{
		list( $namespace, $className ) = $this->generateClassName( $name );
		
		if( empty( $namespace ) ) {
			
			$path = !is_array( $this->migrationPath )
				? $this->migrationPath
				: ( $this->defaultMigrationPath ?? reset( $this->migrationPath ) );
			
			$this->migrationPath = Yii::getAlias( $path );
		}
		
		parent::actionCreate( $name ); // TODO: Change the autogenerated stub
	}
40591
protected function migrateConnectionUp($name)
    {
        $manager = $this->createManager($name);
        $lastApplied = $manager->getLast();
        echo "\n\nmigrate up $name from $lastApplied";
        $folder = \Devil::getPathOf('@app/migrations/' . $name);
        if (is_dir($folder)) {
            $d = opendir($folder);
            while ($e = readdir($d)) {
                if ('.' == $e || '..' == $e) continue;
                if (is_file($folder . '/' . $e)) {
                    $time = intval(substr($e, 2));
                    if ($time > $lastApplied) {
                        $className = '\\app\\migrations\\' . $name . '\\m_' . $time;
                        $this->migrateUp(new $className);
                    }
                }
            }
        }
        echo "\n--status:done";
    }
231892
public function make(Connection $connection, $name = null)
    {
        if ($name && $this->config->has('migrations.' . $name)) {
            $config = new Repository($this->config->get('migrations.' . $name, []));
        } else {
            $config = new Repository($this->config->get('migrations.default', []));
        }

        $configuration = new Configuration($connection);
        $configuration->setName($config->get('name', 'Doctrine Migrations'));
        $configuration->setMigrationsNamespace($config->get('namespace', 'Database\\Migrations'));
        $configuration->setMigrationsTableName($config->get('table', 'migrations'));

        $configuration->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression(
            $config->get('schema.filter', '/^(?).*$/')
        );

        $configuration->setNamingStrategy($this->container->make(
            $config->get('naming_strategy', DefaultNamingStrategy::class)
        ));

        $configuration->setMigrationsFinder($configuration->getNamingStrategy()->getFinder());

        $directory = $config->get('directory', database_path('migrations'));
        $configuration->setMigrationsDirectory($directory);
        $configuration->registerMigrationsFromDirectory($directory);

        return $configuration;
    }
563169
public function make( $name )
	{
		$this->name = ucfirst( camel_case( $name ) );
		$this->createContract();
		$this->createBlueprint();
		$this->createModel();
		$this->addToEnsphereRegistration();
		$this->reRegister();
	}