1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* BEdita, API-first content management framework |
4
|
|
|
* Copyright 2020 ChannelWeb Srl, Chialab Srl |
5
|
|
|
* |
6
|
|
|
* This file is part of BEdita: you can redistribute it and/or modify |
7
|
|
|
* it under the terms of the GNU Lesser General Public License as published |
8
|
|
|
* by the Free Software Foundation, either version 3 of the License, or |
9
|
|
|
* (at your option) any later version. |
10
|
|
|
* |
11
|
|
|
* See LICENSE.LGPL or <http://gnu.org/licenses/lgpl-3.0.html> for more details. |
12
|
|
|
*/ |
13
|
|
|
namespace BEdita\DevTools\Shell\Task; |
14
|
|
|
|
15
|
|
|
use Cake\Utility\Inflector; |
16
|
|
|
use Migrations\Shell\Task\SimpleMigrationTask; |
17
|
|
|
use Phinx\Util\Util; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Task class for generating resources migrations files. |
21
|
|
|
* |
22
|
|
|
* {@inheritDoc} |
23
|
|
|
*/ |
24
|
|
|
class ResourcesMigrationTask extends SimpleMigrationTask |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* Main migration file name. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $migrationFile = ''; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritDoc} |
35
|
|
|
*/ |
36
|
|
|
public function name() |
37
|
|
|
{ |
38
|
|
|
return 'resources_migration'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritDoc} |
43
|
|
|
*/ |
44
|
|
|
public function fileName($name) |
45
|
|
|
{ |
46
|
|
|
$name = $this->getMigrationName($name); |
47
|
|
|
$this->migrationFile = Util::getCurrentTimestamp() . '_' . Inflector::camelize($name) . '.php'; |
48
|
|
|
|
49
|
|
|
return $this->migrationFile; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritDoc} |
54
|
|
|
*/ |
55
|
|
|
public function template() |
56
|
|
|
{ |
57
|
|
|
return 'BEdita/DevTools.resources'; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* {@inheritDoc} |
62
|
|
|
*/ |
63
|
|
|
public function bake($name) |
64
|
|
|
{ |
65
|
|
|
// create .php file first, then .yml |
66
|
|
|
parent::bake($name); |
67
|
|
|
|
68
|
|
|
$contents = $this->BakeTemplate->generate('BEdita/DevTools.yaml'); |
69
|
|
|
|
70
|
|
|
$filename = $this->getPath() . str_replace('.php', '.yml', $this->migrationFile); |
71
|
|
|
$this->createFile($filename, $contents); |
72
|
|
|
|
73
|
|
|
return $contents; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|