1
|
|
|
<?php namespace Tequilarapido\Cli\Commands\Base; |
2
|
|
|
|
3
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
4
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
5
|
|
|
use Tequilarapido\Cli\Commands\Base\AbstractDatabaseCommand; |
6
|
|
|
use Tequilarapido\Database\Database; |
7
|
|
|
use Tequilarapido\Database\Table; |
8
|
|
|
|
9
|
|
|
abstract class AbstractDatabaseConvertToEngine extends AbstractDatabaseCommand |
10
|
|
|
{ |
11
|
|
|
protected $engine = null; |
12
|
|
|
|
13
|
|
|
protected $databaseTables; |
14
|
|
|
|
15
|
|
|
protected function configure() |
16
|
|
|
{ |
17
|
|
|
parent::configure(); |
18
|
|
|
|
19
|
|
|
$description = ''; |
20
|
|
|
$description .= 'Converts database tables to ' . $this->engine . '. ' . PHP_EOL; |
21
|
|
|
$description .= ' '; |
22
|
|
|
|
23
|
|
|
$this |
24
|
|
|
->setName('db:' . strtolower($this->engine)) |
25
|
|
|
->setDescription($description); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
29
|
|
|
{ |
30
|
|
|
parent::execute($input, $output); |
31
|
|
|
|
32
|
|
|
// Database configuration |
33
|
|
|
$dbConfig = $this->config->getDatabase(); |
34
|
|
|
$databaseName = $this->config->getDatabaseName(); |
35
|
|
|
|
36
|
|
|
// Connection |
37
|
|
|
$this->db = new Database(); |
38
|
|
|
$this->db->connect($dbConfig); |
39
|
|
|
|
40
|
|
|
// Tables |
41
|
|
|
$this->table = new Table(); |
|
|
|
|
42
|
|
|
$this->databaseTables = $this->table->all($databaseName); |
43
|
|
|
|
44
|
|
|
// Set proper engine |
45
|
|
|
$this->setEngine($this->engine); |
46
|
|
|
|
47
|
|
|
// Test out |
48
|
|
|
$isOK = $this->table->isEngine($databaseName, $this->engine); |
49
|
|
|
if ($isOK) { |
50
|
|
|
$this->output->success("Done. All tables are now " . $this->engine); |
|
|
|
|
51
|
|
|
} else { |
52
|
|
|
$this->output->warn("Done. But not sure all tables are " . $this->engine); |
|
|
|
|
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $engine |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
protected function setEngine($engine) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$this->output->title("Setting database engine to $engine"); |
|
|
|
|
62
|
|
|
|
63
|
|
|
// Cli progress setup |
64
|
|
|
$progress = $this->getHelperSet()->get('progress'); |
65
|
|
|
$progress->start($this->output, count($this->databaseTables)); |
66
|
|
|
|
67
|
|
|
foreach ($this->databaseTables as $tableName) { |
68
|
|
|
|
69
|
|
|
$this->output->info($tableName); |
|
|
|
|
70
|
|
|
$this->table->alterEngine($tableName, $engine); |
71
|
|
|
$progress->advance(); |
72
|
|
|
} |
73
|
|
|
$progress->finish(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..