修复因为数据库索引导致签到功能异常的问题

master
落雨楓 2 years ago
parent e7ce4d04c9
commit d39a4861c4

@ -24,6 +24,8 @@ class Hooks {
}
public static function onBeforePageDisplay(OutputPage $out, Skin $skin) {
$user = $out->getUser();
$config = MediaWikiServices::getInstance()->getMainConfig();
$out->addModuleStyles(['ext.isekai.userpoints.base']);

@ -1,6 +1,7 @@
<?php
namespace Isekai\UserPoints\Service;
use Isekai\UserPoints\Utils;
use User;
use stdClass;
use MediaWiki\MediaWikiServices;
@ -376,6 +377,13 @@ class IsekaiUserPoints {
return true;
}
public function getPointInfo() {
return [
'name' => Utils::getPointName($this->type),
'icon' => Utils::getPointIcon($this->type),
];
}
/**
* Save point data
*/

@ -1,43 +1,45 @@
$(function() {
const storeKey = 'isekai-userpoints-dailysign-lastSignDate';
const lastSignDate = localStorage.getItem(storeKey);
const today = new Date().toLocaleDateString();
if (lastSignDate !== today) {
let mwApi = new mw.Api();
mwApi.postWithToken('csrf', {
action: 'userdailysign',
}).done(function(data) {
if (data.userdailysign && data.userdailysign.success) {
if (Array.isArray(data.userdailysign.point_delta)) {
const pointDelta = data.userdailysign.point_delta;
let pointMsgList = [];
pointDelta.forEach(function (pointDeltaInfo) {
let msg = mw.msg('isekai-userpoints-point-name-num', pointDeltaInfo.name, pointDeltaInfo.icon, pointDeltaInfo.points);
pointMsgList.push(msg);
});
let separator = mw.msg('comma-separator');
let pointMsg = pointMsgList.join(separator);
if (!mw.user.isAnon()) {
const storeKey = 'isekai-userpoints-dailysign-lastSignDate';
const lastSignDate = localStorage.getItem(storeKey);
const today = new Date().toLocaleDateString();
if (lastSignDate !== today) {
let mwApi = new mw.Api();
mwApi.postWithToken('csrf', {
action: 'userdailysign',
}).done(function(data) {
if (data.userdailysign && data.userdailysign.success) {
if (Array.isArray(data.userdailysign.point_delta)) {
const pointDelta = data.userdailysign.point_delta;
let pointMsgList = [];
pointDelta.forEach(function (pointDeltaInfo) {
let msg = mw.msg('isekai-userpoints-point-name-num', pointDeltaInfo.name, pointDeltaInfo.icon, pointDeltaInfo.points);
pointMsgList.push(msg);
});
let separator = mw.msg('comma-separator');
let pointMsg = pointMsgList.join(separator);
let notificationMsg = mw.msg('isekai-userpoints-dailysign-notify-success', pointMsg);
mw.notify('', {
title: mw.msg('isekai-userpoints-dailysign-notify-title'),
tag: 'isekai-userpoints-dailysign',
id: 'isekai-userpoints-dailysign-notify',
});
let notificationMsg = mw.msg('isekai-userpoints-dailysign-notify-success', pointMsg);
mw.notify('', {
title: mw.msg('isekai-userpoints-dailysign-notify-title'),
tag: 'isekai-userpoints-dailysign',
id: 'isekai-userpoints-dailysign-notify',
});
function changeNotifyContent() {
let notifyDom = document.querySelector('#isekai-userpoints-dailysign-notify');
if (notifyDom) {
notifyDom.querySelector('.mw-notification-content').innerHTML = notificationMsg;
} else {
requestAnimationFrame(changeNotifyContent);
function changeNotifyContent() {
let notifyDom = document.querySelector('#isekai-userpoints-dailysign-notify');
if (notifyDom) {
notifyDom.querySelector('.mw-notification-content').innerHTML = notificationMsg;
} else {
requestAnimationFrame(changeNotifyContent);
}
}
}
changeNotifyContent();
changeNotifyContent();
}
localStorage.setItem(storeKey, today);
}
localStorage.setItem(storeKey, today);
}
});
});
}
}
});

@ -4,7 +4,7 @@ CREATE TABLE /*_*/isekai_user_daily_sign_log (
`month` INT UNSIGNED NOT NULL,
`sign_log` LONGTEXT NOT NULL
) /*$wgDBTableOptions*/;
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD PRIMARY KEY (`user_id`);
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`user_id`, `year`, `month`);
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD PRIMARY KEY (`user_id`, `year`, `month`);
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`user_id`);
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`year`);
ALTER TABLE /*_*/isekai_user_daily_sign_log ADD INDEX(`month`);

@ -4,7 +4,7 @@ CREATE TABLE isekai_user_daily_sign_log (
month INT NOT NULL,
sign_log JSON NOT NULL
);
ALTER TABLE isekai_user_daily_sign_log ADD PRIMARY KEY (user_id);
ALTER TABLE isekai_user_daily_sign_log ADD INDEX(user_id, year, month);
ALTER TABLE isekai_user_daily_sign_log ADD PRIMARY KEY (user_id, year, month);
ALTER TABLE isekai_user_daily_sign_log ADD INDEX(user_id);
ALTER TABLE isekai_user_daily_sign_log ADD INDEX(year);
ALTER TABLE isekai_user_daily_sign_log ADD INDEX(month);
Loading…
Cancel
Save