if ((null != wpa.getApiKey()) && (0 == wpa.getApiKey().length()) && (null != ap.getApiKey()))
{
// Delete existing API key
// (We'll allow a user to update their own API key - just not create it, see below)
CookiePojo removeMe = new CookiePojo();
removeMe.setApiKey(ap.getApiKey());
ap.setApiKey(null);
DbManager.getSocial().getCookies().remove(removeMe.toDb());
}
else if (null != wpa.getApiKey()) {
// Change or create API key
// Only admins can do this:
if (null != personIdStr) { // (this is != null iff user isn't admin)
// Check security settings
PropertiesManager pm = new PropertiesManager();
if (pm.getHarvestSecurity()) {
rp.setResponse(new ResponseObject("WP Update User",false,"You must be admin in secure mode to set an API key"));
return rp;
}
}//TESTED (admin, admin-enabled, non-admin - harvest.secure on and off)
ap.setApiKey(wpa.getApiKey());
CookiePojo cp = new CookiePojo();
cp.set_id(ap.getProfileId());
cp.setCookieId(cp.get_id());
cp.setApiKey(wpa.getApiKey());
cp.setStartDate(ap.getCreated());
cp.setProfileId(ap.getProfileId());
DbManager.getSocial().getCookies().save(cp.toDb());
}//TESTED
//else if api key is null then leave alone, assume hasn't changed
//update old entries
DbManager.getSocial().getPerson().update(new BasicDBObject("_id", pp.get_id()), pp.toDb());