1 | <?php |
||
13 | class Manager |
||
14 | { |
||
15 | /** |
||
16 | * @var \Rougin\SparkPlug\SparkPlug |
||
17 | */ |
||
18 | protected $ci; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $path; |
||
24 | |||
25 | /** |
||
26 | * Initializes the migration instance. |
||
27 | * |
||
28 | * @param string $path |
||
29 | */ |
||
30 | 45 | public function __construct($path) |
|
42 | |||
43 | /** |
||
44 | * Creates a new file to the "migrations" directory. |
||
45 | * |
||
46 | * @param string $filename |
||
47 | * @param string $content |
||
48 | * @return void |
||
49 | */ |
||
50 | 24 | public function create($filename, $content) |
|
58 | |||
59 | /** |
||
60 | * Returns the current migration version. |
||
61 | * |
||
62 | * @return string |
||
63 | */ |
||
64 | 21 | public function current() |
|
65 | { |
||
66 | 21 | return $this->get('migration_version'); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns a generated migration filename. |
||
71 | * |
||
72 | * @param string $name |
||
73 | * @return string |
||
74 | */ |
||
75 | 27 | public function filename($name) |
|
95 | |||
96 | /** |
||
97 | * Returns an array of database migrations. |
||
98 | * |
||
99 | * @return array |
||
100 | */ |
||
101 | 18 | public function migrations() |
|
102 | { |
||
103 | 18 | $migration = $this->load(); |
|
104 | |||
105 | 18 | $items = $migration->find_migrations(); |
|
106 | |||
107 | 18 | $this->set('migration_enabled', 'false'); |
|
108 | |||
109 | 18 | return (array) $items; |
|
110 | } |
||
111 | |||
112 | /** |
||
113 | * Migrates to a specific schema version. |
||
114 | * |
||
115 | * @param string $version |
||
116 | * @return boolean|string |
||
117 | */ |
||
118 | 18 | public function migrate($version = null) |
|
119 | { |
||
120 | 18 | $migration = $this->load(); |
|
121 | |||
122 | 18 | if ($version !== null) { |
|
123 | 15 | $result = $migration->version($version); |
|
124 | 15 | } else { |
|
125 | 3 | $result = $migration->latest(); |
|
126 | } |
||
127 | |||
128 | 18 | if ($result !== true) { |
|
129 | 18 | $this->set('migration_version', $result); |
|
130 | 18 | } |
|
131 | |||
132 | 18 | $this->set('migration_enabled', 'false'); |
|
133 | |||
134 | 18 | return $result; |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * Resets the migration schema. |
||
139 | * |
||
140 | * @return boolean |
||
141 | */ |
||
142 | 6 | public function reset() |
|
143 | { |
||
144 | 6 | $migration = $this->load(); |
|
145 | |||
146 | 6 | $result = (string) $migration->version(0); |
|
147 | |||
148 | 6 | $result = $result === '000' ? 0 : $result; |
|
149 | |||
150 | 6 | $this->set('migration_version', $result); |
|
151 | |||
152 | 6 | $this->set('migration_enabled', 'false'); |
|
153 | |||
154 | 6 | return (string) $result; |
|
155 | } |
||
156 | |||
157 | /** |
||
158 | * Returns a value from migration configuration. |
||
159 | * |
||
160 | * @param string $key |
||
161 | * @param mixed $default |
||
162 | * @return mixed |
||
163 | */ |
||
164 | 36 | protected function get($key, $default = null) |
|
176 | |||
177 | /** |
||
178 | * Loads the migration instance. |
||
179 | * |
||
180 | * @return \CI_Migration |
||
181 | */ |
||
182 | 27 | protected function load() |
|
194 | |||
195 | /** |
||
196 | * Changes the value from migration configuration. |
||
197 | * |
||
198 | * @param string $key |
||
199 | * @param string $value |
||
200 | * @return void |
||
201 | */ |
||
202 | 27 | protected function set($key, $value) |
|
216 | } |
||
217 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.