Hi, I am a new to Drupal and I have been working on an internal website developed for my company. I have a php cron script that regularly runs against my Active Directory server to check for any changes to users and their department assignments.
I have created a CCK field, field_objectguid, to store the unique object GUID that is assigned to every AD objects in my Department type node. This is done so that in case a department/user changes its name, the system can detect it and update the existing one instead of creating it.
Here is the code I have for the department type nodes:
foreach (ldap_get_entries($ds, $result) as $k => $v) {
$group = node_load(array('field_objectguid' => bin2hex($v["objectguid"][0]), 'type' => DEPARTMENT_NODE_TYPE)); // Error on this line
if($group && $group->title != $v["description"][0]){
$group->title = $v["description"][0];
$group->og_description = $v["description"][0];
node_save($group);
}
}
The problem is node_load() can't use CCK fields since its code only queries the core node fields. I have looked around for solutions but haven't found an official fix to this kind of problem. Is there any other way to approach this?
Comments
Comment #1
wolfdenoir commentedComment #2
nevets commentedYou need to know the table field_objectguid is in and do something like
Comment #3
wolfdenoir commentedHey thanks for the advice nevets! Although I kind of come up with my own workaround.
Instead of querying the nodes specifically using the CCK field, I pulled the entire list of department nodes and iterated through them, querying the corresponding AD object each time with the field_objectguid stored in the node, which is made available AFTER the node_load():
The code could probably be further refined. It's not the most elegant solution, but it works for my case. :)