summaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2017-06-02 13:54:09 +0200
committerMorris Jobke <hey@morrisjobke.de>2017-07-05 13:01:19 +0200
commit194ef1a1715038c2193cee65a74372f07bc4eee6 (patch)
tree3e9f6120c64f85614cf926c2a7bd6286aaef3b88 /core/Command
parent183b1dbde3b5586e3bae0073f6f9c40414e7c6a6 (diff)
downloadnextcloud-server-194ef1a1715038c2193cee65a74372f07bc4eee6.tar.gz
nextcloud-server-194ef1a1715038c2193cee65a74372f07bc4eee6.zip
Adjust the code to use our interface and abstract
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/Db/Migrations/GenerateCommand.php90
1 files changed, 27 insertions, 63 deletions
diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php
index 307989c845a..894c0f4f3ed 100644
--- a/core/Command/Db/Migrations/GenerateCommand.php
+++ b/core/Command/Db/Migrations/GenerateCommand.php
@@ -24,7 +24,6 @@ namespace OC\Core\Command\Db\Migrations;
use OC\DB\MigrationService;
use OC\Migration\ConsoleOutput;
-use OCP\IConfig;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
@@ -38,56 +37,37 @@ class GenerateCommand extends Command {
'<?php
namespace <namespace>;
-use OCP\Migration\ISimpleMigration;
+use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;
/**
* Auto-generated migration step: Please modify to your needs!
*/
-class Version<version> implements ISimpleMigration {
-
- /**
- * @param IOutput $out
- */
- public function run(IOutput $out) {
- // auto-generated - please modify it to your needs
- }
-}
-';
-
- private static $_templateSchema =
- '<?php
-namespace <namespace>;
-
-use Doctrine\DBAL\Schema\Schema;
-use OCP\Migration\ISchemaMigration;
-
-/**
- * Auto-generated migration step: Please modify to your needs!
- */
-class Version<version> implements ISchemaMigration {
+class Version<version> extends SimpleMigrationStep {
- public function changeSchema(Schema $schema, array $options) {
- // auto-generated - please modify it to your needs
- }
-}
-';
-
- private static $_templateSql =
- '<?php
-namespace <namespace>;
-
-use OCP\IDBConnection;
-use OCP\Migration\ISqlMigration;
+ /**
+ * @param IOutput $output
+ * @since 13.0.0
+ */
+ public function preSchemaChange(IOutput $output) {
+ }
-/**
- * Auto-generated migration step: Please modify to your needs!
- */
-class Version<version> implements ISqlMigration {
+ /**
+ * @param \Closure $schema The `\Closure` returns a `Schema`
+ * @param array $options
+ * @return null|Schema
+ * @since 13.0.0
+ */
+ public function changeSchema(\Closure $schema, array $options) {
+ return null;
+ }
- public function sql(IDBConnection $connection) {
- // auto-generated - please modify it to your needs
- }
+ /**
+ * @param IOutput $output
+ * @since 13.0.0
+ */
+ public function postSchemaChange(IOutput $output) {
+ }
}
';
@@ -107,7 +87,7 @@ class Version<version> implements ISqlMigration {
$this
->setName('migrations:generate')
->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on')
- ->addArgument('kind', InputArgument::REQUIRED, 'simple, schema or sql - defines the kind of migration to be generated');
+ ;
parent::configure();
}
@@ -115,10 +95,8 @@ class Version<version> implements ISqlMigration {
public function execute(InputInterface $input, OutputInterface $output) {
$appName = $input->getArgument('app');
$ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output));
-
- $kind = $input->getArgument('kind');
$version = date('YmdHis');
- $path = $this->generateMigration($ms, $version, $kind);
+ $path = $this->generateMigration($ms, $version);
$output->writeln("New migration class has been generated to <info>$path</info>");
@@ -127,10 +105,9 @@ class Version<version> implements ISqlMigration {
/**
* @param MigrationService $ms
* @param string $version
- * @param string $kind
* @return string
*/
- private function generateMigration(MigrationService $ms, $version, $kind) {
+ private function generateMigration(MigrationService $ms, $version) {
$placeHolders = [
'<namespace>',
'<version>',
@@ -139,7 +116,7 @@ class Version<version> implements ISqlMigration {
$ms->getMigrationsNamespace(),
$version,
];
- $code = str_replace($placeHolders, $replacements, $this->getTemplate($kind));
+ $code = str_replace($placeHolders, $replacements, self::$_templateSimple);
$dir = $ms->getMigrationsDirectory();
$path = $dir . '/Version' . $version . '.php';
@@ -150,17 +127,4 @@ class Version<version> implements ISqlMigration {
return $path;
}
- private function getTemplate($kind) {
- if ($kind === 'simple') {
- return self::$_templateSimple;
- }
- if ($kind === 'schema') {
- return self::$_templateSchema;
- }
- if ($kind === 'sql') {
- return self::$_templateSql;
- }
- throw new \InvalidArgumentException('Kind can only be one of the following: simple, schema or sql');
- }
-
}