Browse Source

Merge pull request #4556 from weseek/feat/page-migration-i18n

feat: page migration i18n
Yuki Takei 4 years ago
parent
commit
567d7ece43

+ 9 - 0
packages/app/resource/locales/en_US/admin/admin.json

@@ -19,6 +19,15 @@
     "bug_report": "Submitting a bug report",
     "submit_bug_report": "<a href='https://github.com/weseek/growi/issues/new?assignees=&labels=bug&template=bug-report.md&title=Bug%3A' target='_blank' rel='noreferrer'>then submit your issue to GitHub.</a>"
   },
+  "v5_page_migration": {
+    "migration_desc": "Some of the public pages have the old schema. To take advantage of new features such as page trees and easy renaming, please upgrade the schema of all your pages.",
+    "migration_note": "Note: You will lose unique constraints from the page paths.",
+    "upgrade_to_v5": "Upgrade to V5",
+    "modal_migration_warning": "This process may take long. It is highly recommended that administrators tell users not to create, modify, or delete pages during migration.",
+    "start_upgrading": "Start upgrading",
+    "successfully_started": "Succeeded to start migration",
+    "already_upgraded": "You have already completed upgrading"
+  },
   "app_setting": {
     "site_name": "Site name",
     "sitename_change": "You can change site name which is used for header and HTML title.",

+ 1 - 0
packages/app/resource/locales/en_US/translation.json

@@ -106,6 +106,7 @@
   "Create under": "Create page under below:",
   "Wiki Management Home Page": "Wiki Management Home Page",
   "App Settings": "App Settings",
+  "V5 Page Migration": "V5 Page Migration",
   "Site URL settings": "Site URL settings",
   "Markdown Settings": "Markdown Settings",
   "Customize": "Customize",

+ 9 - 0
packages/app/resource/locales/ja_JP/admin/admin.json

@@ -19,6 +19,15 @@
     "bug_report": "バグを報告する",
     "submit_bug_report": "<a href='https://github.com/weseek/growi/issues/new?assignees=&labels=bug&template=bug-report.md&title=Bug%3A' target='_blank' rel='noreferrer'>次に GitHub で Issue を投稿してください。</a>"
   },
+  "v5_page_migration": {
+    "migration_desc": "公開されているページに古いスキーマのものが存在します。ページツリーや簡単なリネームなどの新機能を利用するには、全てのページのスキーマをアップグレードしてください。",
+    "migration_note": "注意: ページパスからユニーク制約が失われます。",
+    "upgrade_to_v5": "V5 にアップグレード",
+    "modal_migration_warning": "管理者はユーザーに、マイグレーション中はページを作成・変更・削除しないように伝えることを強くお勧めします。",
+    "start_upgrading": "アップグレードを開始",
+    "successfully_started": "正常にマイグレーションが開始されました",
+    "already_upgraded": "アップグレードは既に完了しています"
+  },
   "app_setting": {
     "site_name": "サイト名",
     "sitename_change": "ヘッダーや HTML タイトルに使用されるサイト名を変更できます。",

+ 1 - 0
packages/app/resource/locales/ja_JP/translation.json

@@ -106,6 +106,7 @@
   "Create under": "ページを以下に作成",
   "Wiki Management Home Page": "Wiki管理トップ",
   "App Settings": "アプリ設定",
+  "V5 Page Migration": "V5 ページマイグレーション",
   "Site URL settings": "サイトURL設定",
   "Markdown Settings": "マークダウン設定",
   "Customize": "カスタマイズ",

+ 9 - 0
packages/app/resource/locales/zh_CN/admin/admin.json

@@ -19,6 +19,15 @@
     "bug_report": "提交一个错误报告",
     "submit_bug_report": "<a href='https://github.com/weseek/growi/issues/new?assignees=&labels=bug&template=bug-report.md&title=Bug%3A' target='_blank' rel='noreferrer'>然后提交你的问题到GitHub。</a>"
   },
