added error checking to install.js for categories

v1.18.x
barisusakli 11 years ago
parent 5ea74ae9e9
commit 586aeaf53f

@ -275,7 +275,7 @@ var db = require('./database'),
return callback(err);
}
if (!Array.isArray(categories)) {
if (!Array.isArray(categories) || !categories.length) {
return callback(null, []);
}

@ -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);
});
});
}

Loading…
Cancel
Save