Return the latest build for a specific project, of a specific build status.
@param null $projectId
@param int $status
@return array|Build
969942
public function getLastBuildByStatus($projectId = null, $status = Build::STATUS_SUCCESS)
    {
        $query = 'SELECT * FROM build WHERE project_id = :pid AND status = :status ORDER BY id DESC LIMIT 1';
        $stmt = Database::getConnection('read')->prepare($query);
        $stmt->bindValue(':pid', $projectId);
        $stmt->bindValue(':status', $status);

        if ($stmt->execute()) {
            if ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
                return new Build($data);
            }
        } else {
            return array();
        }
    }
450347
public function getBuildBranches($projectId)
    {
        $query = 'SELECT DISTINCT `branch` FROM `build` WHERE `project_id` = :project_id';
        $stmt = Database::getConnection('read')->prepare($query);
        $stmt->bindValue(':project_id', $projectId);

        if ($stmt->execute()) {
            $res = $stmt->fetchAll(\PDO::FETCH_COLUMN);
            return $res;
        } else {
            return array();
        }
    }
1072048
public function getByProject($project_id, $maxItems = null)
    {
        $project_id = (int) $project_id;
        if ($project_id <= 0) {
            throw new Exception('Invalid param project_id');
        }
        $params      = [];
        $maxItems    = (int) $maxItems;
        if ($maxItems) {
            $params['maxItems'] = $maxItems;
        }

        return $this->rest->get("projects/$project_id/$this->action", $params);
    }
51176
public function loadTypesDataForGroup($groupId, $status)
    {
        $q = $this->getLoadTypeQueryBuilder();
        $q
            ->where($q->expr()->eq('g.group_id', ':gid'))
            ->andWhere($q->expr()->eq('c.version', ':version'))
            ->addOrderBy('c.identifier')
            ->setParameter('gid', $groupId, ParameterType::INTEGER)
            ->setParameter('version', $status, ParameterType::INTEGER);

        return $q->execute()->fetchAll();
    }
160235
protected function projectsStatus()
    {
        $status_report = [];
        $status = locale_translation_get_status();
        foreach ($status as $project_id => $project) {
            foreach ($project as $langcode => $project_info) {
                $info = '';
                if ($project_info->type == LOCALE_TRANSLATION_LOCAL || $project_info->type == LOCALE_TRANSLATION_REMOTE) {
                    $local = isset($project_info->files[LOCALE_TRANSLATION_LOCAL]) ? $project_info->files[LOCALE_TRANSLATION_LOCAL] : null;
                    $remote = isset($project_info->files[LOCALE_TRANSLATION_REMOTE]) ? $project_info->files[LOCALE_TRANSLATION_REMOTE] : null;
                    $local_age = $local->timestamp? format_date($local->timestamp, 'html_date'): '';
                    $remote_age = $remote->timestamp? format_date($remote->timestamp, 'html_date'): '';

                    if ($local_age >= $remote_age) {
                        $info = $this->trans('commands.locale.translation.status.messages.translation-project-updated');
                    } else {
                        $info = $this->trans('commands.locale.translation.status.messages.translation-project-available');
                    }
                } elseif ($project_info->type == LOCALE_TRANSLATION_CURRENT) {
                    $info = $this->trans('commands.locale.translation.status.messages.translation-project-updated');
                } else {
                    $local_age = '';
                    $remote_age = '';
                    $info = $this->createInfoString($project_info);
                }

                $status_report[$langcode][] = [$project_info->name, $project_info->version, $local_age, $remote_age ,$info ];
            }
        }

        return $status_report;
    }
