|
|
@@ -11,28 +11,50 @@ module.exports = function(crowi, app) {
|
|
|
|
|
|
const actions = {};
|
|
|
|
|
|
- function createInitialPages(owner, lang) {
|
|
|
+ async function initSearchIndex() {
|
|
|
+ const search = crowi.getSearcher();
|
|
|
+ if (search == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ await search.deleteIndex();
|
|
|
+ await search.buildIndex();
|
|
|
+ await search.addAllPages();
|
|
|
+ }
|
|
|
+
|
|
|
+ async function createInitialPages(owner, lang) {
|
|
|
+ const promises = [];
|
|
|
+
|
|
|
// create portal page for '/'
|
|
|
const welcomeMarkdownPath = path.join(crowi.localeDir, lang, 'welcome.md');
|
|
|
const welcomeMarkdown = fs.readFileSync(welcomeMarkdownPath);
|
|
|
- Page.create('/', welcomeMarkdown, owner, {});
|
|
|
+ promises.push(Page.create('/', welcomeMarkdown, owner, {}));
|
|
|
|
|
|
// create /Sandbox
|
|
|
const sandboxMarkdownPath = path.join(crowi.localeDir, lang, 'sandbox.md');
|
|
|
const sandboxMarkdown = fs.readFileSync(sandboxMarkdownPath);
|
|
|
- Page.create('/Sandbox', sandboxMarkdown, owner, {});
|
|
|
+ promises.push(Page.create('/Sandbox', sandboxMarkdown, owner, {}));
|
|
|
|
|
|
// create /Sandbox/Bootstrap3
|
|
|
const bs3MarkdownPath = path.join(crowi.localeDir, 'en-US', 'sandbox-bootstrap3.md');
|
|
|
const bs3Markdown = fs.readFileSync(bs3MarkdownPath);
|
|
|
- Page.create('/Sandbox/Bootstrap3', bs3Markdown, owner, {});
|
|
|
+ promises.push(Page.create('/Sandbox/Bootstrap3', bs3Markdown, owner, {}));
|
|
|
+
|
|
|
+ await Promise.all(promises);
|
|
|
+
|
|
|
+ try {
|
|
|
+ await initSearchIndex();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ logger.error('Failed to build Elasticsearch Indices', err);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
actions.index = function(req, res) {
|
|
|
return res.render('installer');
|
|
|
};
|
|
|
|
|
|
- actions.createAdmin = function(req, res, next) {
|
|
|
+ actions.install = async function(req, res, next) {
|
|
|
const registerForm = req.body.registerForm || {};
|
|
|
|
|
|
if (!req.form.isValid) {
|
|
|
@@ -45,39 +67,39 @@ module.exports = function(crowi, app) {
|
|
|
const password = registerForm.password;
|
|
|
const language = registerForm['app:globalLang'] || 'en-US';
|
|
|
|
|
|
- User.createUserByEmailAndPassword(name, username, email, password, language, function(err, userData) {
|
|
|
+ let adminUser;
|
|
|
+ try {
|
|
|
+ adminUser = await User.createUser(name, username, email, password, language);
|
|
|
+ await adminUser.asyncMakeAdmin();
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
+ req.form.errors.push('管理ユーザーの作成に失敗しました。' + err.message);
|
|
|
+ return res.render('installer');
|
|
|
+ }
|
|
|
+
|
|
|
+ Config.applicationInstall(function(err, configs) {
|
|
|
if (err) {
|
|
|
- req.form.errors.push('管理ユーザーの作成に失敗しました。' + err.message);
|
|
|
- // TODO
|
|
|
- return res.render('installer');
|
|
|
+ logger.error(err);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- userData.makeAdmin(function(err, userData) {
|
|
|
- Config.applicationInstall(function(err, configs) {
|
|
|
- if (err) {
|
|
|
- logger.error(err);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // save the globalLang config, and update the config cache
|
|
|
- Config.updateNamespaceByArray('crowi', {'app:globalLang': language}, function(err, config) {
|
|
|
- Config.updateConfigCache('crowi', config);
|
|
|
- });
|
|
|
-
|
|
|
- // login with passport
|
|
|
- req.logIn(userData, (err) => {
|
|
|
- if (err) { return next() }
|
|
|
- else {
|
|
|
- req.flash('successMessage', 'GROWI のインストールが完了しました!はじめに、このページで各種設定を確認してください。');
|
|
|
- return res.redirect('/admin/app');
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
-
|
|
|
- // create initial pages
|
|
|
- createInitialPages(userData, language);
|
|
|
+ // save the globalLang config, and update the config cache
|
|
|
+ Config.updateNamespaceByArray('crowi', {'app:globalLang': language}, function(err, config) {
|
|
|
+ Config.updateConfigCache('crowi', config);
|
|
|
+ });
|
|
|
+
|
|
|
+ // login with passport
|
|
|
+ req.logIn(adminUser, (err) => {
|
|
|
+ if (err) { return next() }
|
|
|
+ else {
|
|
|
+ req.flash('successMessage', 'GROWI のインストールが完了しました!はじめに、このページで各種設定を確認してください。');
|
|
|
+ return res.redirect('/admin/app');
|
|
|
+ }
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ // create initial pages
|
|
|
+ await createInitialPages(adminUser, language);
|
|
|
};
|
|
|
|
|
|
return actions;
|