1 | <?php |
||
14 | class Migrator |
||
15 | { |
||
16 | /** |
||
17 | * Migrator configuration array. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $config; |
||
22 | |||
23 | /** |
||
24 | * Directory to store m. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $dir; |
||
29 | |||
30 | /** |
||
31 | * Files interactions. |
||
32 | * |
||
33 | * @var FileStorageInterface |
||
34 | */ |
||
35 | protected $files; |
||
36 | |||
37 | /** |
||
38 | * Interface that gives us access to the database. |
||
39 | * |
||
40 | * @var DatabaseStorageInterface |
||
41 | */ |
||
42 | protected $database; |
||
43 | |||
44 | /** |
||
45 | * TemplatesCollection instance. |
||
46 | * |
||
47 | * @var TemplatesCollection |
||
48 | */ |
||
49 | protected $templates; |
||
50 | |||
51 | /** |
||
52 | * Constructor. |
||
53 | * |
||
54 | * @param array $config |
||
55 | * @param TemplatesCollection $templates |
||
56 | * @param DatabaseStorageInterface $database |
||
57 | * @param FileStorageInterface $files |
||
58 | */ |
||
59 | public function __construct($config, TemplatesCollection $templates, DatabaseStorageInterface $database = null, FileStorageInterface $files = null) |
||
68 | |||
69 | /** |
||
70 | * Create migration file. |
||
71 | * |
||
72 | * @param string $name - migration name |
||
73 | * @param string $templateName |
||
74 | * @param array $replace - array of placeholders that should be replaced with a given values. |
||
75 | * |
||
76 | * @return string |
||
77 | */ |
||
78 | public function createMigration($name, $templateName, array $replace = []) |
||
93 | |||
94 | /** |
||
95 | * Run all migrations that were not run before. |
||
96 | */ |
||
97 | public function runMigrations() |
||
113 | |||
114 | /** |
||
115 | * Run a given migration. |
||
116 | * |
||
117 | * @param string $file |
||
118 | * |
||
119 | * @throws Exception |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | public function runMigration($file) |
||
135 | |||
136 | /** |
||
137 | * Log successful migration. |
||
138 | * |
||
139 | * @param string $migration |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | public function logSuccessfulMigration($migration) |
||
147 | |||
148 | /** |
||
149 | * Get ran migrations. |
||
150 | * |
||
151 | * @return array |
||
152 | */ |
||
153 | public function getRanMigrations() |
||
157 | |||
158 | /** |
||
159 | * Determine whether migration file for migration exists. |
||
160 | * |
||
161 | * @param string $migration |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function doesMigrationFileExist($migration) |
||
169 | |||
170 | /** |
||
171 | * Rollback a given migration. |
||
172 | * |
||
173 | * @param string $file |
||
174 | * |
||
175 | * @throws Exception |
||
176 | * |
||
177 | * @return mixed |
||
178 | */ |
||
179 | public function rollbackMigration($file) |
||
189 | |||
190 | /** |
||
191 | * Remove a migration name from the database so it can be run again. |
||
192 | * |
||
193 | * @param string $file |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | public function removeSuccessfulMigrationFromLog($file) |
||
201 | |||
202 | /** |
||
203 | * Delete migration file. |
||
204 | * |
||
205 | * @param string $migration |
||
206 | * |
||
207 | * @return bool |
||
208 | */ |
||
209 | public function deleteMigrationFile($migration) |
||
213 | |||
214 | /** |
||
215 | * Get array of migrations that should be ran. |
||
216 | * |
||
217 | * @return array |
||
218 | */ |
||
219 | public function getMigrationsToRun() |
||
227 | |||
228 | /** |
||
229 | * Construct migration file name from migration name and current time. |
||
230 | * |
||
231 | * @param string $name |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | protected function constructFileName($name) |
||
243 | |||
244 | /** |
||
245 | * Get a migration class name by a migration file name. |
||
246 | * |
||
247 | * @param string $file |
||
248 | * |
||
249 | * @return string |
||
250 | */ |
||
251 | protected function getMigrationClassNameByFileName($file) |
||
260 | |||
261 | /** |
||
262 | * Replace all placeholders in the stub. |
||
263 | * |
||
264 | * @param string $template |
||
265 | * @param array $replace |
||
266 | * |
||
267 | * @return string |
||
268 | */ |
||
269 | protected function replacePlaceholdersInTemplate($template, array $replace) |
||
277 | |||
278 | /** |
||
279 | * Resolve a migration instance from a file. |
||
280 | * |
||
281 | * @param string $file |
||
282 | * |
||
283 | * @throws Exception |
||
284 | * |
||
285 | * @return MigrationInterface |
||
286 | */ |
||
287 | protected function getMigrationObjectByFileName($file) |
||
301 | |||
302 | /** |
||
303 | * Require migration file. |
||
304 | * |
||
305 | * @param string $file |
||
306 | * |
||
307 | * @return void |
||
308 | */ |
||
309 | protected function requireMigrationFile($file) |
||
313 | |||
314 | /** |
||
315 | * Get path to a migration file. |
||
316 | * |
||
317 | * @param string $migration |
||
318 | * |
||
319 | * @return string |
||
320 | */ |
||
321 | protected function getMigrationFilePath($migration) |
||
325 | |||
326 | /** |
||
327 | * If package arrilot/bitrix-iblock-helper is loaded then we should disable its caching to avoid problems. |
||
328 | */ |
||
329 | private function disableBitrixIblockHelperCache() |
||
345 | } |
||
346 |