2016-08-22 06:27:02 -07:00
// Update courses
2015-08-29 07:15:35 -07:00
// Usage:
// mongo <address>:<port>/<database> <script file> -u <username> -p <password>
2016-07-22 16:37:53 -07:00
// eg: mongo localhost:27017/coco scripts/mongodb/updateCourses.js
2015-08-29 07:15:35 -07:00
2016-08-22 06:27:02 -07:00
// NOTE: Do not use this to create new courses
// TODO: Replace this script with the course editor
2016-08-16 09:24:34 -07:00
load ( 'bower_components/lodash/dist/lodash.js' ) ;
2015-08-29 07:15:35 -07:00
2015-09-10 10:37:32 -07:00
var courses =
2015-08-29 07:15:35 -07:00
[
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '560f1a9f22961295f9427742' ) ,
2015-08-29 07:15:35 -07:00
name : "Introduction to Computer Science" ,
slug : "introduction-to-computer-science" ,
campaignID : ObjectId ( "55b29efd1cd6abe8ce07db0d" ) ,
description : "Learn basic syntax, while loops, and the CodeCombat environment." ,
2015-09-10 10:37:32 -07:00
duration : NumberInt ( 1 ) ,
2015-11-14 06:36:58 -08:00
free : true ,
2016-07-22 16:37:53 -07:00
screenshot : "/images/pages/courses/101_info.png" ,
releasePhase : 'released'
2015-09-03 11:04:40 -07:00
} ,
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '5632661322961295f9428638' ) ,
2015-09-03 11:04:40 -07:00
name : "Computer Science 2" ,
slug : "computer-science-2" ,
2015-10-29 11:26:34 -07:00
campaignID : ObjectId ( "562f88e84df18473073c74e2" ) ,
2016-08-18 13:29:52 -07:00
description : "Introduces arguments, variables, if statements, and arithmetic." ,
2015-09-10 10:37:32 -07:00
duration : NumberInt ( 5 ) ,
2015-11-14 06:36:58 -08:00
free : false ,
2016-07-22 16:37:53 -07:00
screenshot : "/images/pages/courses/102_info.png" ,
releasePhase : 'released'
2015-09-03 11:04:40 -07:00
} ,
2016-08-18 09:57:06 -07:00
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '5789587aad86a6efb573701e' ) ,
2016-08-18 09:57:06 -07:00
name : "Game Development 1" ,
2016-08-19 15:46:48 -07:00
slug : "game-development-1" ,
2016-08-18 09:57:06 -07:00
campaignID : ObjectId ( "5789236960deed1f00ec2ab8" ) ,
description : "Learn to create your own games which you can share with your friends." ,
duration : NumberInt ( 1 ) ,
free : false ,
releasePhase : 'released'
} ,
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '5789587aad86a6efb573701f' ) ,
2016-08-18 09:57:06 -07:00
name : "Web Development 1" ,
2016-08-19 15:46:48 -07:00
slug : "web-development-1" ,
2016-08-18 09:57:06 -07:00
campaignID : ObjectId ( "578913f2c8871ac2326fa3e4" ) ,
description : "Learn the basics of web development in this introductory HTML & CSS course." ,
duration : NumberInt ( 1 ) ,
free : false ,
releasePhase : 'released'
} ,
2015-09-03 11:04:40 -07:00
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '56462f935afde0c6fd30fc8c' ) ,
2015-09-03 11:04:40 -07:00
name : "Computer Science 3" ,
slug : "computer-science-3" ,
2015-11-13 10:51:56 -08:00
campaignID : ObjectId ( "56462ac4410c528505e1160a" ) ,
description : "Introduces arithmetic, counters, advanced while loops, break, continue, arrays." ,
2015-09-10 10:37:32 -07:00
duration : NumberInt ( 5 ) ,
2015-11-14 06:36:58 -08:00
free : false ,
2016-07-22 16:37:53 -07:00
screenshot : "/images/pages/courses/103_info.png" ,
releasePhase : 'released'
2015-11-13 10:51:56 -08:00
} ,
2016-08-18 09:57:06 -07:00
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '57b621e7ad86a6efb5737e64' ) ,
2016-08-18 09:57:06 -07:00
name : "Game Development 2" ,
2016-08-19 15:46:48 -07:00
slug : "game-development-2" ,
2016-08-18 09:57:06 -07:00
campaignID : ObjectId ( "57b49c866430272000100c4d" ) ,
description : "Learn more advanced game development." ,
duration : NumberInt ( 2 ) ,
free : false ,
2016-08-19 16:48:04 -07:00
releasePhase : 'released'
2016-08-18 09:57:06 -07:00
} ,
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '5789587aad86a6efb5737020' ) ,
2016-08-18 09:57:06 -07:00
name : "Web Development 2" ,
2016-08-19 15:46:48 -07:00
slug : "web-development-2" ,
2016-08-18 09:57:06 -07:00
campaignID : ObjectId ( "57891570c8871ac2326fa3f8" ) ,
description : "Learn more advanced web development, including scripting to make interactive webpages." ,
duration : NumberInt ( 2 ) ,
free : false ,
2016-08-19 16:48:04 -07:00
releasePhase : 'released'
2016-08-18 09:57:06 -07:00
} ,
2015-11-13 10:51:56 -08:00
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '56462f935afde0c6fd30fc8d' ) ,
2015-11-13 10:51:56 -08:00
name : "Computer Science 4" ,
slug : "computer-science-4" ,
campaignID : ObjectId ( "56462c1133f1478605ebd018" ) ,
description : "Introduces object literals, for loops, function definitions, drawing, and modulo." ,
duration : NumberInt ( 5 ) ,
2015-11-14 06:36:58 -08:00
free : false ,
2016-07-22 16:37:53 -07:00
screenshot : "/images/pages/courses/104_info.png" ,
releasePhase : 'released'
2016-01-15 09:46:24 -08:00
} ,
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '569ed916efa72b0ced971447' ) ,
2016-01-15 09:46:24 -08:00
name : "Computer Science 5" ,
slug : "computer-science-5" ,
campaignID : ObjectId ( "568ad069a6584820004437f2" ) ,
description : "Introduces function parameters, function return values and algorithms." ,
duration : NumberInt ( 5 ) ,
free : false ,
2016-07-22 16:37:53 -07:00
screenshot : "/images/pages/courses/105_info.png" ,
releasePhase : 'released'
2016-07-15 14:47:32 -07:00
} ,
2016-08-02 11:08:46 -07:00
{
2016-08-22 06:27:02 -07:00
_id : ObjectId ( '57a0dea5ad86a6efb57375c2' ) ,
2016-08-02 11:08:46 -07:00
name : "JS Primer" ,
slug : "js-primer" ,
campaignID : ObjectId ( "579a5f37843ad12000e6d4c7" ) ,
description : "Learn JavaScript after you already know another programming language like Python." ,
duration : NumberInt ( 1 ) ,
2016-07-15 14:47:32 -07:00
free : false ,
2016-07-22 16:37:53 -07:00
releasePhase : 'beta'
2015-08-29 07:15:35 -07:00
}
] ;
2016-08-16 09:24:34 -07:00
_ . forEach ( courses , function ( course ) {
// Find course concepts
2015-09-10 10:56:01 -07:00
var concepts = { } ;
2016-08-16 09:24:34 -07:00
var cursor = db . campaigns . find ( { _id : course . campaignID } , { 'levels' : 1 } ) ;
2015-09-10 10:56:01 -07:00
if ( cursor . hasNext ( ) ) {
var doc = cursor . next ( ) ;
for ( var levelID in doc . levels ) {
2016-07-15 14:47:32 -07:00
for ( var j = 0 ; j < ( doc . levels [ levelID ] . concepts || [ ] ) . length ; j ++ ) {
2015-09-10 10:56:01 -07:00
concepts [ doc . levels [ levelID ] . concepts [ j ] ] = true ;
}
}
}
2016-08-16 09:24:34 -07:00
course . concepts = Object . keys ( concepts ) ;
} ) ;
2015-09-10 10:56:01 -07:00
print ( "Updating courses.." ) ;
2015-09-10 10:37:32 -07:00
for ( var i = 0 ; i < courses . length ; i ++ ) {
2016-08-22 06:27:02 -07:00
var result = db . courses . update ( { _id : courses [ i ] . _id } , { $set : courses [ i ] } ) ;
2016-08-18 16:52:45 -07:00
if ( result . nMatched !== 1 ) {
print ( "Failed to update " + courses [ i ] . slug ) ;
print ( JSON . stringify ( result , null , 2 ) ) ;
}
2015-08-29 07:15:35 -07:00
}
2015-09-10 10:56:01 -07:00
2016-08-16 09:24:34 -07:00
print ( "Upserting i18n" , db . courses . update (
{ i18n : { $exists : false } } ,
{ $set : { i18n : { '-' : { '-' : '-' } } , i18nCoverage : [ ] } } ,
{ multi : true }
) ) ;
2015-09-10 10:56:01 -07:00
print ( "Done." ) ;