1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel Service Provider. |
5
|
|
|
* |
6
|
|
|
* (c) DraperStudio <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DraperStudio\ServiceProvider\Publisher; |
13
|
|
|
|
14
|
|
|
use InvalidArgumentException; |
15
|
|
|
|
16
|
|
|
class MigrationPublisher extends Publisher |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Get the source assets directory to publish. |
20
|
|
|
* |
21
|
|
|
* @param string $packagePath |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
* |
25
|
|
|
* @throws \InvalidArgumentException |
26
|
|
|
*/ |
27
|
|
|
protected function getSource($packagePath) |
28
|
|
|
{ |
29
|
|
|
$sources = [ |
30
|
|
|
"{$packagePath}/resources/database/migrations", |
31
|
|
|
"{$packagePath}/resources/migrations", |
32
|
|
|
"{$packagePath}/migrations", |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
// iterate through all possible locations |
36
|
|
|
foreach ($sources as $source) { |
37
|
|
|
if ($this->files->isDirectory($source)) { |
38
|
|
|
$paths = []; |
39
|
|
|
|
40
|
|
|
// get all files of the current directory |
41
|
|
|
$files = $this->getSourceFiles($source); |
42
|
|
|
|
43
|
|
|
// iterate through all files |
44
|
|
|
foreach ($files as $file) { |
45
|
|
|
// if the destination doesn't exist we can add the file to the queue |
46
|
|
|
if (!class_exists($this->getClassFromFile($file))) { |
47
|
|
|
$paths[$file] = $this->getDestinationPath('migrations', [ |
48
|
|
|
date('Y_m_d_His', time()), $this->getFileName($file), |
49
|
|
|
]); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $paths; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
throw new InvalidArgumentException('Migrations not found.'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|