<div dir="ltr">Some of my scheduled task needs to run as the user who triggered them (not anonymous neither admin); so I thought of writing two actions:<div>- One to impersonate a user, which will receive uid as an argument.</div>
<div>- Another to undo the impersonate.</div><div style>All the called actions should be between them.</div><div><br></div><div>Anybody see any fault in this idea or the actions code?</div><div><br></div><div>Thanks.</div>
<div><br></div><div><div>function wu_action_impersonate($uid) {</div><div> global $user;</div><div> if (!array_key_exists('wu_action_impersonate', $_SESSION)) {</div><div> $_SESSION['wu_action_impersonate'] = array();</div>
<div> }</div><div> array_push($_SESSION['wu_action_impersonate'], $user);</div><div> session_save_session(FALSE);</div><div> $user = user_load($uid);</div><div> user_load($uid);</div><div>}</div><div><br></div>
<div>function wu_action_unimpersonate() {</div><div> global $user;</div><div> if (array_key_exists('wu_action_impersonate', $_SESSION)) {</div><div> if (!empty($_SESSION['wu_action_impersonate'])) {</div>
<div> $user = array_pop($_SESSION['wu_action_impersonate']);</div><div> }</div><div> if (empty($_SESSION['wu_action_impersonate'])) {</div><div> unset($_SESSION['wu_action_impersonate']);</div>
<div> }</div><div> }</div><div> session_save_session(TRUE);</div><div>}</div><div><br></div>-- <br>*Ser freak no és imprescindible per ser informàtic, però ajuda.<br>*La vida no ha de ser feliç, ha de ser plena.<br>
*Abans d'imprimir aquest missatge, pensa en el medi ambient.
</div></div>