resultRedirectFactory->create(); try { $this->assertSchema(); $title = trim((string) $this->getRequest()->getParam('title')); if ($title === '') { throw new LocalizedException(__('Title is required.')); } $homepage = $this->collectionFactory->create() ->setPageSize(1) ->getFirstItem(); if (!$homepage->getId()) { $homepage = $this->homepageFactory->create(); } $homepage->addData([ 'title' => $title, 'content' => (string) $this->getRequest()->getParam('content'), 'meta_title' => trim((string) $this->getRequest()->getParam('meta_title')), 'meta_description' => trim((string) $this->getRequest()->getParam('meta_description')), 'meta_keywords' => trim((string) $this->getRequest()->getParam('meta_keywords')), ]); $this->homepageResource->save($homepage); $this->cacheTypeList->cleanType('block_html'); $this->cacheTypeList->cleanType('full_page'); $this->messageManager->addSuccessMessage(__('The wiki homepage has been saved.')); } catch (\Throwable $exception) { $this->messageManager->addErrorMessage($exception->getMessage()); } return $redirect->setPath('esun_wiki/homepage/edit'); } private function assertSchema(): void { $connection = $this->resourceConnection->getConnection(); $table = $this->resourceConnection->getTableName('esun_wiki_homepage'); if (!$connection->isTableExists($table)) { throw new LocalizedException(__( 'The Wiki homepage is not installed. Run "bin/magento setup:upgrade" and try again.' )); } $columns = $connection->describeTable($table); if (!isset( $columns['title'], $columns['content'], $columns['meta_title'], $columns['meta_description'], $columns['meta_keywords'] )) { throw new LocalizedException(__( 'The Wiki homepage schema is incomplete. Run "bin/magento setup:upgrade" and try again.' )); } } }