1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SamIT\Yii2\PhpFpm\controllers; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Docker\API\Model\BuildInfo; |
8
|
|
|
use Docker\Context\Context; |
9
|
|
|
use Docker\Context\ContextBuilder; |
10
|
|
|
use Docker\Docker; |
11
|
|
|
use Docker\Stream\BuildStream; |
12
|
|
|
use SamIT\Yii2\PhpFpm\Module; |
13
|
|
|
use yii\console\Controller; |
14
|
|
|
use yii\console\ExitCode; |
15
|
|
|
use yii\helpers\Console; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class MigrateController |
19
|
|
|
* @package SamIT\Yii2\PhpFpm\controllers |
20
|
|
|
* @property Module $module |
21
|
|
|
*/ |
22
|
|
|
class MigrateController extends \yii\console\controllers\MigrateController |
23
|
|
|
{ |
24
|
|
|
|
25
|
1 |
View Code Duplication |
public function stdout($string) |
|
|
|
|
26
|
|
|
{ |
27
|
1 |
|
if ($this->isColorEnabled()) { |
28
|
|
|
$args = \func_get_args(); |
29
|
|
|
\array_shift($args); |
30
|
|
|
$string = Console::ansiFormat($string, $args); |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
echo $string; |
34
|
1 |
|
return \strlen($string); |
35
|
|
|
} |
36
|
|
|
|
37
|
1 |
|
public function beforeAction($action) |
38
|
|
|
{ |
39
|
|
|
// Obtain lock. |
40
|
1 |
|
$this->stdout('Waiting for lock...', Console::FG_CYAN); |
41
|
1 |
|
if (!$this->module->getLock()) { |
42
|
1 |
|
$this->stdout("FAIL\n", Console::FG_RED); |
43
|
1 |
|
return false; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$this->stdout("OK\n", Console::FG_GREEN); |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function actionUp($limit = 0) |
51
|
|
|
{ |
52
|
|
|
$command = "/project/{$this->module->getConsoleEntryScript()} migrate/up"; |
53
|
|
|
if ($limit != 0) { |
54
|
|
|
$command .= " $limit"; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
if (!$this->interactive) { |
58
|
|
|
$command .= ' --interactive=0'; |
59
|
|
|
} |
60
|
|
|
$this->stdout("Executing: $command\n", Console::FG_CYAN); |
61
|
|
|
$result = ExitCode::OK; |
62
|
|
|
\passthru($command, $result); |
63
|
|
|
return $result; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
|
67
|
|
|
|
68
|
|
|
|
69
|
|
|
|
70
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.