544407
public function loadBlockData($blockId, int $status): array
    {
        $query = $this->getBlockSelectQuery();
        $query->where(
            $query->expr()->eq('b.id', ':id')
        )
        ->setParameter('id', $blockId, Type::INTEGER);

        $this->applyStatusCondition($query, $status, 'b.status');

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
463761
public function getKnownBranches($projectId)
    {
        $query = 'SELECT DISTINCT branch from build WHERE project_id = :pid';
        $stmt = Database::getConnection('read')->prepare($query);
        $stmt->bindValue(':pid', $projectId);

        if ($stmt->execute()) {
            $res = $stmt->fetchAll(\PDO::FETCH_ASSOC);

            $map = function ($item) {
                return $item['branch'];
            };
            $rtn = array_map($map, $res);

            return $rtn;
        } else {
            return array();
        }
    }
121819
protected function _status($id, $status) {
		if (!$this->{$this->modelClass}->changeStatus($id, $status)) {
			return $this->alert('status.fail');
		}
		$this->alert('status.success');
	}
618565
protected function getStatus($statusId)
    {
        if (!isset($this->cachedStatuses[$statusId])) {
            $this->cachedStatuses[$statusId] = $this->statusRepository->findOneById($statusId);
        }

        return $this->cachedStatuses[$statusId];
    }
149596
public function updateProject(int $projectId, string $name): bool
    {
        if ('' === $name || ! $this->validateId($projectId)) {
            return false;
        }

        $data   = $this->prepareRequestData(['name' => $name]);
        $result = $this->post('projects/' . $projectId, $data);

        return 204 === $result->getStatusCode();
    }
281843
public ItemRequest<ProjectStatus> findById(String projectStatus) {

        String path = String.format("/project_statuses/%s", projectStatus);
        return new ItemRequest<ProjectStatus>(this, ProjectStatus.class, path, "GET");
    }
904367
public function svn($projectId)
    {
        $project = $this->fetchProject($projectId, 'svn');
        $branch = $this->getParam('branch', $project->getBranch());
        $commit = $this->getParam('commit');
        $commitMessage = $this->getParam('message');
        $committer = $this->getParam('committer');

        return $this->createBuild($project, $commit, $branch, $committer, $commitMessage);
    }
628045
protected function getStatusString($status)
    {
        switch ($status) {
            case Values\Content\VersionInfo::STATUS_DRAFT:
                return 'DRAFT';

            case Values\Content\VersionInfo::STATUS_PUBLISHED:
                return 'PUBLISHED';

            case Values\Content\VersionInfo::STATUS_ARCHIVED:
                return 'ARCHIVED';
        }

        throw new RuntimeException('Undefined version status: ' . $status);
    }
1319416
public function setIssueStatus($id, $status)
    {
        $api = $this->client->issue_status;
        $statusId = $api->getIdByName($status);

        return $this->update($id, [
            'status_id' => $statusId,
        ]);
    }
1269035
private function mapStatusToVersionInfoStatus($status)
    {
        if (array_key_exists($status, self::VERSION_STATUS)) {
            return self::VERSION_STATUS[$status];
        }

        throw new InvalidArgumentException(
            'status',
            sprintf(
                "Status %s can't be mapped to VersionInfo status.",
                $status
            )
        );
    }
1033612
public function setStatus($contentId, $version, $status)
    {
        $q = $this->dbHandler->createUpdateQuery();
        $q->update(
            $this->dbHandler->quoteTable('ezcontentobject_version')
        )->set(
            $this->dbHandler->quoteColumn('status'),
            $q->bindValue($status, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('modified'),
            $q->bindValue(time(), null, \PDO::PARAM_INT)
        )->where(
            $q->expr->lAnd(
                $q->expr->eq(
                    $this->dbHandler->quoteColumn('contentobject_id'),
                    $q->bindValue($contentId, null, \PDO::PARAM_INT)
                ),
                $q->expr->eq(
                    $this->dbHandler->quoteColumn('version'),
                    $q->bindValue($version, null, \PDO::PARAM_INT)
                )
            )
        );
        $statement = $q->prepare();
        $statement->execute();

        if ((bool)$statement->rowCount() === false) {
            return false;
        }

        if ($status !== APIVersionInfo::STATUS_PUBLISHED) {
            return true;
        }

        // If the version's status is PUBLISHED, we set the content to published status as well
        $q = $this->dbHandler->createUpdateQuery();
        $q->update(
            $this->dbHandler->quoteTable('ezcontentobject')
        )->set(
            $this->dbHandler->quoteColumn('status'),
            $q->bindValue(ContentInfo::STATUS_PUBLISHED, null, \PDO::PARAM_INT)
        )->set(
            $this->dbHandler->quoteColumn('current_version'),
            $q->bindValue($version, null, \PDO::PARAM_INT)
        )->where(
            $q->expr->eq(
                $this->dbHandler->quoteColumn('id'),
                $q->bindValue($contentId, null, \PDO::PARAM_INT)
            )
        );
        $statement = $q->prepare();
        $statement->execute();

        return (bool)$statement->rowCount();
    }
232085
public function addProjectToTask($taskId, $projectId = null)
    {
        $data = [
            'project' => $projectId ?: $this->defaultProjectId
        ];

        return $this->curl->post("tasks/{$taskId}/addProject", ['data' => $data]);
    }