Scalr\Model\Entity\Image::checkImage PHP Метод

checkImage() публичный Метод

Check if image exists and return more info if special data exists
public checkImage ( ) : boolean | array
Результат boolean | array Returns array of data if exists when update is required
    public function checkImage()
    {
        $info = [];
        if (!empty($this->envId)) {
            try {
                $env = Scalr_Environment::init()->loadById($this->envId);
                try {
                    if (empty($info = PlatformFactory::NewPlatform($this->platform)->getImageInfo($env, $this->cloudLocation, $this->id))) {
                        return false;
                    }
                    foreach (["name", "size", "architecture", "type"] as $k) {
                        if (isset($info[$k])) {
                            $this->{$k} = $info[$k];
                            unset($info[$k]);
                        }
                    }
                } catch (\Exception $e) {
                    return false;
                }
            } catch (\Exception $e) {
            }
        }
        return $info;
    }

Usage Example

Пример #1
0
 protected function run2()
 {
     $cnt = 0;
     $images = $this->db->GetAll('SELECT ri.*, r.env_id FROM role_images ri LEFT JOIN roles r ON r.id = ri.role_id');
     foreach ($images as $i) {
         /* @var Image $imObj */
         $i['env_id'] = $i['env_id'] == 0 ? NULL : $i['env_id'];
         $imObj = Image::findOne([['id' => $i['image_id']], ['$or' => [['envId' => $i['env_id']], ['envId' => null]]], ['platform' => $i['platform']], ['cloudLocation' => $i['cloud_location']]]);
         if (!$imObj) {
             $imObj = new Image();
             $imObj->id = $i['image_id'];
             $imObj->envId = $i['env_id'];
             $imObj->platform = $i['platform'];
             $imObj->cloudLocation = $i['cloud_location'];
             $imObj->architecture = $i['architecture'] ? $i['architecture'] : 'x84_64';
             $imObj->osId = $i['os_id'];
             $imObj->isDeprecated = 0;
             $imObj->dtAdded = NULL;
             $imObj->source = Image::SOURCE_MANUAL;
             if ($imObj->envId) {
                 $imObj->checkImage();
             } else {
                 $imObj->status = Image::STATUS_ACTIVE;
             }
             if (is_null($imObj->status)) {
                 $imObj->status = Image::STATUS_ACTIVE;
             }
             if (is_null($imObj->cloudLocation)) {
                 $imObj->cloudLocation = '';
             }
             $imObj->save();
             $cnt++;
         }
     }
     $this->console->notice('Added %s images', $cnt);
 }
All Usage Examples Of Scalr\Model\Entity\Image::checkImage