Skip to content

Commit 1ef07ef

Browse files
authored
Merge pull request #3 from vcian/main
Merge latest code.
2 parents 45b6dfe + 3bc918c commit 1ef07ef

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

src/Command/DBConstraintCheck.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,16 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in
8484
*/
8585
public function displayTable(string $tableName, $io): void
8686
{
87+
$engine = $this->getTableEngine($tableName);
88+
if( $engine == 'InnoDB') {
89+
$size = $this->getTablesSize($tableName);
90+
} else {
91+
$size = Constant::DASH;
92+
}
93+
8794
$data = [
8895
"table" => $tableName,
89-
"size" => $this->getTablesSize($tableName),
96+
"size" => $size,
9097
"fields" => $this->getTableFields($tableName),
9198
'field_count' => count($this->getTableFields($tableName)),
9299
'constrain' => [

src/Traits/AuditService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public function getTableFields(string $tableName): array
3838
*/
3939
public function getTablesSize(string $tableName): string
4040
{
41-
return $this->getTableSize($tableName);
41+
$engine = $this->getTableEngine($tableName);
42+
if( $engine == 'InnoDB') {
43+
return $this->getTableSize($tableName);
44+
} else {
45+
return Constant::DASH;
46+
}
4247
}
4348

4449
/**

src/Traits/DBConnection.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ public function getTableSize(string $tableName): string
126126
return Constant::NULL;
127127
}
128128

129+
/**
130+
* Get Table Engine
131+
* @param string $tableName
132+
*/
133+
public function getTableEngine(string $tableName)
134+
{
135+
try {
136+
$conn = createConnection();
137+
$query = 'SELECT engine FROM information_schema.Tables where TABLE_SCHEMA = "'. $this->getDatabaseName() .'" AND TABLE_NAME = "' . $tableName . '" Limit 1';
138+
139+
$query = $conn->query($query);
140+
$result = $query->fetch_assoc();
141+
142+
if (isset($result['ENGINE']) && !empty($result['ENGINE'])) {
143+
return $result['ENGINE'];
144+
}
145+
146+
} catch (Exception $exception) {
147+
error_log($exception->getMessage());
148+
}
149+
return Constant::NULL;
150+
}
151+
129152
/**
130153
* Get Field Data Type
131154
* @param string $tableName

src/Traits/Rules.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ public function tablesRule(): array
2727
$tableList = $this->getTableList();
2828
foreach ($tableList as $tableName) {
2929
$status = $this->checkStatus($tableName);
30-
$size = $this->getTableSize($tableName);
30+
$engine = $this->getTableEngine($tableName);
31+
32+
if( $engine == 'InnoDB') {
33+
$size = $this->getTableSize($tableName);
34+
} else {
35+
$size = Constant::DASH;
36+
}
37+
3138
$checkTableStandard[] = ["name" => $tableName, "status" => $status, "size" => $size];
3239
}
3340
} catch (Exception $exception) {

0 commit comments

Comments
 (0)