function updateRemote() { global $wgUser, $wgVanillaDB; try { $db = new Database($wgVanillaDB['host'], $wgVanillaDB['user'], $wgVanillaDB['password'], $wgVanillaDB['dbname']); $oldignore = $db->ignoreErrors(true); // get vanilla user id $vid = $db->selectField('GDN_UserAuthentication', array('UserID'), array('ForeignUserKey' => $wgUser->getID())); if (!$vid) { return true; } $photo = Avatar::getAvatarURL($wgUser->getName()); $updates = array("Photo" => $photo, "Email" => $wgUser->getEmail()); if (in_array('bureaucrat', $wgUser->getGroups())) { $updates["Admin"] = 1; } else { $updates["Admin"] = 0; } $opts = array('UserID' => $vid); $db->update('GDN_User', $updates, $opts); if (self::isUserBlocked()) { $db->update('GDN_UserRole', array('RoleID = 1'), $opts); } else { if (in_array('bureaucrat', $wgUser->getGroups())) { $db->update('GDN_UserRole', array('RoleID = 16'), $opts); } else { if (in_array('sysop', $wgUser->getGroups())) { $db->update("GDN_User", array('Permissions' => 'a:14:{i:0;s:19:"Garden.SignIn.Allow";i:1;s:22:"Garden.Activity.Delete";i:2;s:25:"Vanilla.Categories.Manage";i:3;s:19:"Vanilla.Spam.Manage";s:24:"Vanilla.Discussions.View";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Discussions.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:24:"Vanilla.Discussions.Edit";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:28:"Vanilla.Discussions.Announce";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:24:"Vanilla.Discussions.Sink";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:25:"Vanilla.Discussions.Close";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:26:"Vanilla.Discussions.Delete";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:20:"Vanilla.Comments.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:21:"Vanilla.Comments.Edit";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Comments.Delete";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}}'), $opts); $db->update('GDN_UserRole', array('RoleID = 32'), $opts); } else { $db->update("GDN_User", array('Permissions' => 'a:4:{i:0;s:19:"Garden.SignIn.Allow";s:24:"Vanilla.Discussions.View";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:23:"Vanilla.Discussions.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}s:20:"Vanilla.Comments.Add";a:6:{i:0;s:1:"1";i:1;s:1:"4";i:2;s:1:"5";i:3;s:1:"7";i:4;s:1:"8";i:5;s:1:"9";}}'), $opts); $db->update('GDN_UserRole', array('RoleID = 8'), $opts); print $db->lastQuery(); } } } $db->ignoreErrors($oldignore); } catch (Exception $e) { print "oops {$e->getMessage()}\n"; } return true; }
<?php require_once 'commandLine.inc'; $db = new Database($wgVanillaDB['host'], $wgVanillaDB['user'], $wgVanillaDB['password'], $wgVanillaDB['dbname']); $oldignore = $db->ignoreErrors(true); $res = $db->select('GDN_UserAuthentication', array('UserID', 'ForeignUserKey')); $updates = array(); while ($row = $db->fetchObject($res)) { $u = User::newFromID($row->ForeignUserKey); $url = Avatar::getAvatarURL($u->getName()); $updates[$row->UserID] = $url; } foreach ($updates as $userid => $url) { echo "Updating {$userid} with avatar {$url}\n"; $db->update("GDN_User", array("Photo" => $url), array("UserID" => $userid)); }