<commit_before><?php

/*
 * Poggit
 *
 * Copyright (C) 2016-2017 Poggit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace poggit\ci\ui;

use poggit\ci\builder\ProjectBuilder;
use poggit\Mbd;
use poggit\Meta;
use poggit\module\VarPage;
use poggit\utils\internet\Curl;
use poggit\utils\internet\GitHubAPIException;
use poggit\utils\internet\Mysql;

abstract class RepoListBuildPage extends VarPage {
    /** @var \stdClass[] */
    protected $repos;

    public function __construct() {
        try {
            $repos = $this->getRepos();
        } catch(GitHubAPIException $e) {
            $this->throwNoRepos();
            return;
        }
        $ids = array_keys($repos);
        $idsImploded = substr(str_repeat(",?", count($ids)), 1);
        foreach(count($ids) === 0 ? [] : Mysql::query("SELECT r.repoId AS rid, p.projectId AS pid, p.name AS pname, p.path,
        (SELECT UNIX_TIMESTAMP(created) FROM builds WHERE builds.projectId=p.projectId 
                        AND builds.class IS NOT NULL ORDER BY created DESC LIMIT 1) AS buildDate,
                (SELECT COUNT(*) FROM builds WHERE builds.projectId=p.projectId 
                        AND builds.class IS NOT NULL) AS buildCount,
                IFNULL((SELECT CONCAT_WS(',', buildId, internal) FROM builds WHERE builds.projectId = p.projectId
                        AND builds.class = ? AND p.repoId IN ($idsImploded) ORDER BY created DESC LIMIT 1), 'null') AS bnums
                FROM projects p INNER JOIN repos r ON p.repoId=r.repoId WHERE r.build=1 ORDER BY r.name, pname", "i" . str_repeat("i", count($ids)), ProjectBuilder::BUILD_CLASS_DEV, ...$ids) as $projRow) {
            $repo = isset($repos[(int) $projRow["rid"]]) ? $repos[(int) $projRow["rid"]] : null;
            if(!isset($repo)) {
                Meta::getLog()->jwtf($repos); // FixMe This gets called occasionally!
                Meta::getLog()->jwtf($projRow["rid"]);
                continue;
            }
            $project = new ProjectThumbnail();
            $project->id = (int) $projRow["pid"];
            $project->name = $projRow["pname"];
            $project->path = $projRow["path"];
            $project->buildCount = (int) $projRow["buildCount"];
            $project->buildDate = $projRow["buildDate"];

            if($projRow["bnums"] === "null") {
                $project->latestBuildGlobalId = null;
                $project->latestBuildInternalId = null;
            } else {
                list($project->latestBuildGlobalId, $project->latestBuildInternalId) = array_map("intval", explode(",", $projRow["bnums"]));
            }
            $project->repo = $repo;
            $repo->projects[] = $project;
        }
        $this->repos = $repos;
        if($this instanceof SelfBuildPage) return;
        foreach($this->repos as $repo) {
            if(count($repo->projects) > 0) return;
        }
        $this->throwNoRepos();
    }

    /**
     * @return \stdClass[]
     */
    protected abstract function getRepos(): array;
<commit_msg>Shut up some warnings<commit_after><?php

/*
 * Poggit
 *
 * Copyright (C) 2016-2017 Poggit
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace poggit\ci\ui;

use poggit\ci\builder\ProjectBuilder;
use poggit\Mbd;
use poggit\Meta;
use poggit\module\VarPage;
use poggit\utils\internet\Curl;
use poggit\utils\internet\GitHubAPIException;
use poggit\utils\internet\Mysql;

abstract class RepoListBuildPage extends VarPage {
    /** @var \stdClass[] */
    protected $repos;

    public function __construct() {
        try {
            $repos = $this->getRepos();
        } catch(GitHubAPIException $e) {
            $this->throwNoRepos();
            return;
        }
        $ids = array_keys($repos);
        $idsImploded = substr(str_repeat(",?", count($ids)), 1);
        foreach(count($ids) === 0 ? [] : Mysql::query("SELECT r.repoId AS rid, p.projectId AS pid, p.name AS pname, p.path,
        (SELECT UNIX_TIMESTAMP(created) FROM builds WHERE builds.projectId=p.projectId 
                        AND builds.class IS NOT NULL ORDER BY created DESC LIMIT 1) AS buildDate,
                (SELECT COUNT(*) FROM builds WHERE builds.projectId=p.projectId 
                        AND builds.class IS NOT NULL) AS buildCount,
                IFNULL((SELECT CONCAT_WS(',', buildId, internal) FROM builds WHERE builds.projectId = p.projectId
                        AND builds.class = ? AND p.repoId IN ($idsImploded) ORDER BY created DESC LIMIT 1), 'null') AS bnums
                FROM projects p INNER JOIN repos r ON p.repoId=r.repoId WHERE r.build=1 ORDER BY r.name, pname", "i" . str_repeat("i", count($ids)), ProjectBuilder::BUILD_CLASS_DEV, ...$ids) as $projRow) {
            $repo = isset($repos[(int) $projRow["rid"]]) ? $repos[(int) $projRow["rid"]] : null;
            if(!isset($repo)) {
//                Meta::getLog()->jwtf($repos); // FixMe This gets called occasionally!
//                Meta::getLog()->jwtf($projRow["rid"]);
                continue;
            }
            $project = new ProjectThumbnail();
            $project->id = (int) $projRow["pid"];
            $project->name = $projRow["pname"];
            $project->path = $projRow["path"];
            $project->buildCount = (int) $projRow["buildCount"];
            $project->buildDate = $projRow["buildDate"];

            if($projRow["bnums"] === "null") {
                $project->latestBuildGlobalId = null;
                $project->latestBuildInternalId = null;
            } else {
                list($project->latestBuildGlobalId, $project->latestBuildInternalId) = array_map("intval", explode(",", $projRow["bnums"]));
            }
            $project->repo = $repo;
            $repo->projects[] = $project;
        }
        $this->repos = $repos;
        if($this instanceof SelfBuildPage) return;
        foreach($this->repos as $repo) {
            if(count($repo->projects) > 0) return;
        }
        $this->throwNoRepos();
    }

    /**
     * @return \stdClass[]
     */
    protected abstract function getRepos(): array;

{'fraction_non_alphanumeric': 0.13340838727835633, 'fraction_numerical': 0.0050661412890515055, 'mean_word_length': 2.433333333333333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3854756', 'n_tokens_mistral': 2147, 'n_tokens_neox': 2035, 'n_words': 567}