Completed
Push — master ( 00b3a6...bce893 )
by Mark
02:24
created
src/Commands/MigrateDisorganise.php 1 patch
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -9,118 +9,118 @@
 block discarded – undo
9 9
 
10 10
 class MigrateDisorganise extends BaseCommand
11 11
 {
12
-    /**
13
-     * The console command name.
14
-     *
15
-     * @var string
16
-     */
17
-    protected $name = 'migrate:disorganise';
18
-
19
-    /**
20
-     * The console command description.
21
-     *
22
-     * @var string
23
-     */
24
-    protected $description = 'Move migrations from a yyyy/mm folder structure back to the base migrations folder';
25
-
26
-    /**
27
-     * The migrator instance.
28
-     *
29
-     * @var \Jaybizzle\MigrationsOrganiser\Migrator
30
-     */
31
-    protected $migrator;
32
-
33
-    /**
34
-     * The filesystem instance.
35
-     *
36
-     * @var \Illuminate\Filesystem\Filesystem
37
-     */
38
-    protected $files;
39
-
40
-    /**
41
-     * The basePath for the migrations.
42
-     */
43
-    protected $basePath;
44
-
45
-    /**
46
-     * Create a new migrator instance.
47
-     *
48
-     * @param \Illuminate\Filesystem\Filesystem        $files
49
-     * @param \Illuminate\Database\Migrations\Migrator $migrator
50
-     */
51
-    public function __construct(Filesystem $files, Migrator $migrator)
52
-    {
53
-        parent::__construct();
54
-        $this->migrator = $migrator;
55
-        $this->files = $files;
56
-    }
57
-
58
-    /**
59
-     * Create date folder structure and move migrations into.
60
-     *
61
-     * @return void
62
-     */
63
-    public function fire()
64
-    {
65
-        $this->basePath = $this->getMigrationPath();
66
-        $migrations = $this->migrator->getMigrationFiles($this->basePath);
67
-        $count = count($migrations);
68
-
69
-        if ($count == 0) {
70
-            $this->comment('No migrations to move');
71
-
72
-            return;
73
-        }
74
-
75
-        foreach ($migrations as $migration) {
76
-            $datePath = $this->migrator->getDateFolderStructure($migration);
77
-            // Move the migration into base migration folder
78
-            $this->files->move($this->basePath.'/'.$datePath.$migration.'.php', $this->basePath.'/'.$migration.'.php');
79
-        }
80
-
81
-        $this->info('Migrations disorganised successfully ('.$count.' migrations moved)');
82
-        $this->cleanup();
83
-    }
84
-
85
-    /**
86
-     * Decide whether or not to delete directories.
87
-     *
88
-     * @return void
89
-     */
90
-    public function cleanup()
91
-    {
92
-        if ($this->option('force')) {
93
-            $this->deleteDirs();
94
-        } elseif ($this->confirm('Delete all subdirectories in migrations folder? [yes|no]', false)) {
95
-            $this->deleteDirs();
96
-        }
97
-    }
98
-
99
-    /**
100
-     * Delete subdirectories in the migrations folder.
101
-     *
102
-     * @return void
103
-     */
104
-    public function deleteDirs()
105
-    {
106
-        $dirs = $this->files->directories($this->basePath);
107
-
108
-        foreach ($dirs as $dir) {
109
-            $this->files->deleteDirectory($dir);
110
-        }
111
-
112
-        $this->info('Subdirectories deleted');
113
-    }
114
-
115
-    /**
116
-     * Get the console command options.
117
-     *
118
-     * @return array
119
-     */
120
-    protected function getOptions()
121
-    {
122
-        return [
123
-            ['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'],
124
-        ];
125
-    }
12
+	/**
13
+	 * The console command name.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	protected $name = 'migrate:disorganise';
18
+
19
+	/**
20
+	 * The console command description.
21
+	 *
22
+	 * @var string
23
+	 */
24
+	protected $description = 'Move migrations from a yyyy/mm folder structure back to the base migrations folder';
25
+
26
+	/**
27
+	 * The migrator instance.
28
+	 *
29
+	 * @var \Jaybizzle\MigrationsOrganiser\Migrator
30
+	 */
31
+	protected $migrator;
32
+
33
+	/**
34
+	 * The filesystem instance.
35
+	 *
36
+	 * @var \Illuminate\Filesystem\Filesystem
37
+	 */
38
+	protected $files;
39
+
40
+	/**
41
+	 * The basePath for the migrations.
42
+	 */
43
+	protected $basePath;
44
+
45
+	/**
46
+	 * Create a new migrator instance.
47
+	 *
48
+	 * @param \Illuminate\Filesystem\Filesystem        $files
49
+	 * @param \Illuminate\Database\Migrations\Migrator $migrator
50
+	 */
51
+	public function __construct(Filesystem $files, Migrator $migrator)
52
+	{
53
+		parent::__construct();
54
+		$this->migrator = $migrator;
55
+		$this->files = $files;
56
+	}
57
+
58
+	/**
59
+	 * Create date folder structure and move migrations into.
60
+	 *
61
+	 * @return void
62
+	 */
63
+	public function fire()
64
+	{
65
+		$this->basePath = $this->getMigrationPath();
66
+		$migrations = $this->migrator->getMigrationFiles($this->basePath);
67
+		$count = count($migrations);
68
+
69
+		if ($count == 0) {
70
+			$this->comment('No migrations to move');
71
+
72
+			return;
73
+		}
74
+
75
+		foreach ($migrations as $migration) {
76
+			$datePath = $this->migrator->getDateFolderStructure($migration);
77
+			// Move the migration into base migration folder
78
+			$this->files->move($this->basePath.'/'.$datePath.$migration.'.php', $this->basePath.'/'.$migration.'.php');
79
+		}
80
+
81
+		$this->info('Migrations disorganised successfully ('.$count.' migrations moved)');
82
+		$this->cleanup();
83
+	}
84
+
85
+	/**
86
+	 * Decide whether or not to delete directories.
87
+	 *
88
+	 * @return void
89
+	 */
90
+	public function cleanup()
91
+	{
92
+		if ($this->option('force')) {
93
+			$this->deleteDirs();
94
+		} elseif ($this->confirm('Delete all subdirectories in migrations folder? [yes|no]', false)) {
95
+			$this->deleteDirs();
96
+		}
97
+	}
98
+
99
+	/**
100
+	 * Delete subdirectories in the migrations folder.
101
+	 *
102
+	 * @return void
103
+	 */
104
+	public function deleteDirs()
105
+	{
106
+		$dirs = $this->files->directories($this->basePath);
107
+
108
+		foreach ($dirs as $dir) {
109
+			$this->files->deleteDirectory($dir);
110
+		}
111
+
112
+		$this->info('Subdirectories deleted');
113
+	}
114
+
115
+	/**
116
+	 * Get the console command options.
117
+	 *
118
+	 * @return array
119
+	 */
120
+	protected function getOptions()
121
+	{
122
+		return [
123
+			['force', null, InputOption::VALUE_NONE, 'Force the operation to delete migration folder subdirectories without prompt.'],
124
+		];
125
+	}
126 126
 }
