-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dependabot/npm_and_yarn/website/client/mu…
…lti-cf87d80143
- Loading branch information
Showing
757 changed files
with
6,752 additions
and
10,447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule habitica-images
updated
200 files
File renamed without changes.
115 changes: 115 additions & 0 deletions
115
migrations/archive/2024/20241119_gem_caps_hourglasses.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* eslint-disable no-console */ | ||
const MIGRATION_NAME = '20241119_gem_caps_hourglasses'; | ||
import { model as User } from '../../../website/server/models/user'; | ||
|
||
const progressCount = 1000; | ||
let count = 0; | ||
|
||
async function updateUser (user) { | ||
count += 1; | ||
if (count % progressCount === 0) console.warn(`${count} ${user._id}`); | ||
|
||
const { consecutive, customerId, dateTerminated, planId } = user.purchased.plan; | ||
const isRecurring = customerId !== 'Gift' && !dateTerminated; | ||
const updateOp = { | ||
$set: { | ||
migration: MIGRATION_NAME, | ||
'purchased.plan.consecutive.gemCapExtra': Math.max(2 * Math.ceil((consecutive.gemCapExtra + 1) / 2, 26)), | ||
}, | ||
$inc: {}, | ||
}; | ||
|
||
let hourglassBonus = 0; | ||
|
||
if (isRecurring) { | ||
await user.updateBalance( | ||
5, | ||
'admin_update_balance', | ||
'', | ||
'Subscription Reward Migration', | ||
); | ||
updateOp.$inc.balance = 5; | ||
switch (planId) { | ||
case 'basic': | ||
case 'basic_earned': | ||
case 'group_plan_auto': | ||
hourglassBonus = 2; | ||
break; | ||
case 'basic_3mo': | ||
case 'basic_6mo': | ||
case 'google_6mo': | ||
hourglassBonus = 4; | ||
break; | ||
case 'basic_12mo': | ||
hourglassBonus = 12; | ||
updateOp.$set['purchased.plan.hourglassPromoReceived'] = new Date(); | ||
break; | ||
default: | ||
hourglassBonus = 0; | ||
} | ||
|
||
if (hourglassBonus) { | ||
updateOp.$inc['purchased.plan.consecutive.trinkets'] = hourglassBonus; | ||
await user.updateHourglasses( | ||
hourglassBonus, | ||
'admin_update_balance', | ||
'', | ||
'Subscription Reward Migration', | ||
); | ||
} | ||
updateOp.$push = { | ||
notifications: { | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_subscriber_reward', | ||
title: 'Thanks for being a subscriber!', | ||
text: 'Enjoy these extra Mystic Hourglasses and Gems to celebrate our new benefits.', | ||
}, | ||
seen: false, | ||
}, | ||
}; | ||
} | ||
|
||
return await User.updateOne( | ||
{ _id: user._id }, | ||
updateOp, | ||
).exec(); | ||
} | ||
|
||
export default async function processUsers () { | ||
let query = { | ||
migration: { $ne: MIGRATION_NAME }, | ||
'purchased.plan.customerId': { $exists: true }, | ||
$or: [ | ||
{ 'purchased.plan.dateTerminated': { $exists: false } }, | ||
{ 'purchased.plan.dateTerminated': null }, | ||
{ 'purchased.plan.dateTerminated': { $gt: new Date() } }, | ||
], | ||
}; | ||
|
||
const fields = { | ||
_id: 1, | ||
purchased: 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) | ||
.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], | ||
}; | ||
} | ||
|
||
await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
/* | ||
* Award Habitoween ladder items to participants in this month's Habitoween festivities | ||
*/ | ||
/* eslint-disable no-console */ | ||
import { model as User } from '../../website/server/models/user'; | ||
|
||
const MIGRATION_NAME = '20241030_habitoween_ladder'; // Update when running in future years | ||
|
||
const progressCount = 1000; | ||
let count = 0; | ||
|
||
async function updateUser (user) { | ||
count += 1; | ||
|
||
const set = { migration: MIGRATION_NAME }; | ||
const inc = { | ||
'items.food.Candy_Skeleton': 1, | ||
'items.food.Candy_Base': 1, | ||
'items.food.Candy_CottonCandyBlue': 1, | ||
'items.food.Candy_CottonCandyPink': 1, | ||
'items.food.Candy_Shade': 1, | ||
'items.food.Candy_White': 1, | ||
'items.food.Candy_Golden': 1, | ||
'items.food.Candy_Zombie': 1, | ||
'items.food.Candy_Desert': 1, | ||
'items.food.Candy_Red': 1, | ||
}; | ||
const push = { notifications: { $each: [] } }; | ||
|
||
if (user && user.items && user.items.mounts && user.items.mounts['JackOLantern-RoyalPurple']) { | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_candy', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.pets && user.items.pets['JackOLantern-RoyalPurple']) { | ||
set['items.mounts.JackOLantern-RoyalPurple'] = true; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_purple_mount', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Royal Purple Jack-O-Lantern Mount and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.mounts && user.items.mounts['JackOLantern-Glow']) { | ||
set['items.pets.JackOLantern-RoyalPurple'] = 5; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_purple_pet', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Royal Purple Jack-O-Lantern Pet and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.pets && user.items.pets['JackOLantern-Glow']) { | ||
set['items.mounts.JackOLantern-Glow'] = true; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_glow_mount', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Glow-in-the-Dark Jack-O-Lantern Mount and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.mounts && user.items.mounts['JackOLantern-Ghost']) { | ||
set['items.pets.JackOLantern-Glow'] = 5; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_glow_pet', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Glow-in-the-Dark Jack-O-Lantern Pet and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.pets && user.items.pets['JackOLantern-Ghost']) { | ||
set['items.mounts.JackOLantern-Ghost'] = true; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_ghost_mount', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Ghost Jack-O-Lantern Mount and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.mounts && user.items.mounts['JackOLantern-Base']) { | ||
set['items.pets.JackOLantern-Ghost'] = 5; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_ghost_pet', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Ghost Jack-O-Lantern Pet and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else if (user && user.items && user.items.pets && user.items.pets['JackOLantern-Base']) { | ||
set['items.mounts.JackOLantern-Base'] = true; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_base_mount', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Jack-O-Lantern Mount and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} else { | ||
set['items.pets.JackOLantern-Base'] = 5; | ||
push.notifications.$each.push({ | ||
type: 'ITEM_RECEIVED', | ||
data: { | ||
icon: 'notif_habitoween_base_pet', | ||
title: 'Happy Habitoween!', | ||
text: 'For this spooky celebration, you\'ve received a Jack-O-Lantern Pet and an assortment of candy for your Pets!', | ||
destination: '/inventory/stable', | ||
}, | ||
seen: false, | ||
}); | ||
} | ||
|
||
if (count % progressCount === 0) console.warn(`${count} ${user._id}`); | ||
return User.updateOne({ _id: user._id }, { $inc: inc, $push: push, $set: set }).exec(); | ||
} | ||
|
||
export default async function processUsers () { | ||
const query = { | ||
migration: { $ne: MIGRATION_NAME }, | ||
'auth.timestamps.loggedin': { $gt: new Date('2024-10-01') }, | ||
}; | ||
|
||
const fields = { | ||
_id: 1, | ||
items: 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], | ||
}; | ||
} | ||
|
||
await Promise.all(users.map(updateUser)); // eslint-disable-line no-await-in-loop | ||
} | ||
} |
Oops, something went wrong.