getEmail() public method

Gets email address of the User
public getEmail ( ) : string
return string Returns user email address
Ejemplo n.º 1
0
 /**
  * Prepares extra data to pass to a backend
  * Those include RUID, EUID, AccountID, environment etc.
  *
  * @return array Prepared extra data for logging
  */
 protected function getCommonData()
 {
     $data = empty($this->user) ? ["login" => $this->systemTask ? '_' . $this->systemTask : 'guest', "ruid" => null, "euid" => null, "env_id" => $this->envId ?: 0, "account_id" => $this->accountId] : ["login" => $this->user->getEmail(), "ruid" => $this->realUserId ?: $this->user->id, "euid" => $this->user->id, "env_id" => $this->envId ?: 0, "account_id" => empty($this->accountId) ? $this->user->getAccountId() : $this->accountId];
     $data['ip_address'] = $this->ipAddress;
     $data['timestamp'] = AuditLogger::getTimestamp();
     $data['request_type'] = $this->requestType;
     return $data;
 }
Ejemplo n.º 2
0
 /**
  * Migrates an Image to another Cloud Location
  *
  * @param  string $cloudLocation The cloud location
  * @param  \Scalr_Account_User|\Scalr\Model\Entity\Account\User $user The user object
  * @return Image
  * @throws Exception
  * @throws NotEnabledPlatformException
  * @throws DomainException
  */
 public function migrateEc2Location($cloudLocation, $user)
 {
     if (!$this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2)) {
         throw new NotEnabledPlatformException("You can migrate image between regions only on EC2 cloud");
     }
     if ($this->cloudLocation == $cloudLocation) {
         throw new DomainException('Destination region is the same as source one');
     }
     $snap = $this->getEnvironment()->aws($this->cloudLocation)->ec2->image->describe($this->id);
     if ($snap->count() == 0) {
         throw new Exception("Image haven't been found on cloud.");
     }
     if ($snap->get(0)->toArray()['imageState'] != 'available') {
         throw new Exception('Image is not in "available" status on cloud and cannot be copied.');
     }
     $this->checkImage();
     // re-check properties
     $aws = $this->getEnvironment()->aws($cloudLocation);
     $newImageId = $aws->ec2->image->copy($this->cloudLocation, $this->id, $this->name, "Image was copied by Scalr from image: {$this->name}, cloudLocation: {$this->cloudLocation}, id: {$this->id}", null, $cloudLocation);
     $newImage = new Image();
     $newImage->platform = $this->platform;
     $newImage->cloudLocation = $cloudLocation;
     $newImage->id = $newImageId;
     $newImage->name = $this->name;
     $newImage->architecture = $this->architecture;
     $newImage->size = $this->size;
     $newImage->accountId = $this->accountId;
     $newImage->envId = $this->envId;
     $newImage->osId = $this->osId;
     $newImage->source = Image::SOURCE_MANUAL;
     $newImage->type = $this->type;
     $newImage->agentVersion = $this->agentVersion;
     $newImage->createdById = $user->getId();
     $newImage->createdByEmail = $user->getEmail();
     $newImage->status = Image::STATUS_ACTIVE;
     $newImage->isScalarized = $this->isScalarized;
     $newImage->hasCloudInit = $this->hasCloudInit;
     $newImage->save();
     $newImage->setSoftware($this->getSoftware());
     return $newImage;
 }
Ejemplo n.º 3
0
 /**
  * Marks server as to be terminated.
  *
  * @param   int|array       $reason      The reason possibly with the format parameters.
  * @param   bool            $forcefully  optional Method: forcefully (true) | gracefully (false)
  * @param   User            $user        optional The user entity
  * @return  bool
  */
 public function terminate($reason, $forcefully = null, $user = null)
 {
     if (in_array($this->status, [Server::STATUS_PENDING_TERMINATE, Server::STATUS_TERMINATED])) {
         return false;
     }
     $forcefully = $forcefully === null ? true : (bool) $forcefully;
     $fnGetReason = function ($reasonId) {
         $args = func_get_args();
         $args[0] = Server::getTerminateReason($reasonId);
         return [call_user_func_array('sprintf', $args), $reasonId];
     };
     list($reason, $reasonId) = is_array($reason) ? call_user_func_array($fnGetReason, $reason) : $fnGetReason($reason);
     $properties = $this->properties;
     if ($user instanceof User) {
         $properties[self::TERMINATED_BY_ID] = $user->getId();
         $properties[self::TERMINATED_BY_EMAIL] = $user->getEmail();
     }
     $properties[self::REBOOTING] = 0;
     $properties->save();
     $this->update(['status' => Server::STATUS_PENDING_TERMINATE, 'shutdownScheduled' => new DateTime($forcefully ? 'now' : Scalr::config('scalr.system.server_terminate_timeout'))]);
     $this->getHistory()->markAsTerminated($reason, $reasonId);
     if (isset($this->farmId)) {
         $DBServer = $this->__getDBServer();
         Scalr::FireEvent($this->farmId, new BeforeHostTerminateEvent($DBServer, false));
         // If instance was terminated outside scalr, we need manually fire HostDown
         if ($reasonId == self::TERMINATE_REASON_CRASHED) {
             Scalr::FireEvent($this->farmId, new HostDownEvent($DBServer, false));
         }
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * Migrates an Image to another Cloud Location
  *
  * @param  string $cloudLocation The cloud location
  * @param  \Scalr_Account_User|\Scalr\Model\Entity\Account\User $user The user object
  * @return Image
  * @throws NotEnabledPlatformException
  * @throws DomainException
  */
 public function migrateEc2Location($cloudLocation, $user)
 {
     if (!$this->getEnvironment()->isPlatformEnabled(SERVER_PLATFORMS::EC2)) {
         throw new NotEnabledPlatformException("You can migrate image between regions only on EC2 cloud");
     }
     if ($this->cloudLocation == $cloudLocation) {
         throw new DomainException('Destination region is the same as source one');
     }
     $this->checkImage();
     // re-check properties
     $aws = $this->getEnvironment()->aws($cloudLocation);
     $newImageId = $aws->ec2->image->copy($this->cloudLocation, $this->id, $this->name, "Image was copied by Scalr from image: {$this->name}, cloudLocation: {$this->cloudLocation}, id: {$this->id}", null, $cloudLocation);
     $newImage = new Image();
     $newImage->platform = $this->platform;
     $newImage->cloudLocation = $cloudLocation;
     $newImage->id = $newImageId;
     $newImage->name = $this->name;
     $newImage->architecture = $this->architecture;
     $newImage->size = $this->size;
     $newImage->envId = $this->envId;
     $newImage->osId = $this->osId;
     $newImage->source = Image::SOURCE_MANUAL;
     $newImage->type = $this->type;
     $newImage->agentVersion = $this->agentVersion;
     $newImage->createdById = $user->getId();
     $newImage->createdByEmail = $user->getEmail();
     $newImage->status = Image::STATUS_ACTIVE;
     $newImage->save();
     $newImage->setSoftware($this->getSoftware());
     return $newImage;
 }