Please login to merge, or discard this patch.
src/MigrationsOrganiserServiceProvider.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -8,41 +8,41 @@
 block discarded – undo
8 8
 
9 9
 class MigrationsOrganiserServiceProvider extends MSP
10 10
 {
11
-    public function register()
12
-    {
13
-        parent::register();
14
-        $this->registerMigrateOrganise();
15
-        $this->registerMigrateDisorganise();
16
-        $this->commands('command.migrate.organise', 'command.migrate.disorganise');
17
-    }
18
-
19
-    protected function registerCreator()
20
-    {
21
-        $this->app->singleton('migration.creator', function ($app) {
22
-            return new MigrationCreator($app['files']);
23
-        });
24
-    }
25
-
26
-    protected function registerMigrator()
27
-    {
28
-        $this->app->singleton('migrator', function ($app) {
29
-            $repository = $app['migration.repository'];
30
-
31
-            return new Migrator($repository, $app['db'], $app['files']);
32
-        });
33
-    }
34
-
35
-    protected function registerMigrateOrganise()
36
-    {
37
-        $this->app->singleton('command.migrate.organise', function ($app) {
38
-            return new MigrateOrganise($app['files'], $app['migrator']);
39
-        });
40
-    }
41
-
42
-    protected function registerMigrateDisorganise()
43
-    {
44
-        $this->app->singleton('command.migrate.disorganise', function ($app) {
45
-            return new MigrateDisorganise($app['files'], $app['migrator']);
46
-        });
47
-    }
11
+	public function register()
12
+	{
13
+		parent::register();
14
+		$this->registerMigrateOrganise();
15
+		$this->registerMigrateDisorganise();
16
+		$this->commands('command.migrate.organise', 'command.migrate.disorganise');
17
+	}
18
+
19
+	protected function registerCreator()
20
+	{
21
+		$this->app->singleton('migration.creator', function ($app) {
22
+			return new MigrationCreator($app['files']);
23
+		});
24
+	}
25
+
26
+	protected function registerMigrator()
27
+	{
28
+		$this->app->singleton('migrator', function ($app) {
29
+			$repository = $app['migration.repository'];
30
+
31
+			return new Migrator($repository, $app['db'], $app['files']);
32
+		});
33
+	}
34
+
35
+	protected function registerMigrateOrganise()
36
+	{
37
+		$this->app->singleton('command.migrate.organise', function ($app) {
38
+			return new MigrateOrganise($app['files'], $app['migrator']);
39
+		});
40
+	}
41
+
42
+	protected function registerMigrateDisorganise()
43
+	{
44
+		$this->app->singleton('command.migrate.disorganise', function ($app) {
45
+			return new MigrateDisorganise($app['files'], $app['migrator']);
46
+		});
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,14 +18,14 @@  discard block
 block discarded – undo
18 18
 
19 19
     protected function registerCreator()
20 20
     {
21
-        $this->app->singleton('migration.creator', function ($app) {
21
+        $this->app->singleton('migration.creator', function($app) {
22 22
             return new MigrationCreator($app['files']);
23 23
         });
24 24
     }
25 25
 
26 26
     protected function registerMigrator()
27 27
     {
28
-        $this->app->singleton('migrator', function ($app) {
28
+        $this->app->singleton('migrator', function($app) {
29 29
             $repository = $app['migration.repository'];
30 30
 
31 31
             return new Migrator($repository, $app['db'], $app['files']);
@@ -34,14 +34,14 @@  discard block
 block discarded – undo
34 34
 
35 35
     protected function registerMigrateOrganise()
36 36
     {
37
-        $this->app->singleton('command.migrate.organise', function ($app) {
37
+        $this->app->singleton('command.migrate.organise', function($app) {
38 38
             return new MigrateOrganise($app['files'], $app['migrator']);
39 39
         });
40 40
     }
41 41
 
42 42
     protected function registerMigrateDisorganise()
43 43
     {
44
-        $this->app->singleton('command.migrate.disorganise', function ($app) {
44
+        $this->app->singleton('command.migrate.disorganise', function($app) {
45 45
             return new MigrateDisorganise($app['files'], $app['migrator']);
46 46
         });
47 47
     }
Please login to merge, or discard this patch.
src/MigrationCreator.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -6,14 +6,14 @@
 block discarded – undo
6 6
 
7 7
 class MigrationCreator extends MC
8 8
 {
9
-    protected function getPath($name, $path)
10
-    {
11
-        $path = $path.'/'.date('Y').'/'.date('m');
9
+	protected function getPath($name, $path)
10
+	{
11
+		$path = $path.'/'.date('Y').'/'.date('m');
12 12
 
13
-        if (! $this->files->exists($path)) {
14
-            $this->files->makeDirectory($path, 0775, true);
15
-        }
13
+		if (! $this->files->exists($path)) {
14
+			$this->files->makeDirectory($path, 0775, true);
15
+		}
16 16
 
17
-        return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
18
-    }
17
+		return $path.'/'.$this->getDatePrefix().'_'.$name.'.php';
18
+	}
19 19
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@
 block discarded – undo
10 10
     {
11 11
         $path = $path.'/'.date('Y').'/'.date('m');
12 12
 
13
-        if (! $this->files->exists($path)) {
13
+        if ( ! $this->files->exists($path)) {
14 14
             $this->files->makeDirectory($path, 0775, true);
15 15
         }
16 16
 
Please login to merge, or discard this patch.
src/Commands/MigrateOrganise.php 2 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -8,76 +8,76 @@
 block discarded – undo
8 8
 
9 9
 class MigrateOrganise extends BaseCommand
10 10
 {
11
-    /**
12
-     * The console command name.
13
-     *
14
-     * @var string
15
-     */
16
-    protected $name = 'migrate:organise';
11
+	/**
12
+	 * The console command name.
13
+	 *
14
+	 * @var string
15
+	 */
16
+	protected $name = 'migrate:organise';
17 17
 
18
-    /**
19
-     * The console command description.
20
-     *
21
-     * @var string
22
-     */
23
-    protected $description = 'Move migrations into a yyyy/mm folder structure';
18
+	/**
19
+	 * The console command description.
20
+	 *
21
+	 * @var string
22
+	 */
23
+	protected $description = 'Move migrations into a yyyy/mm folder structure';
24 24
 
25
-    /**
26
-     * The migrator instance.
27
-     *
28
-     * @var \Jaybizzle\MigrationsOrganiser\Migrator
29
-     */
30
-    protected $migrator;
25
+	/**
26
+	 * The migrator instance.
27
+	 *
28
+	 * @var \Jaybizzle\MigrationsOrganiser\Migrator
29
+	 */
30
+	protected $migrator;
31 31
 
32
-    /**
33
-     * The filesystem instance.
34
-     *
35
-     * @var \Illuminate\Filesystem\Filesystem
36
-     */
37
-    protected $files;
32
+	/**
33
+	 * The filesystem instance.
34
+	 *
35
+	 * @var \Illuminate\Filesystem\Filesystem
36
+	 */
37
+	protected $files;
38 38
 
39
-    /**
40
-     * Create a new migrator instance.
41
-     *
42
-     * @param \Illuminate\Filesystem\Filesystem        $files
43
-     * @param \Illuminate\Database\Migrations\Migrator $migrator
44
-     */
45
-    public function __construct(Filesystem $files, Migrator $migrator)
46
-    {
47
-        parent::__construct();
48
-        $this->migrator = $migrator;
49
-        $this->files = $files;
50
-    }
39
+	/**
40
+	 * Create a new migrator instance.
41
+	 *
42
+	 * @param \Illuminate\Filesystem\Filesystem        $files
43
+	 * @param \Illuminate\Database\Migrations\Migrator $migrator
44
+	 */
45
+	public function __construct(Filesystem $files, Migrator $migrator)
46
+	{
47
+		parent::__construct();
48
+		$this->migrator = $migrator;
49
+		$this->files = $files;
50
+	}
51 51
 
52
-    /**
53
-     * Create date folder structure and move migrations into.
54
-     *
55
-     * @return void
56
-     */
57
-    public function fire()
58
-    {
59
-        $basePath = $this->getMigrationPath();
60
-        $migrations = $this->migrator->getMigrationFiles($basePath, false);
61
-        $count = count($migrations);
52
+	/**
53
+	 * Create date folder structure and move migrations into.
54
+	 *
55
+	 * @return void
56
+	 */
57
+	public function fire()
58
+	{
59
+		$basePath = $this->getMigrationPath();
60
+		$migrations = $this->migrator->getMigrationFiles($basePath, false);
61
+		$count = count($migrations);
62 62
 
63
-        if ($count == 0) {
64
-            $this->comment('No migrations to move');
63
+		if ($count == 0) {
64
+			$this->comment('No migrations to move');
65 65
 
66
-            return;
67
-        }
66
+			return;
67
+		}
68 68
 
69
-        foreach ($migrations as $migration) {
70
-            $datePath = $this->migrator->getDateFolderStructure($migration);
69
+		foreach ($migrations as $migration) {
70
+			$datePath = $this->migrator->getDateFolderStructure($migration);
71 71
 
72
-            // Create folder if it does not already exist
73
-            if (! $this->files->exists($basePath.'/'.$datePath)) {
74
-                $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true);
75
-            }
72
+			// Create folder if it does not already exist
73
+			if (! $this->files->exists($basePath.'/'.$datePath)) {
74
+				$this->files->makeDirectory($basePath.'/'.$datePath, 0775, true);
75
+			}
76 76
 
77
-            // Move the migration into its new folder
78
-            $this->files->move($basePath.'/'.$migration.'.php', $basePath.'/'.$datePath.$migration.'.php');
79
-        }
77
+			// Move the migration into its new folder
78
+			$this->files->move($basePath.'/'.$migration.'.php', $basePath.'/'.$datePath.$migration.'.php');
79
+		}
80 80
 
81
-        $this->info('Migrations organised successfully ('.$count.' migrations moved)');
82
-    }
81
+		$this->info('Migrations organised successfully ('.$count.' migrations moved)');
82
+	}
83 83
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@
 block discarded – undo
70 70
             $datePath = $this->migrator->getDateFolderStructure($migration);
71 71
 
72 72
             // Create folder if it does not already exist
73
-            if (! $this->files->exists($basePath.'/'.$datePath)) {
73
+            if ( ! $this->files->exists($basePath.'/'.$datePath)) {
74 74
                 $this->files->makeDirectory($basePath.'/'.$datePath, 0775, true);
75 75
             }
76 76
 
Please login to merge, or discard this patch.
src/Migrator.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -6,167 +6,167 @@
 block discarded – undo
6 6
 
7 7
 class Migrator extends M
8 8
 {
9
-    /**
10
-     * Fully qualified path to the application's migration directory
11
-     *
12
-     * @var string
13
-     */
14
-    private $path;
9
+	/**
10
+	 * Fully qualified path to the application's migration directory
11
+	 *
12
+	 * @var string
13
+	 */
14
+	private $path;
15 15
     
16
-    /**
17
-     * Get all of the migration files in a given path.
18
-     *
19
-     * @param string $path
20
-     * @param bool   $recursive
21
-     *
22
-     * @return array
23
-     */
24
-    public function getMigrationFiles($path, $recursive = true)
25
-    {
26
-        $this->setPath($path);
16
+	/**
17
+	 * Get all of the migration files in a given path.
18
+	 *
19
+	 * @param string $path
20
+	 * @param bool   $recursive
21
+	 *
22
+	 * @return array
23
+	 */
24
+	public function getMigrationFiles($path, $recursive = true)
25
+	{
26
+		$this->setPath($path);
27 27
         
28
-        if ($recursive === true) {
29
-            $files = $this->rglob($this->path.'/*_*.php', 0, true);
30
-        } else {
31
-            $files = $this->files->glob($this->path.'/*_*.php');
32
-        }
33
-
34
-        // Once we have the array of files in the directory we will just remove the
35
-        // extension and take the basename of the file which is all we need when
36
-        // finding the migrations that haven't been run against the databases.
37
-        if ($files === false) {
38
-            return [];
39
-        }
40
-
41
-        $files = array_map(function ($file) {
42
-            return str_replace('.php', '', basename($file));
43
-
44
-        }, $files);
45
-
46
-        // Once we have all of the formatted file names we will sort them and since
47
-        // they all start with a timestamp this should give us the migrations in
48
-        // the order they were actually created by the application developers.
49
-        sort($files);
50
-
51
-        return $files;
52
-    }
53
-
54
-    /**
55
-     * Require in all the migration files in a given path.
56
-     *
57
-     * @param array  $files
58
-     *
59
-     * @return void
60
-     */
61
-    public function requireFiles(array $files)
62
-    {
63
-        foreach ($files as $file) {
64
-            $newPath = $this->getFilePathWithFolders($file).'.php';
65
-            $this->files->requireOnce($newPath);
66
-        }
67
-    }
68
-
69
-    /**
70
-     * Run "up" a migration instance.
71
-     *
72
-     * @param string $file
73
-     * @param int    $batch
74
-     * @param bool   $pretend
75
-     *
76
-     * @return void
77
-     */
78
-    protected function runUp($file, $batch, $pretend)
79
-    {
80
-        // First we will resolve a "real" instance of the migration class from this
81
-        // migration file name. Once we have the instances we can run the actual
82
-        // command such as "up" or "down", or we can just simulate the action.
83
-        $migration = $this->resolve($file);
84
-
85
-        if ($pretend) {
86
-            return $this->pretendToRun($migration, 'up');
87
-        }
88
-
89
-        $migration->up();
90
-
91
-        // Once we have run a migrations class, we will log that it was run in this
92
-        // repository so that we don't try to run it next time we do a migration
93
-        // in the application. A migration repository keeps the migrate order.
94
-        $this->repository->log($this->getFilePathWithoutFolders($file), $batch);
95
-
96
-        $this->note("<info>Migrated:</info> $file");
97
-    }
98
-
99
-    /**
100
-     * Recursive glob.
101
-     *
102
-     * @param string $pattern
103
-     * @param int    $flags
104
-     * @param bool   $ignore
105
-     *
106
-     * @return array
107
-     */
108
-    public function rglob($pattern, $flags = 0, $ignore = false)
109
-    {
110
-        if ($ignore === false) {
111
-            $files = glob($pattern, $flags);
112
-        } else {
113
-            $files = [];
114
-        }
115
-
116
-        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
117
-            $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags));
118
-        }
119
-
120
-        return $files;
121
-    }
122
-
123
-    /**
124
-     * Get the migration file path with our injected date folder.
125
-     *
126
-     * @param string $file
127
-     *
128
-     * @return string
129
-     */
130
-    public function getFilePathWithFolders($file)
131
-    {
132
-        $datePath = $this->getDateFolderStructure($file);
133
-
134
-        return $this->path . '/' . $datePath . $file;
135
-    }
136
-
137
-    /**
138
-     * Remove folders from file path.
139
-     *
140
-     * @param string $file
141
-     *
142
-     * @return string
143
-     */
144
-    public function getFilePathWithoutFolders($file)
145
-    {
146
-        return basename($file);
147
-    }
148
-
149
-    /**
150
-     * Add date folders to migrations path.
151
-     *
152
-     * @param string $file
153
-     *
154
-     * @return string
155
-     */
156
-    public function getDateFolderStructure($file)
157
-    {
158
-        $parts = explode('_', $file);
159
-
160
-        return $parts[0].'/'.$parts[1].'/';
161
-    }
28
+		if ($recursive === true) {
29
+			$files = $this->rglob($this->path.'/*_*.php', 0, true);
30
+		} else {
31
+			$files = $this->files->glob($this->path.'/*_*.php');
32
+		}
33
+
34
+		// Once we have the array of files in the directory we will just remove the
35
+		// extension and take the basename of the file which is all we need when
36
+		// finding the migrations that haven't been run against the databases.
37
+		if ($files === false) {
38
+			return [];
39
+		}
40
+
41
+		$files = array_map(function ($file) {
42
+			return str_replace('.php', '', basename($file));
43
+
44
+		}, $files);
45
+
46
+		// Once we have all of the formatted file names we will sort them and since
47
+		// they all start with a timestamp this should give us the migrations in
48
+		// the order they were actually created by the application developers.
49
+		sort($files);
50
+
51
+		return $files;
52
+	}
53
+
54
+	/**
55
+	 * Require in all the migration files in a given path.
56
+	 *
57
+	 * @param array  $files
58
+	 *
59
+	 * @return void
60
+	 */
61
+	public function requireFiles(array $files)
62
+	{
63
+		foreach ($files as $file) {
64
+			$newPath = $this->getFilePathWithFolders($file).'.php';
65
+			$this->files->requireOnce($newPath);
66
+		}
67
+	}
68
+
69
+	/**
70
+	 * Run "up" a migration instance.
71
+	 *
72
+	 * @param string $file
73
+	 * @param int    $batch
74
+	 * @param bool   $pretend
75
+	 *
76
+	 * @return void
77
+	 */
78
+	protected function runUp($file, $batch, $pretend)
79
+	{
80
+		// First we will resolve a "real" instance of the migration class from this
81
+		// migration file name. Once we have the instances we can run the actual
82
+		// command such as "up" or "down", or we can just simulate the action.
83
+		$migration = $this->resolve($file);
84
+
85
+		if ($pretend) {
86
+			return $this->pretendToRun($migration, 'up');
87
+		}
88
+
89
+		$migration->up();
90
+
91
+		// Once we have run a migrations class, we will log that it was run in this
92
+		// repository so that we don't try to run it next time we do a migration
93
+		// in the application. A migration repository keeps the migrate order.
94
+		$this->repository->log($this->getFilePathWithoutFolders($file), $batch);
95
+
96
+		$this->note("<info>Migrated:</info> $file");
97
+	}
98
+
99
+	/**
100
+	 * Recursive glob.
101
+	 *
102
+	 * @param string $pattern
103
+	 * @param int    $flags
104
+	 * @param bool   $ignore
105
+	 *
106
+	 * @return array
107
+	 */
108
+	public function rglob($pattern, $flags = 0, $ignore = false)
109
+	{
110
+		if ($ignore === false) {
111
+			$files = glob($pattern, $flags);
112
+		} else {
113
+			$files = [];
114
+		}
115
+
116
+		foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
117
+			$files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags));
118
+		}
119
+
120
+		return $files;
121
+	}
122
+
123
+	/**
124
+	 * Get the migration file path with our injected date folder.
125
+	 *
126
+	 * @param string $file
127
+	 *
128
+	 * @return string
129
+	 */
130
+	public function getFilePathWithFolders($file)
131
+	{
132
+		$datePath = $this->getDateFolderStructure($file);
133
+
134
+		return $this->path . '/' . $datePath . $file;
135
+	}
136
+
137
+	/**
138
+	 * Remove folders from file path.
139
+	 *
140
+	 * @param string $file
141
+	 *
142
+	 * @return string
143
+	 */
144
+	public function getFilePathWithoutFolders($file)
145
+	{
146
+		return basename($file);
147
+	}
148
+
149
+	/**
150
+	 * Add date folders to migrations path.
151
+	 *
152
+	 * @param string $file
153
+	 *
154
+	 * @return string
155
+	 */
156
+	public function getDateFolderStructure($file)
157
+	{
158
+		$parts = explode('_', $file);
159
+
160
+		return $parts[0].'/'.$parts[1].'/';
161
+	}
162 162
     
163
-    /**
164
-     * Set the path
165
-     *
166
-     * @param array|string $path
167
-     */
168
-    private function setPath($path)
169
-    {
170
-        $this->path = is_array($path) ? $path[0] : $path;
171
-    }
163
+	/**
164
+	 * Set the path
165
+	 *
166
+	 * @param array|string $path
167
+	 */
168
+	private function setPath($path)
169
+	{
170
+		$this->path = is_array($path) ? $path[0] : $path;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
             return [];
39 39
         }
40 40
 
41
-        $files = array_map(function ($file) {
41
+        $files = array_map(function($file) {
42 42
             return str_replace('.php', '', basename($file));
43 43
 
44 44
         }, $files);
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
     {
132 132
         $datePath = $this->getDateFolderStructure($file);
133 133
 
134
-        return $this->path . '/' . $datePath . $file;
134
+        return $this->path.'/'.$datePath.$file;
135 135
     }
136 136
 
137 137
     /**
Please login to merge, or discard this patch.