DBServer::LoadByPropertyValue PHP Method

LoadByPropertyValue() public static method

Return DBServer by property value
public static LoadByPropertyValue ( string $propName, string $propValue ) : DBServer
$propName string
$propValue string
return DBServer
    public static function LoadByPropertyValue($propName, $propValue)
    {
        $db = \Scalr::getDb();
        $serverId = $db->GetOne("SELECT server_id FROM server_properties WHERE `name`=? AND `value`=? LIMIT 1", array($propName, $propValue));
        if (!$serverId) {
            throw new \Scalr\Exception\ServerNotFoundException(sprintf("Server with property '%s'='%s' not found in database", $propName, $propValue));
        }
        return self::LoadByID($serverId);
    }

Usage Example

Example #1
0
 public function xCreateAction()
 {
     $this->request->defineParams(array('volumeId', 'cloudLocation'));
     $aws = $this->getEnvironment()->aws($this->getParam('cloudLocation'));
     $snapshot = $aws->ec2->snapshot->create($this->getParam('volumeId'));
     if (isset($snapshot->snapshotId)) {
         /* @var $volume \Scalr\Service\Aws\Ec2\DataType\VolumeData */
         $volume = $aws->ec2->volume->describe($snapshot->volumeId)->get(0);
         if (count($volume->attachmentSet) && !empty($volume->attachmentSet[0]->instanceId)) {
             $instanceId = $volume->attachmentSet[0]->instanceId;
             try {
                 $dBServer = DBServer::LoadByPropertyValue(EC2_SERVER_PROPERTIES::INSTANCE_ID, $instanceId);
                 $dBFarm = $dBServer->GetFarmObject();
             } catch (Exception $e) {
             }
             if (isset($dBServer) && isset($dBFarm)) {
                 $comment = sprintf(_("Created on farm '%s', server '%s' (Instance ID: %s)"), $dBFarm->Name, $dBServer->serverId, $instanceId);
             }
         } else {
             $comment = '';
         }
         $this->db->Execute("\n                INSERT INTO ebs_snaps_info\n                SET snapid = ?,\n                    comment = ?,\n                    dtcreated = NOW(),\n                    region = ?\n            ", array($snapshot->snapshotId, $comment, $this->getParam('cloudLocation')));
         $this->response->data(array('data' => array('snapshotId' => $snapshot->snapshotId)));
     } else {
         throw new Exception("Unable to create snapshot. Please try again later.");
     }
 }
All Usage Examples Of DBServer::LoadByPropertyValue