Skip to content

Commit

Permalink
Merge branch 'release' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreCat committed Nov 28, 2018
2 parents bf7fabb + fde4402 commit b826608
Show file tree
Hide file tree
Showing 149 changed files with 5,573 additions and 5,295 deletions.
110 changes: 110 additions & 0 deletions migrations/archive/mystery-items-old.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import monk from 'monk';
import nconf from 'nconf';

const migrationName = 'mystery-items-201808.js'; // Update per month
const authorName = 'Sabe'; // in case script author needs to know when their ...
const authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done

/*
* Award this month's mystery items to subscribers
*/
const MYSTERY_ITEMS = ['armor_mystery_201810', 'head_mystery_201810'];
const CONNECTION_STRING = nconf.get('MIGRATION_CONNECT_STRING');

let dbUsers = monk(CONNECTION_STRING).get('users', { castIds: false });
let UserNotification = require('../../website/server/models/userNotification').model;

function processUsers (lastId) {
// specify a query to limit the affected users (empty for all users):
let query = {
migration: {$ne: migrationName},
'purchased.plan.customerId': { $ne: null },
$or: [
{ 'purchased.plan.dateTerminated': { $gte: new Date() } },
{ 'purchased.plan.dateTerminated': { $exists: false } },
{ 'purchased.plan.dateTerminated': { $eq: null } },
],
};

if (lastId) {
query._id = {
$gt: lastId,
};
}

dbUsers.find(query, {
sort: {_id: 1},
limit: 250,
fields: [
], // specify fields we are interested in to limit retrieved data (empty if we're not reading data):
})
.then(updateUsers)
.catch((err) => {
console.log(err);
return exiting(1, `ERROR! ${ err}`);
});
}

let progressCount = 1000;
let count = 0;

function updateUsers (users) {
if (!users || users.length === 0) {
console.warn('All appropriate users found and modified.');
displayData();
return;
}

let userPromises = users.map(updateUser);
let lastUser = users[users.length - 1];

return Promise.all(userPromises)
.then(() => {
processUsers(lastUser._id);
});
}

function updateUser (user) {
count++;

const addToSet = {
'purchased.plan.mysteryItems': {
$each: MYSTERY_ITEMS,
},
};
const push = {
notifications: (new UserNotification({
type: 'NEW_MYSTERY_ITEMS',
data: {
MYSTERY_ITEMS,
},
})).toJSON(),
};

dbUsers.update({_id: user._id}, {$addToSet: addToSet, $push: push});

if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
if (user._id === authorUuid) console.warn(`${authorName } processed`);
}

function displayData () {
console.warn(`\n${ count } users processed\n`);
return exiting(0);
}

function exiting (code, msg) {
code = code || 0; // 0 = success
if (code && !msg) {
msg = 'ERROR!';
}
if (msg) {
if (code) {
console.error(msg);
} else {
console.log(msg);
}
}
process.exit(code);
}

module.exports = processUsers;
131 changes: 46 additions & 85 deletions migrations/users/mystery-items.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,13 @@
import monk from 'monk';
import nconf from 'nconf';
/* eslint-disable no-console */
const MIGRATION_NAME = 'mystery_items_201811';
const MYSTERY_ITEMS = ['head_mystery_201811', 'weapon_mystery_201811'];
import { model as User } from '../../website/server/models/user';
import { model as UserNotification } from '../../website/server/models/userNotification';

const migrationName = 'mystery-items-201808.js'; // Update per month
const authorName = 'Sabe'; // in case script author needs to know when their ...
const authorUuid = '7f14ed62-5408-4e1b-be83-ada62d504931'; // ... own data is done

/*
* Award this month's mystery items to subscribers
*/
const MYSTERY_ITEMS = ['armor_mystery_201810', 'head_mystery_201810'];
const CONNECTION_STRING = nconf.get('MIGRATION_CONNECT_STRING');

let dbUsers = monk(CONNECTION_STRING).get('users', { castIds: false });
let UserNotification = require('../../website/server/models/userNotification').model;

