clearCache(); $this->disableHooks(); $this->checkModules(); $this->rebuildMetadata(); $this->populateConfigParameters(); $this->rebuildDatabase($entityTypeList); $this->rebuildActionProcessor->process(); $this->configMissingDefaultParamsSaver->process(); $this->enableHooks(); } /** * Clear cache. * * @throws Error */ public function clearCache(): void { $this->module->clearCache(); $result = $this->fileManager->removeInDir($this->cachePath); if (!$result) { throw new Error("Error while clearing cache"); } $this->updateCacheTimestamp(); } /** * Rebuild database. * * @param ?string[] $entityTypeList * @param RebuildMode::* $mode * @throws Error */ public function rebuildDatabase(?array $entityTypeList = null, string $mode = RebuildMode::SOFT): void { $schemaManager = $this->schemaManager; try { $result = $schemaManager->rebuild($entityTypeList, $mode); } catch (Throwable $e) { $result = false; $this->log->error( "Failed to rebuild database schema. Details: ". $e->getMessage() . " at " . $e->getFile() . ":" . $e->getLine() ); } if (!$result) { throw new Error("Error while rebuilding database. See log file for details."); } $databaseType = strtolower($schemaManager->getDatabaseHelper()->getType()); if ( !$this->config->get('actualDatabaseType') || $this->config->get('actualDatabaseType') !== $databaseType ) { $this->configWriter->set('actualDatabaseType', $databaseType); } $databaseVersion = $schemaManager->getDatabaseHelper()->getVersion(); if ( !$this->config->get('actualDatabaseVersion') || $this->config->get('actualDatabaseVersion') !== $databaseVersion ) { $this->configWriter->set('actualDatabaseVersion', $databaseVersion); } $this->configWriter->updateCacheTimestamp(); $this->configWriter->save(); } /** * Rebuild metadata. */ public function rebuildMetadata(): void { $this->metadata->init(true); $this->ormMetadataData->reload(); $this->entityManager->getMetadata()->updateData(); $this->updateCacheTimestamp(); } /** * Update cache timestamp. */ public function updateCacheTimestamp(): void { $this->configWriter->updateCacheTimestamp(); $this->configWriter->save(); } /** * Update app timestamp. */ public function updateAppTimestamp(): void { $this->configWriter->set('appTimestamp', time()); $this->configWriter->save(); } private function populateConfigParameters(): void { $this->setFullTextConfigParameters(); $this->setCryptKeyConfigParameter(); if (!$this->config->get('appTimestamp')) { $this->updateAppTimestamp(); } $this->configWriter->save(); } private function setFullTextConfigParameters(): void { $databaseParams = $this->databaseParamsFactory->create(); if ($databaseParams->getPlatform() !== 'Mysql') { return; } $helper = $this->injectableFactory->create(DatabaseHelper::class); $fullTextSearchMinLength = $helper->getParam('ft_min_word_len'); if ($fullTextSearchMinLength !== null) { $fullTextSearchMinLength = (int) $fullTextSearchMinLength; } $this->configWriter->set('fullTextSearchMinLength', $fullTextSearchMinLength); } private function setCryptKeyConfigParameter(): void { if ($this->config->get('cryptKey')) { return; } $cryptKey = Util::generateSecretKey(); $this->configWriter->set('cryptKey', $cryptKey); } private function disableHooks(): void { $this->hookManager->disable(); } private function enableHooks(): void { $this->hookManager->enable(); } /** * @throws Error */ private function checkModules(): void { $moduleNameList = $this->module->getList(); if (count(array_unique($moduleNameList)) !== count($moduleNameList)) { throw new Error( "There is a same module in both `custom` and `internal` directories. " . "Should be only in one location." ); } } }