/**
  * Updates the 'simple' userdata
  * @param NsmUser $user
  * @param AgaviRequestDataHolder $rd
  * @return boolean
  * @author Marius Hein
  */
 public function updateUserData(NsmUser &$user, AgaviRequestDataHolder &$rd)
 {
     AppKitDoctrineUtil::updateRecordsetFromArray($user, $rd->getParameters(), self::$editableAttributes);
     if (!$user->get("user_password")) {
         $user->set("user_password", AppKitRandomUtil::initRand());
         $user->set("user_salt", AppKitRandomUtil::initRand());
     }
     // Check the principal. Because we have nothing
     // in some situations #3992
     //
     // Create one of missed here
     if (!$user->principalIsValid()) {
         $principal = new NsmPrincipal();
         $principal->principal_type = NsmPrincipal::TYPE_USER;
         $user->principal = $principal;
     }
     // Manually because we want write empty strings
     $user->set('user_description', $rd->getParameter('user_description', new Doctrine_Null()));
     $user->save();
     return true;
 }
 /**
  * Updates the simple role data
  * @param NsmRole $role
  * @param AgaviRequestDataHolder $rd
  * @return boolean
  * @author Marius Hein
  */
 public function updateRoleData(NsmRole &$role, AgaviRequestDataHolder &$rd)
 {
     AppKitDoctrineUtil::updateRecordsetFromArray($role, $rd->getParameters(), self::$editableAttributes);
     // Checking the principal
     if (!$role->NsmPrincipal->principal_id) {
         $role->NsmPrincipal->principal_type = NsmPrincipal::TYPE_ROLE;
     }
     if ($role->role_id === null) {
         // insert a new role
         $role->save();
     } else {
         // update role
         $parts = array();
         $params = array();
         foreach ($role as $property => $value) {
             if ($property == "role_id" || !in_array($property, self::$editableAttributes)) {
                 continue;
             }
             if ($value === null) {
                 $parts[] = "{$property} = NULL";
             } else {
                 $parts[] = "{$property} = ? ";
                 $params[] = $value;
             }
         }
         $params[] = $role->role_id;
         $dql = "UPDATE NsmRole SET " . implode(",", $parts) . " WHERE role_id = ?";
         AppKitLogger::warn("Test: %s - %s", $dql, var_export($params, true));
         $query = new Doctrine_Query();
         $query->setConnection(AppKitDoctrineUtil::getConnection());
         $query->parseDqlQuery($dql);
         $query->execute($params);
     }
     return true;
 }