From cb2d2dd36349758e4440a5419415425f26dd5265 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 10 Sep 2020 12:54:24 +0300 Subject: [PATCH] code style fix --- upgrades/6.0/scripts/BeforeUpgrade.php | 50 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/upgrades/6.0/scripts/BeforeUpgrade.php b/upgrades/6.0/scripts/BeforeUpgrade.php index af2370607d..bb7d31699d 100644 --- a/upgrades/6.0/scripts/BeforeUpgrade.php +++ b/upgrades/6.0/scripts/BeforeUpgrade.php @@ -27,40 +27,70 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ +use Espo\Core\Exceptions\Error; + class BeforeUpgrade { public function run($container) { $this->container = $container; - $myisamTableList = $this->getMyisamTableList($container); - if (!empty($myisamTableList)) { - $isCli = (substr(php_sapi_name(), 0, 3) == 'cli') ? true : false; - throw new \Espo\Core\Exceptions\Error("In v6.0 we have dropped a support of MyISAM engine for DB tables. You have the following tables that use MyISAM: " . implode(", ", $myisamTableList) . ". " . ($isCli ? "\n" : "
") . "Please change the engine to InnoDB for these tables then run upgrade again. See ". ($isCli ? "" : "") . "https://www.espocrm.com/blog/converting-myisam-engine-to-innodb." . ($isCli ? "" : "")); - } + $this->processMyIsamCheck(); } - protected function getMyisamTableList($container) + protected function processMyIsamCheck() { + $myisamTableList = $this->getMyIsamTableList(); + + if (empty($myisamTableList)) { + return; + } + + $isCli = (substr(php_sapi_name(), 0, 3) == 'cli') ? true : false; + + $tableListString = implode(", ", $myisamTableList); + + $lineBreak = $isCli ? "\n" : "
"; + + $link = "https://www.espocrm.com/blog/converting-myisam-engine-to-innodb"; + + $linkString = $isCli ? $link : "link"; + + $message = + "In v6.0 we have dropped a support of MyISAM engine for DB tables. " . + "You have the following tables that use MyISAM: {$tableListString}.{$lineBreak}" . + "Please change the engine to InnoDB for these tables then run upgrade again.{$lineBreak}" . + "See: {$linkString}."; + + throw new Error($message); + } + + protected function getMyIsamTableList() + { + $container = $this->container; + $pdo = $container->get('entityManager')->getPDO(); $databaseInfo = $container->get('config')->get('database'); try { + $sth = $pdo->prepare(" SELECT TABLE_NAME as tableName FROM information_schema.TABLES WHERE TABLE_SCHEMA = '". $databaseInfo['dbname'] ."' AND ENGINE = 'MyISAM' "); + $sth->execute(); - } catch (\Exception $e) { - return; + + }catch (Exception $e) { + return []; } - $tableList = $sth->fetchAll(\PDO::FETCH_COLUMN); + $tableList = $sth->fetchAll(PDO::FETCH_COLUMN); if (empty($tableList)) { - return; + return []; } return $tableList;