Fixed archive

This commit is contained in:
Dmitry Khomutov 2017-01-15 22:35:42 +07:00
parent 1ce0b4880e
commit 18ac9fadaf
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
12 changed files with 93 additions and 66 deletions

View file

@ -140,13 +140,14 @@ class Application extends b8\Application
$groupList = $groupStore->getWhere([], 100, 0, [], ['title' => 'ASC']);
foreach ($groupList['items'] as $group) {
$thisGroup = ['title' => $group->getTitle()];
$projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId());
$thisGroup = ['title' => $group->getTitle()];
$projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), false);
$thisGroup['projects'] = $projects['items'];
$groups[] = $thisGroup;
$groups[] = $thisGroup;
}
$layout->groups = $groups;
$layout->archived_projects = (b8\Store\Factory::getStore('Project')->getAll(true))['items'];
$layout->groups = $groups;
}
/**

View file

@ -70,7 +70,7 @@ class CreateBuildCommand extends Command
$branch = $input->getOption('branch');
$project = $this->projectStore->getById($projectId);
if (empty($project)) {
if (empty($project) || $project->getArchived()) {
throw new \InvalidArgumentException('Project does not exist: ' . $projectId);
}

View file

@ -72,13 +72,13 @@ class PollCommand extends Command
$http = new HttpClient('https://api.github.com');
$commits = $http->get('/repos/' . $project->getReference() . '/commits', ['access_token' => $token]);
$last_commit = $commits['body'][0]['sha'];
$last_commit = $commits['body'][0]['sha'];
$last_committer = $commits['body'][0]['commit']['committer']['email'];
$message = $commits['body'][0]['commit']['message'];
$message = $commits['body'][0]['commit']['message'];
$this->logger->info(Lang::get('last_commit_is', $project->getTitle(), $last_commit));
if ($project->getLastCommit() != $last_commit && $last_commit != "") {
if (!$project->getArchived() && ($project->getLastCommit() != $last_commit && $last_commit != "")) {
$this->logger->info(
Lang::get('adding_new_build')
);
@ -89,7 +89,8 @@ class PollCommand extends Command
$build->setStatus(Build::STATUS_NEW);
$build->setBranch($project->getBranch());
$build->setCreated(new \DateTime());
$build->setCommitMessage($message);
$build->setCommitMessage($message);
if (!empty($last_committer)) {
$build->setCommitterEmail($last_committer);
}

View file

@ -93,8 +93,13 @@ class BuildController extends Controller
$delete = Lang::get('delete_build');
$deleteLink = APP_URL . 'build/delete/' . $build->getId();
$project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($build->getProjectId());
$actions = "<a class=\"btn btn-default\" href=\"{$rebuildLink}\">{$rebuild}</a> ";
$actions = '';
if (!$project->getArchived()) {
$actions .= "<a class=\"btn btn-default\" href=\"{$rebuildLink}\">{$rebuild}</a> ";
}
if ($this->currentUserIsAdmin()) {
$actions .= " <a class=\"btn btn-danger\" id=\"delete-build\" href=\"{$deleteLink}\">{$delete}</a>";
@ -157,9 +162,10 @@ class BuildController extends Controller
*/
public function rebuild($buildId)
{
$copy = BuildFactory::getBuildById($buildId);
$copy = BuildFactory::getBuildById($buildId);
$project = b8\Store\Factory::getStore('Project')->getByPrimaryKey($copy->getProjectId());
if (empty($copy)) {
if (empty($copy) || $project->getArchived()) {
throw new NotFoundException(Lang::get('build_x_not_found', $buildId));
}

View file

@ -53,9 +53,11 @@ class GroupController extends Controller
'title' => $group->getTitle(),
'id' => $group->getId(),
];
$projects = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId());
$thisGroup['projects'] = $projects['items'];
$groups[] = $thisGroup;
$projects_active = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), false);
$projects_archived = b8\Store\Factory::getStore('Project')->getByGroupId($group->getId(), true);
$thisGroup['projects'] = array_merge($projects_active['items'], $projects_archived['items']);
$groups[] = $thisGroup;
}
$this->layout->title = Lang::get('group_projects');

View file

@ -110,6 +110,7 @@ class HomeController extends Controller
/**
* Get a summary of the project groups we have, and what projects they have in them.
*
* @return array
*/
protected function getGroupInfo()
@ -119,7 +120,7 @@ class HomeController extends Controller
foreach ($groups['items'] as $group) {
$thisGroup = ['title' => $group->getTitle()];
$projects = $this->projectStore->getByGroupId($group->getId());
$projects = $this->projectStore->getByGroupId($group->getId(), false);
$thisGroup['projects'] = $projects['items'];
$thisGroup['summary'] = $this->getSummaryHtml($thisGroup['projects']);
$rtn[] = $thisGroup;

View file

@ -111,7 +111,7 @@ class ProjectController extends PHPCensor\Controller
$branch = $project->getBranch();
}
if (empty($project)) {
if (empty($project) || $project->getArchived()) {
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
}

View file

@ -13,6 +13,7 @@ namespace PHPCensor\Controller;
use b8;
use b8\Store;
use Exception;
use PHPCensor\Helper\Lang;
use PHPCensor\Model\Project;
use PHPCensor\Service\BuildService;
use PHPCensor\Store\BuildStore;
@ -20,6 +21,7 @@ use PHPCensor\Store\ProjectStore;
use b8\Controller;
use b8\Config;
use b8\HttpClient;
use b8\Exception\HttpException\NotFoundException;
/**
* Webhook Controller - Processes webhook pings from BitBucket, Github, Gitlab, etc.
@ -444,6 +446,10 @@ class WebhookController extends Controller
$commitMessage,
array $extra = null
) {
if ($project->getArchived()) {
throw new NotFoundException(Lang::get('project_x_not_found', $project->getId()));
}
// Check if a build already exists for this commit ID:
$builds = $this->buildStore->getByProjectAndCommit($project->getId(), $commitId);

View file

@ -160,6 +160,6 @@ class ProjectGroupBase extends Model
*/
public function getGroupProjects()
{
return Factory::getStore('Project', 'PHPCensor')->getByGroupId($this->getId());
return Factory::getStore('Project', 'PHPCensor')->getByGroupId($this->getId(), false);
}
}

