Exemplo n.º 1
0
 /**
  * Adds a user to the Kaltura DB.
  * Input param $id is the unique identifier in the partner's system
  *
  * @action add
  * @param KalturaUser $user 
  * @return KalturaUser
  *
  * @throws KalturaErrors::DUPLICATE_USER_BY_ID
  * @throws KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL
  * @throws KalturaErrors::INVALID_FIELD_VALUE
  * @throws KalturaErrors::UNKNOWN_PARTNER_ID
  * @throws KalturaErrors::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED
  * @throws KalturaErrors::PASSWORD_STRUCTURE_INVALID
  * @throws KalturaErrors::DUPLICATE_USER_BY_LOGIN_ID
  */
 function addAction(KalturaUser $user)
 {
     $user->validatePropertyMinLength("id", 1);
     if ($user instanceof KalturaAdminUser) {
         $user->isAdmin = true;
     }
     $user->partnerId = $this->getPartnerId();
     $dbUser = null;
     $dbUser = $user->toObject($dbUser);
     try {
         $dbUser = kuserPeer::addUser($dbUser, $user->password);
     } catch (kUserException $e) {
         $code = $e->getCode();
         if ($code == kUserException::USER_ALREADY_EXISTS) {
             throw new KalturaAPIException(KalturaErrors::DUPLICATE_USER_BY_ID, $user->id);
             //backward compatibility
         }
         if ($code == kUserException::LOGIN_ID_ALREADY_USED) {
             throw new KalturaAPIException(KalturaErrors::DUPLICATE_USER_BY_LOGIN_ID, $user->email);
             //backward compatibility
         } else {
             if ($code == kUserException::USER_ID_MISSING) {
                 throw new KalturaAPIException(KalturaErrors::PROPERTY_VALIDATION_CANNOT_BE_NULL, $user->getFormattedPropertyNameWithClassName('id'));
             } else {
                 if ($code == kUserException::INVALID_EMAIL) {
                     throw new KalturaAPIException(KalturaErrors::INVALID_FIELD_VALUE, 'email');
                 } else {
                     if ($code == kUserException::INVALID_PARTNER) {
                         throw new KalturaAPIException(KalturaErrors::UNKNOWN_PARTNER_ID);
                     } else {
                         if ($code == kUserException::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED) {
                             throw new KalturaAPIException(KalturaErrors::ADMIN_LOGIN_USERS_QUOTA_EXCEEDED);
                         } else {
                             if ($code == kUserException::PASSWORD_STRUCTURE_INVALID) {
                                 throw new KalturaAPIException(KalturaErrors::PASSWORD_STRUCTURE_INVALID);
                             }
                         }
                     }
                 }
             }
         }
         throw $e;
     } catch (kPermissionException $e) {
         $code = $e->getCode();
         if ($code == kPermissionException::ROLE_ID_MISSING) {
             throw new KalturaAPIException(KalturaErrors::ROLE_ID_MISSING);
         }
         if ($code == kPermissionException::ONLY_ONE_ROLE_PER_USER_ALLOWED) {
             throw new KalturaAPIException(KalturaErrors::ONLY_ONE_ROLE_PER_USER_ALLOWED);
         }
         throw $e;
     }
     $newUser = new KalturaUser();
     $newUser->fromObject($dbUser);
     return $newUser;
 }