@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | 'batch' => $batch, |
331 | 331 | ]; |
332 | 332 | |
333 | - $this->insertOrUpdate($sets, ['filename' => $sets[ 'filename' ]]); |
|
333 | + $this->insertOrUpdate($sets, ['filename' => $sets['filename']]); |
|
334 | 334 | } |
335 | 335 | } |
336 | 336 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | $timestamp = filemtime($filename); |
367 | 367 | preg_match('/\d{4}[-]?\d{2}[-]?\d{2}[-]?\d{2}[-]?\d{2}[-]?\d{2}/', $filename, $matches); |
368 | 368 | |
369 | - $timestamp = count($matches) ? strtotime($matches[ 0 ]) : $timestamp; |
|
369 | + $timestamp = count($matches) ? strtotime($matches[0]) : $timestamp; |
|
370 | 370 | |
371 | 371 | return date('Y-m-d H:i:s', $timestamp); |
372 | 372 | } |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $version = 'v0.0.0'; |
388 | 388 | preg_match('/v\d*[.]?\d*[.]\d*/', $filename, $matches); |
389 | 389 | |
390 | - return count($matches) ? $matches[ 0 ] : $version; |
|
390 | + return count($matches) ? $matches[0] : $version; |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // ------------------------------------------------------------------------ |
@@ -424,13 +424,13 @@ discard block |
||
424 | 424 | */ |
425 | 425 | public function import() |
426 | 426 | { |
427 | - if( ! empty($this->optionSql)) { |
|
428 | - $filePath = PATH_DATABASE . str_replace(['/','\\'], DIRECTORY_SEPARATOR, $this->optionSql); |
|
427 | + if ( ! empty($this->optionSql)) { |
|
428 | + $filePath = PATH_DATABASE . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $this->optionSql); |
|
429 | 429 | |
430 | - if(is_file($filePath)) { |
|
430 | + if (is_file($filePath)) { |
|
431 | 431 | $sqlStatement = file_get_contents($filePath); |
432 | 432 | |
433 | - if($this->model->db->query($sqlStatement)) { |
|
433 | + if ($this->model->db->query($sqlStatement)) { |
|
434 | 434 | |
435 | 435 | } else { |
436 | 436 | |
@@ -446,9 +446,9 @@ discard block |
||
446 | 446 | */ |
447 | 447 | public function latest() |
448 | 448 | { |
449 | - if($result = $this->model->findWhere(['batch' => $this->model->getLatestBatch()])) { |
|
450 | - if($result->count()) { |
|
451 | - foreach($result as $row) { |
|
449 | + if ($result = $this->model->findWhere(['batch' => $this->model->getLatestBatch()])) { |
|
450 | + if ($result->count()) { |
|
451 | + foreach ($result as $row) { |
|
452 | 452 | $this->run($row->filename, 'up'); |
453 | 453 | } |
454 | 454 | } |
@@ -466,17 +466,17 @@ discard block |
||
466 | 466 | $requestBatch = ($latestBatch - 1); |
467 | 467 | $requestBatch = $requestBatch < 1 ? 1 : $requestBatch; |
468 | 468 | |
469 | - if( ! empty($this->optionBatch) ) { |
|
469 | + if ( ! empty($this->optionBatch)) { |
|
470 | 470 | $requestBatch = $this->optionBatch; |
471 | 471 | } |
472 | 472 | |
473 | 473 | $batches = range($requestBatch, $latestBatch, 1); |
474 | 474 | $batches = array_reverse($batches); |
475 | 475 | |
476 | - foreach($batches as $batch) { |
|
477 | - if($result = $this->model->findWhere(['batch' => $batch])) { |
|
478 | - if($result->count()) { |
|
479 | - foreach($result as $row) { |
|
476 | + foreach ($batches as $batch) { |
|
477 | + if ($result = $this->model->findWhere(['batch' => $batch])) { |
|
478 | + if ($result->count()) { |
|
479 | + foreach ($result as $row) { |
|
480 | 480 | $this->run($row->filename, 'down'); |
481 | 481 | $this->run($row->filename, 'up'); |
482 | 482 | } |
@@ -496,10 +496,10 @@ discard block |
||
496 | 496 | $batches = range(1, $batch, 1); |
497 | 497 | $batches = array_reverse($batches); |
498 | 498 | |
499 | - foreach($batches as $batch) { |
|
500 | - if($result = $this->model->findWhere(['batch' => $batch])) { |
|
501 | - if($result->count()) { |
|
502 | - foreach($result as $row) { |
|
499 | + foreach ($batches as $batch) { |
|
500 | + if ($result = $this->model->findWhere(['batch' => $batch])) { |
|
501 | + if ($result->count()) { |
|
502 | + foreach ($result as $row) { |
|
503 | 503 | $this->run($row->filename, 'down'); |
504 | 504 | $this->run($row->filename, 'up'); |
505 | 505 | } |
@@ -515,9 +515,9 @@ discard block |
||
515 | 515 | */ |
516 | 516 | public function fresh() |
517 | 517 | { |
518 | - if($result = $this->model->findWhere(['batch' => 1])) { |
|
519 | - if($result->count()) { |
|
520 | - foreach($result as $row) { |
|
518 | + if ($result = $this->model->findWhere(['batch' => 1])) { |
|
519 | + if ($result->count()) { |
|
520 | + foreach ($result as $row) { |
|
521 | 521 | $this->run($row->filename, 'up'); |
522 | 522 | } |
523 | 523 | } |
@@ -538,13 +538,13 @@ discard block |
||
538 | 538 | protected function run($filename, $method = 'up') |
539 | 539 | { |
540 | 540 | $filePaths = [ |
541 | - PATH_DATABASE . 'migrations' . DIRECTORY_SEPARATOR . str_replace(['/','\\'], DIRECTORY_SEPARATOR, $filename), |
|
542 | - PATH_DATABASE . str_replace(['/','\\'], DIRECTORY_SEPARATOR, $filename) |
|
541 | + PATH_DATABASE . 'migrations' . DIRECTORY_SEPARATOR . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $filename), |
|
542 | + PATH_DATABASE . str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $filename) |
|
543 | 543 | ]; |
544 | 544 | |
545 | - foreach($filePaths as $filePath) { |
|
546 | - if(is_file($filePath)) { |
|
547 | - if(pathinfo($filePath, PATHINFO_EXTENSION) == 'php') { |
|
545 | + foreach ($filePaths as $filePath) { |
|
546 | + if (is_file($filePath)) { |
|
547 | + if (pathinfo($filePath, PATHINFO_EXTENSION) == 'php') { |
|
548 | 548 | require_once($filePath); |
549 | 549 | $filename = pathinfo($filePath, PATHINFO_FILENAME); |
550 | 550 | $filename = explode('_', $filename); |
@@ -560,22 +560,22 @@ discard block |
||
560 | 560 | ->setNewLinesAfter(1) |
561 | 561 | ); |
562 | 562 | |
563 | - if(class_exists($className)) { |
|
563 | + if (class_exists($className)) { |
|
564 | 564 | $migration = new $className(); |
565 | 565 | |
566 | - if(method_exists($migration, $method)) { |
|
566 | + if (method_exists($migration, $method)) { |
|
567 | 567 | call_user_func([$migration, $method]); |
568 | 568 | |
569 | 569 | output()->write( |
570 | 570 | (new Format()) |
571 | 571 | ->setContextualClass(Format::SUCCESS) |
572 | - ->setString(language()->getLine('CLI_MIGRATION_RUN_'.strtoupper($method).'_SUCCESS', [$filename])) |
|
572 | + ->setString(language()->getLine('CLI_MIGRATION_RUN_' . strtoupper($method) . '_SUCCESS', [$filename])) |
|
573 | 573 | ->setNewLinesAfter(1) |
574 | 574 | ); |
575 | 575 | |
576 | - if($method === 'up') { |
|
577 | - if(method_exists($migration, 'seed')) { |
|
578 | - if($this->optionSeed) { |
|
576 | + if ($method === 'up') { |
|
577 | + if (method_exists($migration, 'seed')) { |
|
578 | + if ($this->optionSeed) { |
|
579 | 579 | call_user_func([$migration, 'seed']); |
580 | 580 | |
581 | 581 | output()->write( |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | } |
590 | 590 | } |
591 | 591 | } |
592 | - } elseif(pathinfo($filePath, PATHINFO_EXTENSION) == 'sql') { |
|
592 | + } elseif (pathinfo($filePath, PATHINFO_EXTENSION) == 'sql') { |
|
593 | 593 | $sqlStatement = file_get_contents($filePath); |
594 | 594 | |
595 | - if($this->model->db->query($sqlStatement)) { |
|
595 | + if ($this->model->db->query($sqlStatement)) { |
|
596 | 596 | output()->write( |
597 | 597 | (new Format()) |
598 | 598 | ->setContextualClass(Format::SUCCESS) |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | */ |
622 | 622 | public function execute() |
623 | 623 | { |
624 | - if($this->optionFilename) { |
|
624 | + if ($this->optionFilename) { |
|
625 | 625 | $this->run($this->optionFilename); |
626 | 626 | } |
627 | 627 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | |
103 | 103 | $className = studlycase($this->optionFilename); |
104 | 104 | |
105 | - if(empty($this->optionFileVersion)) { |
|
105 | + if (empty($this->optionFileVersion)) { |
|
106 | 106 | $filename = date('YmdHis') . '_' . underscore($this->optionFilename); |
107 | 107 | } else { |
108 | 108 | $filename = $this->optionFileVersion . '_' . underscore($this->optionFilename); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | |
111 | 111 | $filePath = PATH_DATABASE . 'migrations' . DIRECTORY_SEPARATOR; |
112 | 112 | |
113 | - if( ! empty($this->optionPath) ) { |
|
113 | + if ( ! empty($this->optionPath)) { |
|
114 | 114 | $filePath = $filePath . $this->optionPath; |
115 | 115 | } |
116 | 116 | |
@@ -133,15 +133,15 @@ discard block |
||
133 | 133 | exit(EXIT_ERROR); |
134 | 134 | } |
135 | 135 | |
136 | - $vars[ 'CREATE_DATETIME' ] = date('d/m/Y H:m'); |
|
137 | - $vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\Sql\Migration'; |
|
136 | + $vars['CREATE_DATETIME'] = date('d/m/Y H:m'); |
|
137 | + $vars['BASE_MIGRATION'] = 'O2System\Framework\Models\Sql\Migration'; |
|
138 | 138 | |
139 | - if($this->optionNoSql) { |
|
140 | - $vars[ 'BASE_MIGRATION' ] = 'O2System\Framework\Models\NoSql\Migration'; |
|
139 | + if ($this->optionNoSql) { |
|
140 | + $vars['BASE_MIGRATION'] = 'O2System\Framework\Models\NoSql\Migration'; |
|
141 | 141 | } |
142 | 142 | |
143 | - $vars[ 'CLASS' ] = $className; |
|
144 | - $vars[ 'FILEPATH' ] = $filePath; |
|
143 | + $vars['CLASS'] = $className; |
|
144 | + $vars['FILEPATH'] = $filePath; |
|
145 | 145 | |
146 | 146 | $phpTemplate = <<<PHPTEMPLATE |
147 | 147 | <?php |