DBFarmRole::getReplacementRoles PHP Method

getReplacementRoles() public method

public getReplacementRoles ( $includeSelf = false )
    public function getReplacementRoles($includeSelf = false)
    {
        $dbRole = $this->GetRoleObject();
        $roles_sql = "\n            SELECT r.id\n            FROM roles r\n            INNER JOIN role_images ri ON r.id = ri.role_id\n            INNER JOIN os ON os.id = r.os_id\n            LEFT JOIN role_environments re ON re.role_id = r.id\n            WHERE r.generation = '2' AND (r.client_id IS NULL OR r.client_id = ? AND r.env_id IS NULL AND (re.env_id IS NULL OR re.env_id = ?) OR r.env_id = ?)\n            AND ri.platform = ? " . (in_array($this->Platform, array(SERVER_PLATFORMS::GCE)) ? '' : "AND ri.cloud_location = ? ") . "AND os.family = ? " . ($dbRole->isScalarized == 1 ? ' AND r.is_scalarized = 1 ' : '') . ($includeSelf ? '' : "AND r.id != ? ") . "GROUP BY r.id";
        $args = array($this->GetFarmObject()->ClientID, $this->GetFarmObject()->EnvID, $this->GetFarmObject()->EnvID, $this->Platform);
        if (!in_array($this->Platform, array(SERVER_PLATFORMS::GCE))) {
            $args[] = $this->CloudLocation;
        }
        $args[] = $dbRole->getOs()->family;
        if ($includeSelf) {
            $args[] = $dbRole->id;
        }
        $behaviors = $dbRole->getBehaviors();
        if (in_array(ROLE_BEHAVIORS::CHEF, $behaviors) && $dbRole->getProperty(Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP) != 1 && $this->GetSetting(Scalr_Role_Behavior_Chef::ROLE_CHEF_BOOTSTRAP) != 1) {
            // role has chef behavior, but doesn't use chef, remove chef from list of behaviors
            $behaviors = array_diff($behaviors, [ROLE_BEHAVIORS::CHEF]);
        }
        sort($behaviors);
        $hasChef = in_array(ROLE_BEHAVIORS::CHEF, $behaviors);
        $result = array();
        foreach ($this->DB->GetCol($roles_sql, $args) as $roleId) {
            $role = DBRole::loadById($roleId);
            $behaviors2 = $role->getBehaviors();
            if (!$hasChef) {
                $behaviors2 = array_diff($behaviors2, [ROLE_BEHAVIORS::CHEF]);
            }
            sort($behaviors2);
            if ($behaviors == $behaviors2 || $dbRole->isScalarized == 0) {
                $image = $role->__getNewRoleObject()->getImage($this->Platform, $this->CloudLocation)->getImage();
                if ($image) {
                    $result[] = array('id' => $role->id, 'name' => $role->name, 'osId' => $role->osId, 'behaviors' => $role->getBehaviors(), 'scope' => $role->__getNewRoleObject()->getScope(), 'image' => ['id' => $image->id, 'type' => $image->type, 'architecture' => $image->architecture]);
                }
            } else {
                //var_dump($behaviors2);
            }
        }
        return $result;
    }