View file

@ -48,12 +48,19 @@ class ProjectStore extends ProjectStoreBase
/**
* Get a list of all projects, ordered by their title.
*
* @param boolean $archived
*
* @return array
*/
public function getAll()
public function getAll($archived = false)
{
$query = 'SELECT * FROM `project` ORDER BY `title` ASC';
$stmt = Database::getConnection('read')->prepare($query);
$archived = (integer)$archived;
$query = 'SELECT * FROM `project` WHERE `archived` = :archived ORDER BY `title` ASC';
$stmt = Database::getConnection('read')->prepare($query);
$stmt->bindValue(':archived', $archived);
if ($stmt->execute()) {
$res = $stmt->fetchAll(\PDO::FETCH_ASSOC);
@ -74,21 +81,28 @@ class ProjectStore extends ProjectStoreBase
/**
* Get multiple Project by GroupId.
* @param int $value
* @param int $limit
* @param string $useConnection
*
* @param integer $value
* @param boolean $archived
* @param integer $limit
* @param string $useConnection
*
* @return array
*
* @throws \Exception
*/
public function getByGroupId($value, $limit = 1000, $useConnection = 'read')
public function getByGroupId($value, $archived = false, $limit = 1000, $useConnection = 'read')
{
if (is_null($value)) {
throw new \Exception('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$archived = (integer)$archived;
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id AND `archived` = :archived ORDER BY title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$query = 'SELECT * FROM `project` WHERE `group_id` = :group_id ORDER BY title LIMIT :limit';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':group_id', $value);
$stmt->bindValue(':archived', $archived);
$stmt->bindValue(':limit', (int)$limit, \PDO::PARAM_INT);
if ($stmt->execute()) {

View file

@ -15,9 +15,11 @@
</a>
<div class="pull-right btn-group">
<a class="btn btn-success" href="<?php print APP_URL . 'project/build/' . $project->getId(); ?><?php echo !empty($branch) ? '/' . urlencode($branch) : '' ?>">
<?php Lang::out('build_now'); ?>
</a>
<?php if (!$project->getArchived()): ?>
<a class="btn btn-success" href="<?php print APP_URL . 'project/build/' . $project->getId(); ?><?php echo !empty($branch) ? '/' . urlencode($branch) : '' ?>">
<?php Lang::out('build_now'); ?>
</a>
<?php endif; ?>
<div class="btn-group branch-btn pull-right">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">

View file

@ -173,53 +173,47 @@
<?php endif; ?>
<?php foreach ($groups as $group): ?>
<li class="treeview">
<a href="#">
<i class="fa fa-folder"></i>
<span><?php print $group['title']; ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<?php if (count($group['projects'])): ?>
<ul class="treeview-menu">
<?php foreach($group['projects'] as $project): ?>
<li>
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
<span><?php print $project->getTitle(); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
<li class="treeview">
<a href="#">
<i class="fa fa-folder"></i>
<span><?php print $group['title']; ?></span>
<i class="fa fa-archive"></i> <span><?php Lang::out('archived_menu'); ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<?php if (count($group['projects'])): ?>
<ul class="treeview-menu">
<?php foreach($group['projects'] as $project): ?>
<li>
<a href="<?php print APP_URL; ?>project/view/<?php print $project->getId(); ?>">
<i class="fa fa-<?php print $project->getIcon(); ?>"></i>
<span><?php print $project->getTitle(); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php if (isset($nav)): ?>
<li class="treeview">
<a href="#">
<i class="fa fa-<?php print $nav['icon']; ?>"></i>
<span><?php print $nav['title']; ?></span>
<i class="fa fa-angle-left pull-right"></i>
</a>
<?php if (count($archived_projects)): ?>
<ul class="treeview-menu">
<?php foreach ($nav['links'] as $link => $linkTitle): ?>
<?php foreach($archived_projects as $archived_project): ?>
<li>
<a href="<?php print APP_URL . $link; ?>">
<i class="fa fa-angle-double-right"></i> <?php print $linkTitle; ?>
<a href="<?php print APP_URL; ?>project/view/<?= $archived_project->getId(); ?>">
<i class="fa fa-<?= $archived_project->getIcon(); ?>"></i>
<span><?= $archived_project->getTitle(); ?></span>
</a>
</li>
<?php endforeach; ?>
</ul>
</li>
<?php endif; ?>
<li class="archive<?php print (array_key_exists('archived', $_GET) ? ' active' : ''); ?>">
<a href="<?php print APP_URL . (array_key_exists('archived', $_GET) ? '' : '?archived'); ?>">
<i class="fa fa-archive"></i> <span><?php Lang::out('archived_menu'); ?></span>
</a>
<?php endif; ?>
</li>
</ul>