function testProfileReadingFunctions()
 {
     // find a user with 'newcss' set
     list($uid, $css) = Dal::query_one("SELECT user_id, field_value FROM user_profile_data WHERE field_type='ui' AND field_name='newcss' ORDER BY user_id LIMIT 1");
     if (empty($uid)) {
         echo "Test not possible as nobody has the newcss field set.  Try again on a more populated database.\n";
         return;
     }
     // find another field, so we can test with more than one
     list($f2_name, $f2_value) = Dal::query_one("SELECT field_name, field_value FROM user_profile_data WHERE field_type='ui' AND user_id=? AND field_name <>'newcss' AND field_value IS NOT NULL LIMIT 1", $uid);
     echo "getting ui/newcss and {$f2_name} properties from user_profile_data for user_id {$uid}.\n";
     $user = new User();
     $user->load((int) $uid);
     // load just the newcss field
     echo "getting just the newcss property for user {$uid}\n";
     $css2 = $user->get_profile_field('ui', 'newcss');
     $this->assertEquals($css, $css2);
     // load just the second field
     echo "getting just the {$f2_name} property for user {$uid}\n";
     $v = $user->get_profile_field('ui', $f2_name);
     $this->assertEquals($v, $f2_value);
     // load newcss and the second field, with get_profile_fields()
     echo "getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // try again, flushing the cache first
     Cache::reset();
     echo "(without cache) getting the newcss and {$f2_name} properties, with get_profile_fields()\n";
     $data = $user->get_profile_fields('ui', array('newcss', 'graagh', $f2_name));
     $this->assertEquals($css, $data['newcss']);
     $this->assertEquals(NULL, $data['graagh']);
     $this->assertEquals($f2_value, $data[$f2_name]);
     // regression test (phil) 2007-04-01, for bug spotted by martin
     // 2007-03-23: make sure we don't crash if we request fields that
     // are all cached.
     echo "regression: make sure it doesn't crash if everything is in the cache\n";
     $data = $user->get_profile_fields('ui', array('newcss'));
     $this->assertEquals($css, $data['newcss']);
     // try by loading the entire 'ui' section
     echo "getting entire ui section for user {$uid}\n";
     $ui = User::load_profile_section($uid, "ui");
     $this->assertEquals($css, $ui['newcss']['value']);
     $this->assertEquals($f2_value, $ui[$f2_name]['value']);
 }
Example #2
0
 public function loadProfileData()
 {
     // load the profile data for the sections this user has
     foreach ($this->userSections as $sectionName => $section) {
         $this->user->{$sectionName} = User::load_profile_section($this->user->user_id, $section);
     }
 }
Example #3
0
 public function sync($userdata)
 {
     Logger::log("ShadowUser::sync " . serialize($userdata), LOGGER_ACTION);
     // make sure we have a loaded user here
     if (empty($this->email)) {
         throw new PAException(USER_INVALID, "ShadowUser::sync There was no User loaded yet");
     }
     // we need the namespace in the user_profile_data
     // so make sure it get's set
     if (empty($userdata['namespace'])) {
         $userdata['namespace'] = $this->namespace;
     }
     $needupdate = FALSE;
     // check the core user profile fields
     $corefields = array("first_name", "last_name", "email");
     foreach ($corefields as $i => $field) {
         // Logger::log("ShadowUser::sync checking $field", LOGGER_ACTION);
         if (empty($userdata[$field])) {
             // oops? how'd this happen?
             Logger::log("ShadowUser::sync missing userdata:{$field}", LOGGER_ACTION);
             continue;
         }
         if ($this->{$field} != $userdata[$field]) {
             // make email unique here
             if ($field == 'email') {
                 // Test to see if the email was used before
                 $res = Dal::query("SELECT user_id FROM users WHERE email=?", array($userdata['email']));
                 if ($res->numrows() > 0) {
                     // oops email has been used
                     // use the prefix+email@address.tld format
                     // to ensure we have an unique string for email
                     $userdata['email'] = $userdata['user_id'] . "+" . $userdata['email'];
                     Logger::log("ShadowUser::sync using email " . $userdata['email'], LOGGER_ACTION);
                 }
             }
             $this->{$field} = $userdata[$field];
             $needupdate = TRUE;
         }
         unset($userdata[$field]);
         // so we don't handle it again below
     }
     if ($needupdate) {
         try {
             Logger::log("ShadowUser::sync saving core fields", LOGGER_ACTION);
             $this->save();
         } catch (PAException $e) {
             Logger::log("ShadowUser::sync failed user->save()", LOGGER_ACTION);
             throw $e;
         }
     }
     // handle the dislay_login_name
     $userdata['display_login_name'] = $userdata['login_name'];
     // check the namespace profile fields
     $extendeddata = User::load_profile_section($this->user_id, $this->namespace);
     // Logger::log(print_r($extendeddata,1), LOGGER_ACTION);
     $needupdate = FALSE;
     foreach ($extendeddata as $key => $data) {
         if ($extendeddata[$key]['perm'] == 0) {
             // we ned ti be able to search all this
             // so we force it to public
             $extendeddata[$key]['perm'] = 1;
             $needupdate = TRUE;
         }
         if (isset($userdata[$key])) {
             // only if it got passed
             if ($userdata[$key] != $data['value']) {
                 $extendeddata[$key]['value'] = $userdata[$key];
                 $needupdate = TRUE;
             }
             unset($userdata[$key]);
         }
     }
     // do we have any additional info left?
     if (!empty($userdata)) {
         // add it in
         foreach ($userdata as $key => $value) {
             $extendeddata[$key]['value'] = $value;
             $needupdate = TRUE;
             unset($userdata[$key]);
         }
     }
     if ($needupdate) {
         Logger::log("ShadowUser::sync saving extended data ", LOGGER_ACTION);
         $this->save_profile_section($extendeddata, $this->namespace);
     }
     Logger::log("ShadowUser::sync done", LOGGER_ACTION);
 }
 public function sync($userdata)
 {
     // make sure we have a loaded ser here
     if (empty($this->email)) {
         throw new PAException(USER_INVALID, "There was no User loaded yet");
     }
     $needupdate = FALSE;
     // check the core user profile fields
     $corefields = array("first_name", "last_name", "email");
     foreach ($corefields as $i => $field) {
         if ($this->{$field} != $userdata[$field]) {
             $this->{$field} = $userdata[$field];
             $needupdate = TRUE;
         }
     }
     if ($needupdate) {
         try {
             $this->save();
         } catch (PAException $e) {
             throw $e;
         }
     }
     // handle the dislay_login_name
     $userdata['display_login_name'] = $userdata['login_name'];
     // check the namespace profile fields
     $extendeddata = User::load_profile_section($this->user_id, $this->namespace);
     $needupdate = FALSE;
     foreach ($extendeddata as $key => $data) {
         if (isset($userdata[$key])) {
             // only if it got passed
             if ($userdata[$key] != $data['value']) {
                 $extendeddata[$key]['value'] = $userdata[$key];
                 $needupdate = TRUE;
             }
         }
     }
     if ($needupdate) {
         $this->save_profile_section($extendeddata, $this->namespace);
     }
 }