|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* CakeCMS Core |
|
4
|
|
|
* |
|
5
|
|
|
* This file is part of the of the simple cms based on CakePHP 3. |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @package Core |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @copyright MIT License http://www.opensource.org/licenses/mit-license.php |
|
12
|
|
|
* @link https://github.com/CakeCMS/Core". |
|
13
|
|
|
* @author Sergey Kalistratov <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Core\Migration; |
|
17
|
|
|
|
|
18
|
|
|
use Core\Plugin; |
|
19
|
|
|
use JBZoo\Utils\FS; |
|
20
|
|
|
use Cake\Filesystem\Folder; |
|
21
|
|
|
use Cake\Utility\Inflector; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class Migration |
|
25
|
|
|
* |
|
26
|
|
|
* @package Core |
|
27
|
|
|
*/ |
|
28
|
|
|
class Migration |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
const MIGRATION_DIR = 'Migrations'; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Get plugin migration path. |
|
35
|
|
|
* |
|
36
|
|
|
* @param string $plugin |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function getPath($plugin) |
|
40
|
|
|
{ |
|
41
|
|
|
return FS::clean(Plugin::path($plugin) . '/config/' . self::MIGRATION_DIR, '/'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get data for migration. |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $plugin |
|
48
|
|
|
* @return array |
|
49
|
|
|
*/ |
|
50
|
|
|
public static function getData($plugin) |
|
51
|
|
|
{ |
|
52
|
|
|
$data = []; |
|
53
|
|
|
$path = self::getPath($plugin); |
|
54
|
|
|
$dir = new Folder($path); |
|
55
|
|
|
$files = (array) $dir->find('.*\.php'); |
|
56
|
|
|
|
|
57
|
|
|
if (count($files) > 0) { |
|
58
|
|
|
foreach ($files as $file) { |
|
59
|
|
|
$name = FS::filename($file); |
|
60
|
|
|
$segments = explode('_', $name); |
|
61
|
|
|
$version = array_shift($segments); |
|
62
|
|
|
$class = Inflector::camelize(implode('_', $segments)); |
|
63
|
|
|
|
|
64
|
|
|
$data[$version] = [ |
|
65
|
|
|
'class' => $class, |
|
66
|
|
|
'path' => $path . DS . $file, |
|
67
|
|
|
]; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $data; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $plugin |
|
78
|
|
|
* @return Manager |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function getManager($plugin) |
|
81
|
|
|
{ |
|
82
|
|
|
return new Manager($plugin); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|