Skip to content

Node.js based forum software built for the modern web

closes #5813

Baris Usaklie036e26238a0
diff --git a/src/controllers/index.js b/src/controllers/index.js
index 0f15d2f4ab..84c20ade81 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -291,8 +291,8 @@ Controllers.confirmEmail = function (req, res) {
Controllers.robots = function (req, res) {
res.set('Content-Type', 'text/plain');
- if (meta.config['robots.txt']) {
- res.send(meta.config['robots.txt']);
+ if (meta.config['robots:txt']) {
+ res.send(meta.config['robots:txt']);
} else {
res.send('User-agent: *\n' +
'Disallow: ' + nconf.get('relative_path') + '/admin/\n' +
diff --git a/src/upgrades/1.6.0/robots-config-change.js b/src/upgrades/1.6.0/robots-config-change.js
new file mode 100644
index 0000000000..3a18872bbc
--- /dev/null
+++ b/src/upgrades/1.6.0/robots-config-change.js
@@ -0,0 +1,35 @@
+'use strict';
+
+var async = require('async');
+var db = require('../../database');
+
+module.exports = {
+ name: 'Fix incorrect robots.txt schema',
+ timestamp: Date.UTC(2017, 6, 10),
+ method: function (callback) {
+ async.waterfall([
+ function (next) {
+ db.getObject('config', next);
+ },
+ function (config, next) {
+ if (!config) {
+ return callback();
+ }
+ // fix mongo nested data
+ if (config.robots && config.robots.txt) {
+ db.setObjectField('config', 'robots:txt', config.robots.txt, next);
+ } else if (typeof config['robots.txt'] === 'string' && config['robots.txt']) {
+ db.setObjectField('config', 'robots:txt', config['robots.txt'], next);
+ } else {
+ next();
+ }
+ },
+ function (next) {
+ db.deleteObjectField('config', 'robots', next);
+ },
+ function (next) {
+ db.deleteObjectField('config', 'robots.txt', next);
+ },
+ ], callback);
+ },
+};
diff --git a/src/views/admin/settings/web-crawler.tpl b/src/views/admin/settings/web-crawler.tpl
index 276a4fb0aa..45f7156ed9 100644
--- a/src/views/admin/settings/web-crawler.tpl
+++ b/src/views/admin/settings/web-crawler.tpl
@@ -5,7 +5,7 @@
<div class="col-sm-10 col-xs-12">
<form>
<strong>[[admin/settings/web-crawler:robots-txt]]</strong><br />
- <textarea class="form-control" data-field="robots.txt"></textarea>
+ <textarea class="form-control" data-field="robots:txt"></textarea>
</form>
</div>
</div>