2016-09-04 22:39:12 +02:00
|
|
|
import mongoose from 'mongoose';
|
|
|
|
const ObjectId = mongoose.Types.ObjectId;
|
|
|
|
mongoose.connect('mongodb://localhost:27017/p5js-web-editor');
|
|
|
|
mongoose.connection.on('error', () => {
|
|
|
|
console.error('MongoDB Connection Error. Please make sure that MongoDB is running.');
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
import Project from '../models/project';
|
2016-10-01 20:01:32 +02:00
|
|
|
import User from '../models/user';
|
2016-09-04 22:39:12 +02:00
|
|
|
|
2016-09-09 04:02:42 +02:00
|
|
|
// let projectsNotToUpdate;
|
|
|
|
// Project.find({'files.name': 'root'})
|
|
|
|
// .exec((err, projects) => {
|
|
|
|
// projectsNotToUpdate = projects.map(project => project.id);
|
|
|
|
// console.log(projectsNotToUpdate);
|
2016-09-04 22:39:12 +02:00
|
|
|
|
2016-09-09 04:02:42 +02:00
|
|
|
// Project.find({})
|
|
|
|
// .exec((err, projects) => {
|
|
|
|
// projects.forEach( (project, projectIndex) => {
|
|
|
|
// if (!projectsNotToUpdate.find(projectId => projectId === project.id)) {
|
|
|
|
// const childIdArray = project.files.map(file => file._id.valueOf());
|
|
|
|
// const newId = new ObjectId();
|
|
|
|
// project.files.push({
|
|
|
|
// name: 'root',
|
|
|
|
// _id: newId,
|
|
|
|
// id: newId,
|
|
|
|
// fileType: 'folder',
|
|
|
|
// children: childIdArray,
|
|
|
|
// content: ''
|
|
|
|
// });
|
2016-09-04 22:39:12 +02:00
|
|
|
|
2016-09-09 04:02:42 +02:00
|
|
|
// project.files = project.files.map(file => {
|
|
|
|
// if (file.name === "sketch.js") {
|
|
|
|
// file.isSelected = true;
|
|
|
|
// return file;
|
|
|
|
// }
|
|
|
|
// return file;
|
|
|
|
// });
|
|
|
|
// project.save((err, savedProject) => {
|
|
|
|
// console.log('project', projectIndex, 'is saved.');
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
2016-09-04 22:39:12 +02:00
|
|
|
|
|
|
|
// Project.find({'files.name': 'root'})
|
|
|
|
// .exec((err, projects) => {
|
|
|
|
// projects.forEach((project, projectIndex) => {
|
|
|
|
// project.files = project.files.map(file => {
|
|
|
|
// if (file.name === "sketch.js") {
|
|
|
|
// file.isSelected = true;
|
|
|
|
// return file;
|
|
|
|
// } else if (file.name === "root") {
|
|
|
|
// file.content = '';
|
|
|
|
// return file;
|
|
|
|
// }
|
|
|
|
// return file;
|
|
|
|
// });
|
|
|
|
|
|
|
|
// project.save((err, savedProject) => {
|
|
|
|
// console.log('project', projectIndex, 'is saved.');
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
2016-09-14 21:57:52 +02:00
|
|
|
// const s3Bucket = `http://p5.js-webeditor.s3.amazonaws.com/`;
|
|
|
|
// const s3BucketHttps = `https://s3-us-west-2.amazonaws.com/p5.js-webeditor/`;
|
|
|
|
|
|
|
|
// Project.find({})
|
|
|
|
// .exec((err, projects) => {
|
|
|
|
// projects.forEach((project, projectIndex) => {
|
|
|
|
// project.files.forEach((file) => {
|
|
|
|
// if (file.url) {
|
|
|
|
// file.url = file.url.replace(s3Bucket, s3BucketHttps);
|
|
|
|
// console.log('Updating', file.name);
|
|
|
|
// console.log(file.url);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// project.save((err, savedProject) => {
|
|
|
|
// console.log('project', projectIndex, 'is saved.');
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
2016-09-09 04:02:42 +02:00
|
|
|
|
2016-10-01 20:01:32 +02:00
|
|
|
// Project.find({})
|
|
|
|
// .exec((err, projects) => {
|
|
|
|
// projects.forEach((project, projectIndex) => {
|
|
|
|
// project.files.forEach((file) => {
|
|
|
|
// if (file.isSelected) {
|
|
|
|
// delete file.isSelected;
|
|
|
|
// }
|
2016-09-14 22:20:25 +02:00
|
|
|
|
2016-10-01 20:01:32 +02:00
|
|
|
// if (file.name === 'sketch.js') {
|
|
|
|
// file.isSelectedFile = true;
|
|
|
|
// console.log(file.name, 'is now selected');
|
|
|
|
// // file.save((err, savedFile) => {
|
|
|
|
// // console.log('file saved');
|
|
|
|
// // });
|
|
|
|
// } else {
|
|
|
|
// file.isSelectedFile = false;
|
|
|
|
// }
|
|
|
|
// // console.log('project', projectIndex);
|
|
|
|
// // if (file.isSelected) {
|
|
|
|
// // console.log('is selected remains');
|
|
|
|
// // }
|
2016-09-14 22:33:47 +02:00
|
|
|
|
2016-10-01 20:01:32 +02:00
|
|
|
// // if (file.isSelctedFile) {
|
|
|
|
// // console.log('changed to isSelected file');
|
|
|
|
// // }
|
|
|
|
// project.save((err, savedProject) => {
|
|
|
|
// console.log('project', projectIndex, 'is saved.');
|
|
|
|
// });
|
|
|
|
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
2016-09-14 22:33:47 +02:00
|
|
|
|
2016-10-04 21:35:23 +02:00
|
|
|
// User.findOne({email: 'test@test.com'})
|
|
|
|
// .exec((err, user) => {
|
|
|
|
// console.log(user);
|
|
|
|
// user.password = '1234';
|
|
|
|
// user.save((err, savedUser) => {
|
|
|
|
// console.log('user saved');
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
|
|
|
|
User.find({})
|
|
|
|
.exec((err, users) => {
|
|
|
|
users.forEach(user => {
|
|
|
|
user.preferences.autorefresh = false;
|
|
|
|
user.save((err, savedUser) => {
|
|
|
|
console.log('user saved');
|
|
|
|
});
|
2016-09-09 04:02:42 +02:00
|
|
|
});
|
2016-11-17 17:15:35 +01:00
|
|
|
});
|