Taichi Masuyama il y a 4 ans
Parent
commit
404ae4585d

+ 1 - 0
packages/app/src/components/Admin/App/V5PageMigration.tsx

@@ -13,6 +13,7 @@ const V5PageMigration: FC<any> = (props) => {
   const { t } = useTranslation();
 
   const onConfirm = async() => {
+    setIsV5PageMigrationModalShown(false);
     await adminAppContainer.v5PageMigrationHandler('upgrade');
   };
 

+ 2 - 2
packages/app/src/components/Admin/App/V5PageMigrationModal.tsx

@@ -1,4 +1,4 @@
-import React, { FC, useCallback } from 'react';
+import React, { FC } from 'react';
 import PropTypes from 'prop-types';
 import {
   Modal, ModalHeader, ModalBody, ModalFooter,
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
 
 type V5PageMigrationModalProps = {
   isModalOpen: boolean
-  onConfirm: () => Promise<any>;
+  onConfirm: () => Promise<void>;
   onCancel: () => void;
 };
 

+ 6 - 5
packages/app/src/server/routes/apiv3/pages.js

@@ -688,14 +688,14 @@ module.exports = (crowi) => {
 
     switch (action) {
       case 'notNow':
-        // set config to false
         try {
+          // set notNow
           await crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
             'app:isV5Compatible': false,
           });
-          return res.apiv3({});
         }
         catch (err) {
+          // not throw since this is not important
           logger.error('Error occurred while updating app:isV5Compatible.', err);
         }
         break;
@@ -703,6 +703,7 @@ module.exports = (crowi) => {
       case 'upgrade':
         try {
           const Page = crowi.model('Page');
+          // not await
           crowi.pageService.v5RecursiveMigration(Page.GRANT_PUBLIC);
         }
         catch (err) {
@@ -713,11 +714,11 @@ module.exports = (crowi) => {
 
       default:
         logger.error(`${action} action is not supported.`);
-        break;
+        return res.apiv3Err(new ErrorV3('This action is not supported.', 'not_supported'), 400);
     }
 
-    // TODO: determine what to respond
-    return res.apiv3({ status: 'inProgress' });
+    const isV5Compatible = crowi.configManager.getConfig('crowi', 'app:isV5Compatible');
+    return res.apiv3({ isV5Compatible });
   });
 
   return router;

+ 6 - 2
packages/app/src/server/service/page.js

@@ -836,9 +836,13 @@ class PageService {
       .pipe(migratePagesStream);
 
     await streamToPromise(migratePagesStream);
-    if (await Page.exists({ grant, parent: null })) {
-      await this.v5RecursiveMigration(grant, rootPath);
+    if (await Page.exists({ grant, parent: null, path: { $ne: '/' } })) {
+      return this.v5RecursiveMigration(grant, rootPath);
     }
+
+    await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
+      'app:isV5Compatible': true,
+    });
   }
 
 }