Updating user info in liferay database -


i need update info of existing user in database programmaticaly need update user name birth date values in user_ table in liferay database need run update query.

it not recommended update liferay database directly, should use liferay api instead these things. per this liferay forum post:

the liferay database not published reason. reason api more stuff simple sql insert statements. there internally managed foreign keys, there things updated not in database in indices, in jackrabbit, etc.

since of managed code , not database, updates code change how , when database updated. if did work in 6.1 ga1 version, ga2 coming out in couple of weeks , database/code may change again.

sticking api way insure changes done correctly.

ok enough preaching , problem, here ways can these:

  1. you can either build custom portlet , use liferay's services , update username, birthdate etc using userlocalserviceutil.updateuser() method.
  2. or can build web-service client based on soap or json update details call same method
  3. or can use liferay's beanshell tool control panel, following code update user (created asap):

    import com.liferay.portal.model.company; import com.liferay.portal.model.contact; import com.liferay.portal.model.contactconstants; import com.liferay.portal.model.user; import com.liferay.portal.service.companylocalserviceutil; import com.liferay.portal.service.contactlocalserviceutil; import com.liferay.portal.service.userlocalserviceutil;  import java.util.calendar; import java.util.date; import java.util.gregoriancalendar;  long companyid = 10135; // different  user user = userlocalserviceutil.getuserbyemailaddress(companyid, "test@liferay.com");  // updating user's details  user.setemailaddress("mytest@liferay.com"); user.setfirstname("first test"); user.setlastname("last test"); user.setscreenname("mytestscreenname");  userlocalserviceutil.updateuser(user, false);  // updating user's birthday  // december 12, 1912 int birthdaymonth = 11; int birthdayday = 12; int birthdayyear = 1912;  calendar cal = new gregoriancalendar(); cal.set(birthdayyear, birthdaymonth, birthdayday, 0, 0, 0); cal.set(calendar.millisecond, 0);  date birthday = cal.gettime();      system.out.println("updated user: " + user + "\nbirthdate updated: " + birthday);  long contactid = user.getcontactid();  contact contact = contactlocalserviceutil.getcontact(contactid);  if(contact == null) {      contact = contactlocalserviceutil.createcontact(contactid);      company company = companylocalserviceutil.getcompany(user.getcompanyid());      contact.setcompanyid(user.getcompanyid());     contact.setusername(stringpool.blank);     contact.setcreatedate(new date());     contact.setaccountid(company.getaccountid());     contact.setparentcontactid(contactconstants.default_parent_contact_id); }  contact.setmodifieddate(new date()); contact.setbirthday(birthday);  contactlocalserviceutil.updatecontact(contact, false);  system.out.println("users birthdate updated successfully"); 

    the contact code built of liferay's source code userlocalserviceimpl#updateuser method

in case wondering bean-shell , put code, here can find in liferay control panel control panel --> server --> server administration --> script

liferay beanshell


Comments