Scalr\Stats\CostAnalytics\Entity\ProjectEntity::checkRemoval PHP Method

checkRemoval() public method

If Project can't be archived and removed it will throw an exception
public checkRemoval ( ) : boolean
return boolean Returns TRUE if Project can be removed or false if it can be archived or throws an exception otherwise
    public function checkRemoval()
    {
        //Checks data integrity
        if ($this->projectId == Usage::DEFAULT_PROJECT_ID) {
            throw new AnalyticsException(sprintf("'%s' is default automatically created Project and it can not be archived.", $this->name));
        }
        $farm = \Scalr::getDb()->GetRow("\n            SELECT f.id, f.name FROM farms f\n            JOIN farm_settings fs ON fs.farmid = f.id\n            WHERE fs.name = ? AND fs.value = ?\n            LIMIT 1\n        ", [Entity\FarmSetting::PROJECT_ID, strtolower($this->projectId)]);
        if ($farm) {
            throw new AnalyticsException(sprintf("Project '%s' can not be archived because it is used by the farm '%s' (id:%d). " . "Reallocate '%s' to another project first.", $this->name, $farm['name'], $farm['id'], $farm['name'], $this->name));
        }
        $bAllowedToRemove = $this->projectId != Usage::DEFAULT_PROJECT_ID;
        //Are there any record for this project in the usage statistics?
        if ($bAllowedToRemove && \Scalr::getContainer()->analytics->enabled) {
            $budget = QuarterlyBudgetEntity::findOne([['subjectType' => QuarterlyBudgetEntity::SUBJECT_TYPE_PROJECT], ['subjectId' => $this->projectId], ['cumulativespend' => ['$gt' => 0]]]);
            if ($budget) {
                //It can only be archived
                $bAllowedToRemove = false;
            }
        }
        return $bAllowedToRemove;
    }