chdir($argv[1]);
define("CONSOLE_MODE", true);
define('PUBLIC_FOLDER', 'public');
include "init.php";
session_commit();
// we don't need sessions
@set_time_limit(0);
// don't limit execution of cron, if possible
ini_set('memory_limit', '1024M');
Env::useHelper('permissions');
$user_id = array_var($argv, 2);
$token = array_var($argv, 3);
// log user in
$user = Contacts::findById($user_id);
if (!$user instanceof Contact || !$user->isValidToken($token)) {
    die;
}
CompanyWebsite::instance()->setLoggedUser($user, false, false, false);
// get parameters
$member_id = array_var($argv, 4);
$old_parent_id = array_var($argv, 5);
// execute the permissions rebuild
try {
    DB::beginWork();
    do_member_parent_changed_refresh_object_permisssions($member_id, $old_parent_id);
    DB::commit();
} catch (Exception $e) {
    Logger::log("ERROR updating permissions after changing member parent for member ({$member_id})");
    DB::rollback();
}
示例#2
0
/**
 * Function called after editing a member and changing its parent, it will refresh the permissions for all the objects within the member.
 * If it is possible this function should be executed in background
 */
function member_parent_changed_refresh_object_permisssions($member, $old_parent_id, $user)
{
    if (substr(php_uname(), 0, 7) == "Windows" || !can_save_permissions_in_background()) {
        do_member_parent_changed_refresh_object_permisssions($member->getId(), $old_parent_id);
    } else {
        $command = "nice -n19 " . PHP_PATH . " " . ROOT . "/application/helpers/member_parent_changed_refresh_object_permisssions.php " . ROOT . " " . $user->getId() . " " . $user->getTwistedToken() . " " . $member->getId() . " " . $old_parent_id;
        exec("{$command} > /dev/null &");
        //Test php command
        exec(PHP_PATH . " -r 'echo function_exists(\"foo\") ? \"yes\" : \"no\";' 2>&1", $output, $return_var);
        if ($return_var != 0) {
            Logger::log(print_r("Error executing php command", true));
            Logger::log(print_r($output, true));
            Logger::log(print_r("Error code: " . $return_var, true));
        }
        //END Test php command
    }
}