function processUsers (lastId) {
// specify a query to limit the affected users (empty for all users):
let query = {
migration: {$ne: migrationName},
'purchased.plan.customerId': { $ne: null },
$or: [
{ 'purchased.plan.dateTerminated': { $gte: new Date() } },
{ 'purchased.plan.dateTerminated': { $exists: false } },
{ 'purchased.plan.dateTerminated': { $eq: null } },
],
};

if (lastId) {
query._id = {
$gt: lastId,
};
}

dbUsers.find(query, {
sort: {_id: 1},
limit: 250,
fields: [
], // specify fields we are interested in to limit retrieved data (empty if we're not reading data):
})
.then(updateUsers)
.catch((err) => {
console.log(err);
return exiting(1, `ERROR! ${ err}`);
});
}

let progressCount = 1000;
const progressCount = 1000;
let count = 0;

function updateUsers (users) {
if (!users || users.length === 0) {
console.warn('All appropriate users found and modified.');
displayData();
return;
}

let userPromises = users.map(updateUser);
let lastUser = users[users.length - 1];

return Promise.all(userPromises)
.then(() => {
processUsers(lastUser._id);
});
}

function updateUser (user) {
async function updateUser (user) {
count++;

const addToSet = {
Expand All @@ -80,31 +23,49 @@ function updateUser (user) {
},
})).toJSON(),
};
const set = {
migration: MIGRATION_NAME,
};

dbUsers.update({_id: user._id}, {$addToSet: addToSet, $push: push});
if (count % progressCount === 0) console.warn(`${count} ${user._id}`);

if (count % progressCount === 0) console.warn(`${count } ${ user._id}`);
if (user._id === authorUuid) console.warn(`${authorName } processed`);
return await User.update({_id: user._id}, {$set: set, $push: push, $addToSet: addToSet}).exec();
}

function displayData () {
console.warn(`\n${ count } users processed\n`);
return exiting(0);
}
module.exports = async function processUsers () {
let query = {
migration: {$ne: MIGRATION_NAME},
'purchased.plan.customerId': { $ne: null },
$or: [
{ 'purchased.plan.dateTerminated': { $gte: new Date() } },
{ 'purchased.plan.dateTerminated': { $exists: false } },
{ 'purchased.plan.dateTerminated': { $eq: null } },
],
};

function exiting (code, msg) {
code = code || 0; // 0 = success
if (code && !msg) {
msg = 'ERROR!';
}
if (msg) {
if (code) {
console.error(msg);
} else {
console.log(msg);
const fields = {
_id: 1,
};

while (true) { // eslint-disable-line no-constant-condition
const users = await User // eslint-disable-line no-await-in-loop
.find(query)
.limit(250)
.sort({_id: 1})
.select(fields)
.lean()
.exec();

if (users.length === 0) {
console.warn('All appropriate users found and modified.');
console.warn(`\n${count} users processed\n`);
break;
} else {
query._id = {
$gt: users[users.length - 1],
};
}
}
process.exit(code);
}

module.exports = processUsers;
await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop
}
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "habitica",
"description": "A habit tracker app which treats your goals like a Role Playing Game.",
"version": "4.73.2",
"version": "4.74.0",
"main": "./website/server/index.js",
"dependencies": {
"@slack/client": "^3.8.1",
Expand Down
24 changes: 15 additions & 9 deletions website/client/assets/css/sprites/spritesmith-largeSprites-0.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.achievement-costumeContest6x {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -1136px -169px;
background-position: -1136px -148px;
width: 144px;
height: 156px;
}
Expand All @@ -18,7 +18,7 @@
}
.promo_armoire_backgrounds_201811 {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -481px -568px;
background-position: -481px -420px;
width: 423px;
height: 147px;
}
Expand All @@ -34,21 +34,27 @@
width: 375px;
height: 361px;
}
.promo_mystery_201810 {
.promo_mystery_201811 {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -1136px 0px;
width: 294px;
height: 168px;
background-position: -839px -723px;
width: 282px;
height: 147px;
}
.promo_oddballs_bundle {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -481px -420px;
background-position: -481px -568px;
width: 423px;
height: 147px;
}
.promo_piyo {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -1136px 0px;
width: 279px;
height: 147px;
}
.promo_take_this {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -1281px -169px;
background-position: -1281px -148px;
width: 96px;
height: 69px;
}
Expand Down Expand Up @@ -78,7 +84,7 @@
}
.scene_veteran_pets {
background-image: url('~assets/images/sprites/spritesmith-largeSprites-0.png');
background-position: -1136px -326px;
background-position: -1136px -305px;
width: 242px;
height: 62px;
}
Loading

0 comments on commit b826608

Please sign in to comment.