Skip to content

Commit

Permalink
Added a log in case of an error during install.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-KM committed Dec 20, 2017
1 parent 94bc663 commit b016253
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@
*/
namespace Folksonomy;

use Doctrine\DBAL\DBALException;
use Folksonomy\Entity\Tag;
use Folksonomy\Entity\Tagging;
use Folksonomy\Form\ConfigForm;
use Omeka\Api\Representation\AbstractResourceEntityRepresentation;
use Omeka\Module\AbstractModule;
use Omeka\Module\Exception\ModuleCannotInstallException;
use Omeka\Permissions\Assertion\OwnsEntityAssertion;
use Omeka\Stdlib\Message;
use Zend\EventManager\Event;
use Zend\EventManager\SharedEventManagerInterface;
use Zend\Form\Element\Checkbox;
Expand Down Expand Up @@ -74,13 +77,18 @@ public function install(ServiceLocatorInterface $serviceLocator)
{
$t = $serviceLocator->get('MvcTranslator');

$sql = <<<'SQL'
// To resolve an issue on Percona sql server, the queries are divided.

$sqls = [];
$sqls[] = <<<'SQL'
CREATE TABLE `tag` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(190) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UNIQ_389B7835E237E06` (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL;
$sqls[] = <<<'SQL'
CREATE TABLE `tagging` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tag_id` int(11) DEFAULT NULL,
Expand All @@ -101,7 +109,19 @@ public function install(ServiceLocatorInterface $serviceLocator)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL;
$conn = $serviceLocator->get('Omeka\Connection');
$conn->exec($sql);

foreach ($sqls as $sql) {
try{
$conn->exec($sql);
} catch (DBALException $e) {
$this->uninstall($serviceLocator);
$logger = $serviceLocator->get('Omeka\Logger');
$logger->err($e);
throw new ModuleCannotInstallException(
new Message($t->translate('An error occured during table install. See log for more details. Code: %s; Message: %s'), // @translate
$e->getCode(), $e->getMessage()));
}
}

$settings = $serviceLocator->get('Omeka\Settings');
$this->manageSettings($settings, 'install');
Expand Down

0 comments on commit b016253

Please sign in to comment.