diff --git a/src/categories.js b/src/categories.js index 58c790c1a4..80ed12e621 100644 --- a/src/categories.js +++ b/src/categories.js @@ -275,7 +275,7 @@ var db = require('./database'), return callback(err); } - if (!Array.isArray(categories)) { + if (!Array.isArray(categories) || !categories.length) { return callback(null, []); } diff --git a/src/install.js b/src/install.js index 15005e8999..2fe604029b 100644 --- a/src/install.js +++ b/src/install.js @@ -366,26 +366,25 @@ function createCategories(next) { var Categories = require('./categories'); Categories.getAllCategories(function (err, categoryData) { - if (categoryData.length === 0) { - winston.warn('No categories found, populating instance with default categories'); - - fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function (err, default_categories) { - default_categories = JSON.parse(default_categories); - - async.eachSeries(default_categories, function (category, next) { - Categories.create(category, next); - }, function (err) { - if (!err) { - next(); - } else { - winston.error('Could not set up categories'); - } - }); - }); - } else { + if (err) { + return next(err); + } + + if (Array.isArray(categoryData) && categoryData.length) { winston.info('Categories OK. Found ' + categoryData.length + ' categories.'); - next(); + return next(); } + + winston.warn('No categories found, populating instance with default categories'); + + fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function (err, default_categories) { + if (err) { + return next(err); + } + default_categories = JSON.parse(default_categories); + + async.eachSeries(default_categories, Categories.create, next); + }); }); }