protected function execute(InputInterface $input, OutputInterface $output)
{
// display error message
if (!$input->getOption("mode")) {
$this->writeError("Please specify the mode!");
exit;
}
$db = \Pimcore\Db::get();
if ($input->getOption("mode") == "optimize") {
$tables = $db->fetchAll("SHOW TABLES");
foreach ($tables as $table) {
$t = current($table);
try {
Logger::debug("Running: OPTIMIZE TABLE " . $t);
$db->query("OPTIMIZE TABLE " . $t);
} catch (\Exception $e) {
Logger::error($e);
}
}
} elseif ($input->getOption("mode") == "warmup") {
$tables = $db->fetchAll("SHOW TABLES");
foreach ($tables as $table) {
$t = current($table);
try {
Logger::debug("Running: SELECT COUNT(*) FROM {$t}");
$res = $db->fetchOne("SELECT COUNT(*) FROM {$t}");
Logger::debug("Result: " . $res);
} catch (\Exception $e) {
Logger::error($e);
}
}
}
}