Portal Catalog object not updating

The following code is supposed to update the Lastname in my ZODB, but it doesn't . What is happening?

  obj.setLast_namek('budwa')
  print "obj lastname="+obj.getLast_name()

The above two lines work fine. The print statement will return "budwa". But when I check a listing of names to see if the ZODB has been updated, it hasn't. Can someone help?

from AccessControl import getSecurityManager

from StringIO import StringIO

from Products.CMFCore.utils import getToolByName

membership = getToolByName(context, 'portal_membership')
username = context.portal_membership.getAuthenticatedMember().getUserName()
#print username

buf = StringIO()


itemp = context.portal_catalog.queryCatalog({
            "portal_type":("Staff","Faculty"),
            "path":"/yc1/portal_college/",
            "sort_on" : "created" })


items = list(context.portal_catalog.queryCatalog({
            "portal_type":("Faculty"),
            "path":"/yc1/portal_college/bbharosay",
            "sort_on" : "created" }))
#items = list(itemp)

context.manage_setLocalRoles(username, ['Manager', 'Owner','Editor'])
#context.manage_permission('Edit', roles=['Manager', 'Owner','Editor'], acquire=True)
print >> buf, "Found %d items to be Updated" % len(items)
getSecurityManager().checkPermission('View', context)
roles2 = [r['name'] for r in context.rolesOfPermission('View') if r['selected']]
#context.portal.rolesOfPermission('Modify portal content')
count = 0
for b in items:
    obj = b.getObject()
    #obj.declareObjectPublic() # like __roles__ = ACCESS_PUBLIC
    #print >> buf, "updating:" + obj.absolute_url()
    #obj.at_post_edit_script
    d='dummyvalue'
    print obj.getADStatus()
    try:
      print obj.getADStatus()
      obj.setFirst_name(d)
      obj.setLast_name(d)
      obj.setTeachingTitle(d)
      obj.setOtherTitle(d)
      obj.setEmail(d);
      obj.setOfficePhone(d)
      obj.setOfficeLocation(d)
      obj.setDept(d);
      obj.setEmployeeType(d)
      obj.setDivision(d)
      obj.setCurrentStatus(d)
      obj.setOrgStatus(d)
      print obj.getFirst_name()
      print '\n'
      print obj.getLast_name()
      obj.setLast_namek('budwa')
      print "obj lastname="+obj.getLast_name()
      obj.reindexObject()
    except Exception:
      #pass
      print Exception
    count=count+1
    print count

    
print 'done'
return buf.getvalue(), printed

Maybe the problem is hidden in the getters/setters? What is the difference between the two version with w/o k a the end?

The purpose of this script is to look for all objects of the type Faculty in ZODB and upudate the email, dept, current title, location etc with information from Active Directory.

the setLast_name() method is setting the Last_name of the Faculty Object by obtaining the information from Active Directory.

I added a setLast_nameK() method to manually update a given Faculty just to test and see if the ZODB is actually being updated. The object in the script get updated. Because, if I print it out, I see the new name. ZODB is not being updated, because later if I do a listing of Faculty, the name is still the original.

Plone and ZODB are new to me. Maybe I am doing something stupid, so please bear with me. I usually work in Java/SQL/VB environment and have been asked to do this for our CMS Plone team.

Some thoughts:

  • how are you running this script? Is it a TTW, ZMI python script or something? That isn't completely clear.
  • all the context.manage_setLocalRoles looks odd, not sure why you need that
  • how are you listing these out? Could it be an indexing problem?
  • Do you need to manually use transactions? import transaction; transaction.commit()
  • what version of plone are you on?

Does he need to reindex the object?

How are you running this code? If you are running it with bin/instance run, you need to commit the current transaction to persist the changes into ZODB.

import transaction; transaction.commit()

from the Plone site, I am choosing add Script(python) and typing my code there. I will add import transaction and transaction.commit to see what happens.

Should I be doing this from the File System instead? Would that be better? I also wrote some code for the file system, but I am stuck on how to specify the url for the objects: My Faculty objects are in url http://mysite/yc1/portal_college/
Here is the code:
from ZEO.ClientStorage import ClientStorage
from ZODB import DB
from ZODB.PersistentMapping import PersistentMapping
from Persistence import Persistent
import transaction
storage =ClientStorage(('172.16.140.23',8100))
db = DB(storage)
connection = db.open()
print "connection open"
root = connection.root()
T=transaction.begin()

Ok. That should not be needed there (and I think, it's not even allowed).

If you are on recent Plone enough and have ZEO, you can run python script from commandline with

bin/instance -Omyplonesiteid run myscript.py

This will provide plone object as variable named obj, and you can reach portal catalog etc from there. If you get this working, then you should include transaction.commit().