BundleTask::getActiveTaskIdByName PHP Method

getActiveTaskIdByName() public static method

Check if given name is already used in any running bundletask of this account or environment
public static getActiveTaskIdByName ( string $name, integer $accountId, integer $envId ) : integer | boolean
$name string Name of Role
$accountId integer Identifier of Account
$envId integer Identifier of Environment
return integer | boolean Returns identifier of the Active BundleTask that matches the specified criteria or false otherwise
    public static function getActiveTaskIdByName($name, $accountId, $envId)
    {
        return Scalr::getDb()->GetOne("\n            SELECT id\n            FROM bundle_tasks\n            WHERE rolename = ?\n            AND object = ?\n            AND (client_id = ? AND object_scope = ? OR env_id = ? AND object_scope = ?)\n            AND status NOT IN (?, ?)\n        ", [$name, self::BUNDLETASK_OBJECT_ROLE, $accountId, ScopeInterface::SCOPE_ACCOUNT, $envId, ScopeInterface::SCOPE_ENVIRONMENT, SERVER_SNAPSHOT_CREATION_STATUS::SUCCESS, SERVER_SNAPSHOT_CREATION_STATUS::FAILED]);
    }

Usage Example

コード例 #1
0
ファイル: class.ScalrAPI_2_0_0.php プロジェクト: scalr/scalr
 public function ServerImageCreate($ServerID, $RoleName)
 {
     $this->restrictAccess(Acl::RESOURCE_IMAGES_ENVIRONMENT, Acl::PERM_IMAGES_ENVIRONMENT_MANAGE);
     $this->restrictAccess(Acl::RESOURCE_ROLES_ENVIRONMENT, Acl::PERM_ROLES_ENVIRONMENT_MANAGE);
     $DBServer = DBServer::LoadByID($ServerID);
     // Validate client and server
     if ($DBServer->envId != $this->Environment->id) {
         throw new Exception(sprintf("Server ID #%s not found", $ServerID));
     }
     $this->user->getPermissions()->validate($DBServer);
     //Check for already running bundle on selected instance
     $chk = $this->DB->GetOne("SELECT id FROM bundle_tasks WHERE server_id=? AND status NOT IN ('success', 'failed') LIMIT 1", array($ServerID));
     if ($chk) {
         throw new Exception(sprintf(_("Server '%s' is already synchonizing."), $ServerID));
     }
     if (!Role::isValidName($RoleName)) {
         throw new Exception(_("Role name is incorrect"));
     }
     if (Role::isNameUsed($RoleName, $this->user->getAccountId(), $this->Environment->id)) {
         throw new Exception("Specified role name is already used by another role");
     }
     if ($btId = BundleTask::getActiveTaskIdByName($RoleName, $this->user->getAccountId(), $this->Environment->id)) {
         throw new Exception(sprintf("Specified role name is already reserved for BundleTask with ID: %d.", $btId));
     }
     $ServerSnapshotCreateInfo = new ServerSnapshotCreateInfo($DBServer, $RoleName, SERVER_REPLACEMENT_TYPE::NO_REPLACE, BundleTask::BUNDLETASK_OBJECT_ROLE, 'Bundled via API');
     $BundleTask = BundleTask::Create($ServerSnapshotCreateInfo);
     $BundleTask->createdById = $this->user->id;
     $BundleTask->createdByEmail = $this->user->getEmail();
     $BundleTask->save();
     $response = $this->CreateInitialResponse();
     $response->BundleTaskID = $BundleTask->id;
     return $response;
 }
All Usage Examples Of BundleTask::getActiveTaskIdByName