2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2014-05-12 18:26:17 +02:00
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
|
|
|
* @copyright Copyright 2014, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link https://www.phptesting.org/
|
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
|
|
|
|
namespace PHPCI\Model;
|
|
|
|
|
|
|
|
use PHPCI\Model\Base\ProjectBase;
|
2013-05-17 17:10:54 +02:00
|
|
|
use PHPCI\Model\Build;
|
|
|
|
use b8\Store;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
|
|
|
/**
|
2013-05-16 03:30:48 +02:00
|
|
|
* Project Model
|
2013-05-16 16:40:40 +02:00
|
|
|
* @uses PHPCI\Model\Base\ProjectBase
|
2013-05-16 03:30:48 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
|
|
|
* @package PHPCI
|
|
|
|
* @subpackage Core
|
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
class Project extends ProjectBase
|
|
|
|
{
|
2013-05-17 17:10:54 +02:00
|
|
|
public function getLatestBuild($branch = 'master', $status = null)
|
|
|
|
{
|
|
|
|
$criteria = array('branch' => $branch, 'project_id' => $this->getId());
|
|
|
|
|
|
|
|
if (isset($status)) {
|
|
|
|
$criteria['status'] = $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
$order = array('id' => 'DESC');
|
2013-05-17 17:24:17 +02:00
|
|
|
$builds = Store\Factory::getStore('Build')->getWhere($criteria, 1, 0, array(), $order);
|
2013-05-17 17:10:54 +02:00
|
|
|
|
|
|
|
if (is_array($builds['items']) && count($builds['items'])) {
|
|
|
|
$latest = array_shift($builds['items']);
|
|
|
|
|
|
|
|
if (isset($latest) && $latest instanceof Build) {
|
|
|
|
return $latest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2014-02-26 16:23:24 +01:00
|
|
|
|
2014-07-30 16:13:50 +02:00
|
|
|
public function setAccessInformation($value)
|
|
|
|
{
|
|
|
|
if (is_array($value)) {
|
|
|
|
$value = json_encode($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::setAccessInformation($value);
|
|
|
|
}
|
|
|
|
|
2014-02-26 16:23:24 +01:00
|
|
|
public function getAccessInformation($key = null)
|
|
|
|
{
|
2014-07-30 16:13:50 +02:00
|
|
|
$info = $this->data['access_information'];
|
|
|
|
|
|
|
|
// Handle old-format (serialized) access information first:
|
|
|
|
if (!empty($info) && substr($info, 0, 1) != '{') {
|
|
|
|
$data = unserialize($info);
|
|
|
|
} else {
|
|
|
|
$data = json_decode($info, true);
|
|
|
|
}
|
2014-02-26 16:23:24 +01:00
|
|
|
|
|
|
|
if (is_null($key)) {
|
|
|
|
$rtn = $data;
|
|
|
|
} elseif (isset($data[$key])) {
|
|
|
|
$rtn = $data[$key];
|
|
|
|
} else {
|
|
|
|
$rtn = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $rtn;
|
|
|
|
}
|
2014-07-14 15:59:04 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of Branch / branch.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getBranch()
|
|
|
|
{
|
|
|
|
if (empty($this->data['branch'])) {
|
|
|
|
return $this->getType() === 'hg' ? 'default' : 'master';
|
|
|
|
} else {
|
|
|
|
return $this->data['branch'];
|
|
|
|
}
|
|
|
|
}
|
2014-12-02 17:26:55 +01:00
|
|
|
|
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
switch ($this->getType()) {
|
|
|
|
case 'github':
|
|
|
|
$icon = 'github';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'bitbucket':
|
|
|
|
$icon = 'bitbucket';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'git':
|
|
|
|
case 'gitlab':
|
|
|
|
$icon = 'git';
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
$icon = 'cog';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $icon;
|
|
|
|
}
|
2013-05-03 17:02:53 +02:00
|
|
|
}
|