Pgehres has uploaded a new change for review.
https://gerrit.wikimedia.org/r/61801
Change subject: Adding aa_method field to track login method.
......................................................................
Adding aa_method field to track login method.
Change-Id: I823c873da8670ee158eee0b00759e2df8d5ef5b2
---
M AccountAudit.body.php
M AccountAudit.hooks.php
M accountaudit.sql
3 files changed, 26 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AccountAudit
refs/changes/01/61801/1
diff --git a/AccountAudit.body.php b/AccountAudit.body.php
index 4fe05b6..b15c1db 100644
--- a/AccountAudit.body.php
+++ b/AccountAudit.body.php
@@ -2,6 +2,9 @@
class AccountAudit {
+ const ACCESS_METHOD_DEFAULT = 0;
+ const ACCESS_METHOD_MOBILE = 1;
+
/**
* Updates the aa_lastlogin value for the specified user
*
@@ -19,12 +22,18 @@
$db = wfGetDB( DB_MASTER );
$method = __METHOD__;
- $db->onTransactionIdle( function() use ( $user, $now, $db,
$method ) {
+ $requestMethod = self::ACCESS_METHOD_DEFAULT;
+ if ( MobileContext::singleton()->shouldDisplayMobileView() ) {
+ $requestMethod = self::ACCESS_METHOD_MOBILE;
+ }
+
+ $db->onTransactionIdle( function() use ( $user, $requestMethod,
$now, $db, $method ) {
if ( $db->getType() === 'mysql' ) { // MySQL-specific
implementation
$db->query(
"INSERT INTO " . $db->tableName(
'accountaudit_login' ) .
- "( aa_user, aa_lastlogin )
VALUES (" .
+ "( aa_user, aa_method,
aa_lastlogin ) VALUES (" .
$db->addQuotes( $user->getId()
) . ", " .
+ $db->addQuotes( $requestMethod
) . ", " .
$db->addQuotes( $db->timestamp(
$now ) ) .
") ON DUPLICATE KEY UPDATE
aa_lastlogin = " .
$db->addQuotes( $db->timestamp(
$now ) ),
@@ -34,13 +43,17 @@
$db->update(
'accountaudit_login',
array( 'aa_lastlogin' =>
$db->timestamp( $now ) ),
- array( 'aa_user' => $user->getId() ),
+ array( 'aa_user' => $user->getId(),
'aa_method' => $requestMethod ),
$method
);
- if ( $db->affectedRows() == 0 ) { // no row
existed for that user
+ if ( $db->affectedRows() == 0 ) { // no row
existed for that user, method
$db->insert(
'accountaudit_login',
- array( 'aa_user' =>
$user->getId(), 'aa_lastlogin' => $db->timestamp( $now ) ),
+ array(
+ 'aa_user' =>
$user->getId(),
+ 'aa_method' =>
$requestMethod,
+ 'aa_lastlogin' =>
$db->timestamp( $now )
+ ),
$method,
array( 'IGNORE', )
);
diff --git a/AccountAudit.hooks.php b/AccountAudit.hooks.php
index 8867a60..a625e9c 100644
--- a/AccountAudit.hooks.php
+++ b/AccountAudit.hooks.php
@@ -31,8 +31,9 @@
* @return bool
*/
static function loadExtensionSchemaUpdates( DatabaseUpdater $updater ) {
- $updater->addExtensionTable( 'accountaudit_login',
- __DIR__ . '/accountaudit.sql', true );
+ $updater->addExtensionTable( 'accountaudit_login', __DIR__ .
'/accountaudit.sql' );
+ $updater->addExtensionField( 'accountaudit_login', 'aa_method',
+ __DIR__ . '/patches/add_method.sql' );
return true;
}
}
\ No newline at end of file
diff --git a/accountaudit.sql b/accountaudit.sql
index f228ffc..f36c1de 100644
--- a/accountaudit.sql
+++ b/accountaudit.sql
@@ -4,10 +4,13 @@
--
CREATE TABLE /*$wgDBprefix*/accountaudit_login (
-- Key to user_id
- aa_user int unsigned NOT NULL PRIMARY KEY,
+ aa_user int unsigned NOT NULL,
+ aa_method tinyint unsigned NOT NULL DEFAULT 0,
-- This is a timestamp which is updated when a user logs in
aa_lastlogin varbinary(14) default null
) /*$wgDBTableOptions*/;
-CREATE INDEX /*i*/aa_lastlogin ON /*_*/accountaudit_login (aa_lastlogin);
\ No newline at end of file
+CREATE UNIQUE INDEX /*i*/aa_user ON /*_*/accountaudit_login (aa_user,
aa_method);
+CREATE INDEX /*i*/aa_method ON /*_*/accountaudit_login (aa_method, aa_user);
+CREATE INDEX /*i*/aa_lastlogin ON /*_*/accountaudit_login (aa_lastlogin);
--
To view, visit https://gerrit.wikimedia.org/r/61801
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I823c873da8670ee158eee0b00759e2df8d5ef5b2
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AccountAudit
Gerrit-Branch: master
Gerrit-Owner: Pgehres <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits