Page MenuHomePhabricator

Merge detached Phab and mw.org identities in korma DB if Phab API shows that accounts are linked
Closed, ResolvedPublic

Description

Query for source=mw.org identities in our TechComm Metrics user DB where id == uuid.
Then query Phab API for mw.org username.
If corresponding Phab account exists, check in DB if those two identities are detached (different uuids in DB).
Merge these identities in the DB if uuids don't match.
From the "5AM in the morning and you cannot sleep" series.

Event Timeline

Aklapper triaged this task as Lowest priority.Jan 25 2017, 2:51 AM
Aklapper created this task.
Aklapper moved this task from Backlog to Ready to Go on the wikimedia.biterg.io board.
#!/bin/bash
# requires having jq installed; requires running "sortinghat init sortinghat_wm" first
PHAB_PROFILE_JSON="./foo.json"
mysql -h localhost -u user -e " USE sortinghat_wm; CREATE TABLE sync_phab_mw (phabname VARCHAR(255), phabid VARCHAR(40), phabuuid VARCHAR(40), mwname VARCHAR(255), mwid VARCHAR(40), mwuuid VARCHAR(40), randomid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY);"
mysql -h localhost -u user -e " USE sortinghat_wm; INSERT INTO sync_phab_mw (mwname, mwid, mwuuid) SELECT identities.username,identities.id, identities.uuid FROM identities WHERE identities.id = identities.uuid AND identities.source = 'wikimedia:mediawiki' AND identities.username NOT LIKE '%.%.%.%' AND identities.username NOT LIKE '%:%:%:%:%:%';"
count=1
while [ $count -lt 11000 ]
do
  mwusername=$(mysql -h localhost -u user -e " USE sortinghat_wm; SELECT mwname FROM sync_phab_mw WHERE randomid = $count;");
  mwusername=${mwusername:7}
  echo '{"names":["'$mwusername'"]}' | arc call-conduit --conduit-uri https://phabricator.wikimedia.org/ --conduit-token xxxxxxxx user.mediawikiquery > $PHAB_PROFILE_JSON
  phabusername=$(more $PHAB_PROFILE_JSON | jq -r '.response[0].userName')
  if [ "$phabusername" != "null" ]; then
    mysql -h localhost -u user -e " USE sortinghat_wm; UPDATE sync_phab_mw SET phabname = (SELECT identities.username FROM identities WHERE identities.username = '$phabusername' AND identities.source = 'wikimedia:its_1') WHERE mwname = '$mwusername'; UPDATE sync_phab_mw SET phabid = (SELECT identities.id FROM identities WHERE identities.username = '$phabusername' AND identities.source = 'wikimedia:its_1') WHERE mwname = '$mwusername'; UPDATE sync_phab_mw SET phabuuid = (SELECT identities.uuid FROM identities WHERE identities.username = '$phabusername' AND identities.source = 'wikimedia:its_1') WHERE mwname = '$mwusername';"
  fi
  count=`expr $count + 1`
  sleep 8
  rm $PHAB_PROFILE_JSON
  # echo "PHABUSERNAME: " $phabusername " /// MWUSERNAME: " $mwusername
done
# then get those items and merge them in the DB: select phabid, mwid from sync_phab_mw where phabuuid != mwuuid;

(There's billion ways to write this code differently and noone will stop anyone else from doing that.)

MariaDB [sortinghat_wm]> select mwid, phabuuid from sync_phab_mw WHERE phabuuid != mwuuid AND mwid = mwuuid;
267 rows in set
To https://github.com/Bitergia/mediawiki-identities/
   3ece33d..78d2515  master -> master