public function onUpdate(EavPersisterEvent $event)
 {
     $optionalData = $event->getOptionalData();
     $moduleId = $event->getModule()->getId();
     $tableName = '_flat_module_' . $moduleId;
     $container = $event->getContainer();
     $module = $event->getModule();
     if ($module->getGenerateFlat()) {
         $tableExists = $this->pdo->query('SELECT * FROM information_schema.tables WHERE table_name = "' . $tableName . '" LIMIT 1')->rowCount();
         if (!$tableExists) {
             $this->flatternTable->generate($module, true);
         }
         $context = $event->getContainer()->getContext();
         $containerId = $event->getContainer()->getId();
         $contextId = $event->getContainer()->getContext()->getId();
         $culture = $this->languageManager->getCulture();
         /** @var $moduleRepository EavModuleRepository * */
         $moduleRepository = $this->moduleRepository->getRepository($event->getModule())->setClass(new EavModuleRepository());
         $containerSQL = $moduleRepository->findByForFlatById($container, $module, $context)->getSQL();
         $containerRow = $moduleRepository->findByForFlatById($container, $module, $context)->getQuery()->getResult();
         $countColumnsSQL = $this->pdo->query('SHOW COLUMNS FROM ' . $tableName);
         $countColumnsSQL->execute();
         $columnsRes = $countColumnsSQL->fetchAll();
         $diffColumn = array();
         foreach ($columnsRes as $t) {
             $diffColumn[] = $t['Field'];
         }
         $columns = array_keys($containerRow[0]);
         if (count(array_diff($columns, $diffColumn)) > 0 || count(array_diff($diffColumn, $columns))) {
             $this->flatternTable->generate($module, true);
         }
         $sql = 'DELETE FROM ' . $tableName . '
         WHERE container_id = :container_id
         AND context_id = :context_id
         AND module_id = :module_id';
         $pdo = $this->pdo->prepare($sql);
         $pdo->bindParam('container_id', $containerId);
         $pdo->bindParam('context_id', $contextId);
         $pdo->bindParam('module_id', $moduleId);
         $pdo->execute();
         $sql = 'INSERT INTO ' . $tableName . ' ';
         $sql .= ' (' . implode(', ', $columns) . ' )';
         $sql .= $containerSQL;
         $pdo = $this->pdo->prepare($sql);
         $pdo->bindParam(':container_id', $containerId);
         $pdo->bindParam(':context_id', $contextId);
         $pdo->bindParam(':module_id', $moduleId);
         $pdo->execute();
     }
 }