+  "v5_page_migration": {
+    "migration_desc": "Some of the public pages have the old schema. To take advantage of new features such as page trees and easy renaming, please upgrade the schema of all your pages. ",
+    "migration_note": "Note: You will lose unique constraints from the page paths.",
+    "upgrade_to_v5": "Upgrade to V5",
+    "modal_migration_warning": "This process may take long. It is highly recommended that administrators tell users not to create, modify, or delete pages during migration.",
+    "start_upgrading": "Start upgrading",
+    "successfully_started": "Succeeded to start migration",
+    "already_upgraded": "You have already completed upgrading"
+  },
   "app_setting": {
     "site_name": "网站名称 ",
     "sitename_change": "您可以更改用于标题和HTML标题的网站名称。",

+ 1 - 0
packages/app/resource/locales/zh_CN/translation.json

@@ -114,6 +114,7 @@
 	"Create under": "Create page under below:",
 	"Wiki Management Home Page": "Wiki管理首页",
 	"App Settings": "系统设置",
+  "V5 Page Migration": "V5 Page Migration",
 	"Site URL settings": "主页URL设置",
 	"Markdown Settings": "Markdown设置",
 	"Customize": "页面定制",

+ 0 - 1
packages/app/src/client/services/AdminAppContainer.js

@@ -449,7 +449,6 @@ export default class AdminAppContainer extends Container {
     return pluginSettingParams;
   }
 
-  // TODO: define data to interact
   /**
    * Start v5 page migration
    * @memberOf AdminAppContainer

+ 2 - 2
packages/app/src/components/Admin/AdminHome/AdminHome.jsx

@@ -46,10 +46,10 @@ class AdminHome extends React.Component {
           !isV5Compatible
           && (
             <div className={`alert ${alertStyle}`}>
-              GROWI is running with v4 compatible pages. To use new features such as Page tree or easy renaming, please migrate page schema to v5.<br />
+              {t('admin:v5_page_migration.migration_desc')}
               <a className="btn-link" href="/admin/app" rel="noopener noreferrer">
                 <i className="fa fa-link ml-1" aria-hidden="true"></i>
-                <strong>Upgrade to v5</strong>
+                <strong>{t('admin:v5_page_migration.upgrade_to_v5')}</strong>
               </a>
             </div>
           )

+ 1 - 1
packages/app/src/components/Admin/App/AppSettingsPageContents.jsx

@@ -25,7 +25,7 @@ class AppSettingsPageContents extends React.Component {
           && (
             <div className="row">
               <div className="col-lg-12">
-                <h2 className="admin-setting-header">V5 Page Migration</h2>
+                <h2 className="admin-setting-header">{t('V5 Page Migration')}</h2>
                 <V5PageMigration />
               </div>
             </div>

+ 19 - 14
packages/app/src/components/Admin/App/V5PageMigration.tsx

@@ -1,20 +1,32 @@
 import React, { FC, useState } from 'react';
-import PropTypes from 'prop-types';
 import { useTranslation } from 'react-i18next';
 import { V5PageMigrationModal } from './V5PageMigrationModal';
 import AdminAppContainer from '../../../client/services/AdminAppContainer';
 import { withUnstatedContainers } from '../../UnstatedUtils';
+import { toastSuccess, toastError } from '../../../client/util/apiNotification';
 
+type Props = {
+  adminAppContainer: typeof AdminAppContainer & { v5PageMigrationHandler: (action: string) => Promise<{ isV5Compatible: boolean }> },
+}
 
-const V5PageMigration: FC<any> = (props) => {
+const V5PageMigration: FC<Props> = (props: Props) => {
   const [isV5PageMigrationModalShown, setIsV5PageMigrationModalShown] = useState(false);
   const { adminAppContainer } = props;
-  const { isV5Compatible } = adminAppContainer.state;
   const { t } = useTranslation();
 
   const onConfirm = async() => {
     setIsV5PageMigrationModalShown(false);
-    await adminAppContainer.v5PageMigrationHandler('upgrade');
+    try {
+      const { isV5Compatible } = await adminAppContainer.v5PageMigrationHandler('upgrade');
+      if (isV5Compatible) {
+
+        return toastSuccess(t('admin:v5_page_migration.already_upgraded'));
+      }
+      toastSuccess(t('admin:v5_page_migration.successfully_started'));
+    }
+    catch (err) {
+      toastError(err);
+    }
   };
 
   return (
@@ -25,12 +37,12 @@ const V5PageMigration: FC<any> = (props) => {
         onCancel={() => setIsV5PageMigrationModalShown(false)}
       />
       <p className="card well">
-        GROWI is running with v4 compatible pages.<br />
-        To use new features such as Page tree or easy renaming, please migrate page schema to v5.<br />
+        {t('admin:v5_page_migration.migration_desc')}
+        <br />
         <br />
         <span className="text-danger">
           <i className="icon-exclamation icon-fw"></i>
-          Note: You will lose unique constraint from page path.
+          {t('admin:v5_page_migration.migration_note')}
         </span>
       </p>
       <div className="row my-3">
@@ -42,11 +54,4 @@ const V5PageMigration: FC<any> = (props) => {
   );
 };
 
-/**
- * Wrapper component for using unstated
- */
 export default withUnstatedContainers(V5PageMigration, [AdminAppContainer]);
-
-V5PageMigration.propTypes = {
-  adminAppContainer: PropTypes.instanceOf(AdminAppContainer).isRequired,
-};

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

@@ -32,10 +32,13 @@ export const V5PageMigrationModal: FC<V5PageMigrationModalProps> = (props: V5Pag
         Warning
       </ModalHeader>
       <ModalBody>
-        TODO: tell user
-        that this process may take long,
-        that the admin user is responsible for telling users not to do important interaction until it ends,
-        and that Page schema will no longer have a unique constraint in page path.
+        {t('admin:v5_page_migration.modal_migration_warning')}
+        <br />
+        <br />
+        <span className="text-danger">
+          <i className="icon-exclamation icon-fw"></i>
+          {t('admin:v5_page_migration.migration_note')}
+        </span>
       </ModalBody>
       <ModalFooter>
         <button
@@ -50,7 +53,7 @@ export const V5PageMigrationModal: FC<V5PageMigrationModalProps> = (props: V5Pag
           className="btn btn-outline-primary ml-3"
           onClick={onConfirm}
         >
-          Start Upgrading
+          {t('admin:v5_page_migration.start_upgrading')}
         </button>
       </ModalFooter>
     </Modal>

+ 1 - 0
packages/app/src/server/routes/apiv3/pages.js

@@ -690,6 +690,7 @@ module.exports = (crowi) => {
 
     switch (action) {
       case 'upgrade':
+
         try {
           const Page = crowi.model('Page');
           // not await

+ 24 - 9
packages/app/src/server/service/page.js

@@ -795,7 +795,12 @@ class PageService {
         const notExistingParentPaths = parentPaths.filter(path => !existingParentPaths.includes(path));
 
         // insertMany empty pages
-        await Page.insertMany(notExistingParentPaths.map(path => ({ path, isEmpty: true })));
+        try {
+          await Page.insertMany(notExistingParentPaths.map(path => ({ path, isEmpty: true })));
+        }
+        catch (err) {
+          logger.error('Failed to insert empty pages.', err);
+        }
 
         // find parents again
         const builder2 = new PageQueryBuilder(Page.find({}, { _id: 1, path: 1 }));
@@ -825,10 +830,14 @@ class PageService {
             },
           };
         });
-        const res = await Page.bulkWrite(updateManyOperations);
-
-        countPages += (res.items || []).length;
-        logger.info(`Page migration processing: (count=${countPages}, errors=${res.errors}, took=${res.took}ms)`);
+        try {
+          const res = await Page.bulkWrite(updateManyOperations);
+          countPages += (res.items || []).length;
+          logger.info(`Page migration processing: (count=${countPages}, errors=${res.errors}, took=${res.took}ms)`);
+        }
+        catch (err) {
+          logger.error('Failed to update page.parent.', err);
+        }
 
         callback();
       },
@@ -846,10 +855,16 @@ class PageService {
       return this.v5RecursiveMigration(grant, rootPath);
     }
 
-    logger.info('Successfully migrated all public pages.');
-    await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
-      'app:isV5Compatible': true,
-    });
+    try {
+      await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
+        'app:isV5Compatible': true,
+      });
+      logger.info('Successfully migrated all public pages.');
+    }
+    catch (err) {
+      // just to know
+      logger.error('Failed to update app:isV5Compatible to true.');
+    }
   }
 
 }