Add last active date to member_devices table

This commit is contained in:
Kijin Sung 2020-10-28 01:16:23 +09:00
parent e87bd70e98
commit 5ea9d52b0c
6 changed files with 31 additions and 3 deletions

View file

@ -200,7 +200,9 @@ class member extends ModuleObject {
if(!$oDB->isIndexExists('member_nickname_log', 'idx_after_nick_name')) return true;
if(!$oDB->isIndexExists('member_nickname_log', 'idx_user_id')) return true;
// Add device token type and last active date 2020.10.28
if(!$oDB->isColumnExists('member_devices', 'device_token_type')) return true;
if(!$oDB->isColumnExists('member_devices', 'last_active_date')) return true;
$config = ModuleModel::getModuleConfig('member');
@ -374,7 +376,7 @@ class member extends ModuleObject {
$oDB->addIndex('member_nickname_log', 'idx_user_id', array('user_id'));
}
// Add device token type 2020.10.28
// Add device token type and last active date 2020.10.28
if(!$oDB->isColumnExists('member_devices', 'device_token_type'))
{
$oDB->addColumn('member_devices', 'device_token_type', 'varchar', '20', '', true, 'device_token');
@ -382,6 +384,12 @@ class member extends ModuleObject {
$oDB->query("UPDATE member_devices SET device_token_type = 'fcm' WHERE device_type = 'android' OR LENGTH(device_token) > 64");
$oDB->query("UPDATE member_devices SET device_token_type = 'apns' WHERE device_type = 'ios' AND LENGTH(device_token) = 64");
}
if(!$oDB->isColumnExists('member_devices', 'last_active_date'))
{
$oDB->addColumn('member_devices', 'last_active_date', 'date', '', '', true, 'regdate');
$oDB->addIndex('member_devices', 'idx_last_active_date', array('last_active_date'));
$oDB->query("UPDATE member_devices SET last_active_date = regdate WHERE last_active_date = ''");
}
$config = ModuleModel::getModuleConfig('member');
$changed = false;

View file

@ -82,6 +82,10 @@ class memberController extends member
return $output;
}
}
else
{
executeQuery('member.updateMemberDeviceLastActiveDate', ['device_token' => $device_token]);
}
}
if(!$config->after_login_url)
@ -116,7 +120,7 @@ class memberController extends member
// Get device information
$browserInfo = Rhymix\Framework\UA::getBrowserInfo();
$device_type = strtolower($browserInfo->os);
$device_type = escape(strtolower($browserInfo->os));
$device_version = $browserInfo->os_version;
if(!$device_model)
{
@ -252,6 +256,9 @@ class memberController extends member
$member_info = null;
}
// Update last active date
executeQuery('member.updateMemberDeviceLastActiveDate', ['device_token' => $device_token]);
$this->add('member_srl', $member_srl);
$this->add('user_id', $member_info ? $member_info->user_id : null);
$this->add('user_name', $member_info ? $member_info->user_name : null);

View file

@ -7,7 +7,7 @@
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" />
<condition operation="equal" column="device_token" var="device_token" notnull="notnull" pipe="and" />
<condition operation="equal" column="device_token" var="device_token" pipe="and" />
<condition operation="equal" column="device_key" var="device_key" pipe="and" />
</conditions>
</query>

View file

@ -14,5 +14,6 @@
<column name="device_description" var="device_description" />
<column name="ipaddress" var="ipaddress" default="ipaddress()" />
<column name="regdate" var="regdate" default="curdate()" />
<column name="last_active_date" var="last_active_date" default="curdate()" />
</columns>
</query>

View file

@ -0,0 +1,11 @@
<query id="updateMemberDeviceLastActiveDate" action="update">
<tables>
<table name="member_devices" />
</tables>
<columns>
<column name="last_active_date" default="curdate()" />
</columns>
<conditions>
<condition operation="equal" column="device_token" var="device_token" notnull="notnull" />
</conditions>
</query>

View file

@ -9,5 +9,6 @@
<column name="device_model" type="varchar" size="40" notnull="notnull" />
<column name="device_description" type="varchar" size="200" />
<column name="regdate" type="date" notnull="notnull" index="idx_regdate" />
<column name="last_active_date" type="date" notnull="notnull" index="idx_last_active_date" />
<column name="ipaddress" type="varchar" size="120" notnull="notnull" />
</table>