@@ 329-365 (lines=37) @@ | ||
326 | * @return array A tuple containing the list of actions without actions for dropping the index |
|
327 | * and a list of drop index actions that were removed. |
|
328 | */ |
|
329 | protected function forgetDropIndex(Table $table, array $columns, array $actions) |
|
330 | { |
|
331 | $dropIndexActions = new ArrayObject(); |
|
332 | $indexes = collection($actions) |
|
333 | ->map(function ($alter) use ($table, $columns, $dropIndexActions) { |
|
334 | if ($alter->getTable()->getName() !== $table->getName()) { |
|
335 | return $alter; |
|
336 | } |
|
337 | ||
338 | $newAlter = new AlterTable($table); |
|
339 | collection($alter->getActions()) |
|
340 | ->map(function ($action) use ($columns) { |
|
341 | if (!$action instanceof DropIndex) { |
|
342 | return [$action, null]; |
|
343 | } |
|
344 | if ($action->getIndex()->getColumns() === $columns) { |
|
345 | return [null, $action]; |
|
346 | } |
|
347 | ||
348 | return [$action, null]; |
|
349 | }) |
|
350 | ->each(function ($tuple) use ($newAlter, $dropIndexActions) { |
|
351 | list($action, $dropIndex) = $tuple; |
|
352 | if ($action) { |
|
353 | $newAlter->addAction($action); |
|
354 | } |
|
355 | if ($dropIndex) { |
|
356 | $dropIndexActions->append($dropIndex); |
|
357 | } |
|
358 | }); |
|
359 | ||
360 | return $newAlter; |
|
361 | }) |
|
362 | ->toArray(); |
|
363 | ||
364 | return [$indexes, $dropIndexActions->getArrayCopy()]; |
|
365 | } |
|
366 | ||
367 | /** |
|
368 | * Deletes any RemoveColumn actions for the given table and exact columns |
|
@@ 376-411 (lines=36) @@ | ||
373 | * @return array A tuple containing the list of actions without actions for removing the column |
|
374 | * and a list of remove column actions that were removed. |
|
375 | */ |
|
376 | protected function forgetRemoveColumn(Table $table, array $columns, array $actions) |
|
377 | { |
|
378 | $removeColumnActions = new ArrayObject(); |
|
379 | $indexes = collection($actions) |
|
380 | ->map(function ($alter) use ($table, $columns, $removeColumnActions) { |
|
381 | if ($alter->getTable()->getName() !== $table->getName()) { |
|
382 | return $alter; |
|
383 | } |
|
384 | ||
385 | $newAlter = new AlterTable($table); |
|
386 | collection($alter->getActions()) |
|
387 | ->map(function ($action) use ($columns) { |
|
388 | if (!$action instanceof RemoveColumn) { |
|
389 | return [$action, null]; |
|
390 | } |
|
391 | if (in_array($action->getColumn(), $columns)) { |
|
392 | return [null, $action]; |
|
393 | } |
|
394 | ||
395 | return [$action, null]; |
|
396 | }) |
|
397 | ->each(function ($tuple) use ($newAlter, $removeColumnActions) { |
|
398 | list($action, $removeColumn) = $tuple; |
|
399 | if ($action) { |
|
400 | $newAlter->addAction($action); |
|
401 | } |
|
402 | if ($removeColumn) { |
|
403 | $removeColumnActions->append($removeColumn); |
|
404 | } |
|
405 | }); |
|
406 | ||
407 | return $newAlter; |
|
408 | }) |
|
409 | ->toArray(); |
|
410 | return [$indexes, $removeColumnActions->getArrayCopy()]; |
|
411 | } |
|
412 | ||
413 | /** |
|
414 | * Collects all table creation actions from the given intent |