I'm needing to be able to programmatically load a user, modify their tac_lite permissions, then save it again. The problem is that I can't seem to find a way to do this. I set up the tac_lite array on the $user object like so:

$user->tac_lite[1][105] = 105;

This, in theory, should grant the user the privelage of viewing nodes tagged with a tid of 105. Unfortunately, as it would turn out, this property does not get saved at all, either in $user->data (which it appears that tac_lite makes use of) or in $user->tac_lite (it's simply empty). I'm not sure if this should be an issue, or if I'm simply doing it wrong. But my overall goal is that this must be done programmatically.

Comments

Dave Cohen’s picture

The right way is to use drupal_execute(). It's complicated, but it is the right way to do this sort of thing in Drupal.

jerdiggity’s picture

Just saw you on IRC (@ShooterMG)... Wondering if it worked or not.

Incidentally, @Dave: would something like this work or no?

global $user;
$tac = array(
  'tac_lite' => array(
    1 => array(105)));
user_save($user, $tac);
Dave Cohen’s picture

I dunno. Let us know. The only technique I'd recommend is drupal_execute(), or whatever it now is in D7.

tharna’s picture

I got it working like this (on d7):

global $user;
$edit = (array)$user;
$edit['data']['tac_lite'][$vid][$tid] = $tid;
user_save($user, $edit);
kotnik’s picture

Based on #2, this works for D6:

$tac = array(
  'tac_lite' => array(
    $vid => array($tid1 => $tid1, $tid2 => $tid2,)
  );
);
user_save($user, $tac);
tinker’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.