2014-05-03 23:48:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Patch testing component for the Joomla! CMS
|
|
|
|
*
|
2018-09-01 14:32:23 +00:00
|
|
|
* @copyright Copyright (C) 2011 - 2012 Ian MacLennan, Copyright (C) 2013 - 2018 Open Source Matters, Inc. All rights reserved.
|
2014-05-03 23:48:08 +00:00
|
|
|
* @license GNU General Public License version 2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace PatchTester\Model;
|
|
|
|
|
2020-11-28 16:09:53 +00:00
|
|
|
use Exception;
|
2019-08-28 01:20:49 +00:00
|
|
|
use Joomla\CMS\HTML\HTMLHelper;
|
|
|
|
use Joomla\CMS\Language\Text;
|
2020-11-28 16:09:53 +00:00
|
|
|
use Joomla\CMS\MVC\Model\ListModel;
|
2016-06-25 16:34:48 +00:00
|
|
|
use PatchTester\GitHub\Exception\UnexpectedResponse;
|
2014-05-03 23:48:08 +00:00
|
|
|
use PatchTester\Helper;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Model class for the pulls list view
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2020-11-28 16:09:53 +00:00
|
|
|
class PullsModel extends ListModel
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The object context
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected $context;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of fields the list can be sorted on
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2020-10-10 15:05:13 +00:00
|
|
|
protected $sortFields = array('pulls.pull_id', 'pulls.title');
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
/**
|
2020-11-28 16:09:53 +00:00
|
|
|
* Constructor.
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
2020-11-28 16:09:53 +00:00
|
|
|
* @param array $config An optional associative array of configuration settings.
|
|
|
|
*
|
|
|
|
* @since 4.0.0
|
|
|
|
* @throws Exception
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
*/
|
2020-11-28 16:09:53 +00:00
|
|
|
public function __construct($config = [])
|
|
|
|
{
|
|
|
|
$config = [];
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2020-11-28 16:09:53 +00:00
|
|
|
if (empty($config['filter_fields']))
|
|
|
|
{
|
|
|
|
$config['filter_fields'] = [
|
|
|
|
'applied',
|
|
|
|
'rtc',
|
|
|
|
'npm',
|
2021-10-31 09:41:15 +00:00
|
|
|
'draft',
|
2020-11-28 16:09:53 +00:00
|
|
|
'label',
|
|
|
|
'branch',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($config);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to get an array of data items.
|
|
|
|
*
|
|
|
|
* @return mixed An array of data items on success, false on failure.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function getItems()
|
|
|
|
{
|
|
|
|
$store = $this->getStoreId();
|
|
|
|
|
|
|
|
if (isset($this->cache[$store]))
|
|
|
|
{
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
$items = $this->getList(
|
|
|
|
$this->getListQueryCache(), $this->getStart(),
|
|
|
|
$this->getState()->get('list.limit')
|
|
|
|
);
|
2020-07-25 14:16:38 +00:00
|
|
|
|
2020-11-28 16:09:53 +00:00
|
|
|
$db = $this->getDbo();
|
2020-07-25 14:16:38 +00:00
|
|
|
$query = $db->getQuery(true)
|
|
|
|
->select($db->quoteName(['name', 'color']))
|
|
|
|
->from($db->quoteName('#__patchtester_pulls_labels'));
|
|
|
|
|
|
|
|
array_walk(
|
|
|
|
$items,
|
|
|
|
static function ($item) use ($db, $query) {
|
|
|
|
$query->clear('where');
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where(
|
|
|
|
$db->quoteName('pull_id') . ' = ' . $item->pull_id
|
|
|
|
);
|
2020-07-25 14:16:38 +00:00
|
|
|
$db->setQuery($query);
|
|
|
|
|
|
|
|
$item->labels = $db->loadObjectList();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->cache[$store] = $items;
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
return $this->cache[$store];
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
/**
|
|
|
|
* Method to get a store id based on the model configuration state.
|
|
|
|
*
|
|
|
|
* This is necessary because the model is used by the component and
|
|
|
|
* different modules that might need different sets of data or different
|
|
|
|
* ordering requirements.
|
|
|
|
*
|
|
|
|
* @param string $id An identifier string to generate the store id.
|
|
|
|
*
|
|
|
|
* @return string A store id.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function getStoreId($id = '')
|
|
|
|
{
|
|
|
|
// Add the list state to the store id.
|
|
|
|
$id .= ':' . $this->getState()->get('list.start');
|
|
|
|
$id .= ':' . $this->getState()->get('list.limit');
|
|
|
|
$id .= ':' . $this->getState()->get('list.ordering');
|
|
|
|
$id .= ':' . $this->getState()->get('list.direction');
|
|
|
|
|
|
|
|
return md5($this->context . ':' . $id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets an array of objects from the results of database query.
|
|
|
|
*
|
|
|
|
* @param \JDatabaseQuery|string $query The query.
|
|
|
|
* @param integer $limitstart Offset.
|
|
|
|
* @param integer $limit The number of records.
|
|
|
|
*
|
|
|
|
* @return array An array of results.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @throws RuntimeException
|
|
|
|
*/
|
|
|
|
protected function getList($query, $limitstart = 0, $limit = 0)
|
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
return $this->getDbo()->setQuery($query, $limitstart, $limit)
|
2020-10-10 15:05:13 +00:00
|
|
|
->loadObjectList();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to cache the last query constructed.
|
|
|
|
*
|
|
|
|
* This method ensures that the query is constructed only once for a given state of the model.
|
|
|
|
*
|
|
|
|
* @return \JDatabaseQuery A JDatabaseQuery object
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function getListQueryCache()
|
|
|
|
{
|
|
|
|
// Capture the last store id used.
|
|
|
|
static $lastStoreId;
|
|
|
|
|
|
|
|
// Compute the current store id.
|
|
|
|
$currentStoreId = $this->getStoreId();
|
|
|
|
|
|
|
|
// If the last store id is different from the current, refresh the query.
|
|
|
|
if ($lastStoreId != $currentStoreId || empty($this->query))
|
|
|
|
{
|
|
|
|
$lastStoreId = $currentStoreId;
|
|
|
|
$this->query = $this->getListQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->query;
|
|
|
|
}
|
|
|
|
|
2014-05-03 23:48:08 +00:00
|
|
|
/**
|
|
|
|
* Method to get a JDatabaseQuery object for retrieving the data set from a database.
|
|
|
|
*
|
|
|
|
* @return \JDatabaseQuery A JDatabaseQuery object to retrieve the data set.
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
protected function getListQuery()
|
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
$db = $this->getDbo();
|
2020-10-10 15:05:13 +00:00
|
|
|
$query = $db->getQuery(true);
|
|
|
|
$labelQuery = $db->getQuery(true);
|
|
|
|
|
|
|
|
$query->select('pulls.*')
|
|
|
|
->select($db->quoteName('tests.id', 'applied'))
|
|
|
|
->from($db->quoteName('#__patchtester_pulls', 'pulls'))
|
|
|
|
->leftJoin(
|
|
|
|
$db->quoteName('#__patchtester_tests', 'tests')
|
|
|
|
. ' ON ' . $db->quoteName('tests.pull_id') . ' = '
|
|
|
|
. $db->quoteName('pulls.pull_id')
|
|
|
|
);
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
$search = $this->getState()->get('filter.search');
|
|
|
|
|
|
|
|
if (!empty($search))
|
|
|
|
{
|
2015-12-17 16:39:55 +00:00
|
|
|
if (stripos($search, 'id:') === 0)
|
2015-12-05 17:03:23 +00:00
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where(
|
|
|
|
$db->quoteName('pulls.pull_id') . ' = ' . (int) substr(
|
|
|
|
$search, 3
|
|
|
|
)
|
|
|
|
);
|
2015-12-05 17:03:23 +00:00
|
|
|
}
|
2015-12-17 16:39:55 +00:00
|
|
|
elseif (is_numeric($search))
|
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where(
|
|
|
|
$db->quoteName('pulls.pull_id') . ' = ' . (int) $search
|
|
|
|
);
|
2015-12-17 16:39:55 +00:00
|
|
|
}
|
2015-12-05 17:03:23 +00:00
|
|
|
else
|
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where(
|
|
|
|
'(' . $db->quoteName('pulls.title') . ' LIKE ' . $db->quote(
|
|
|
|
'%' . $db->escape($search, true) . '%'
|
|
|
|
) . ')'
|
|
|
|
);
|
2015-12-05 17:03:23 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2015-02-22 23:44:35 +00:00
|
|
|
$applied = $this->getState()->get('filter.applied');
|
|
|
|
|
|
|
|
if (!empty($applied))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
2020-07-25 14:16:38 +00:00
|
|
|
$value = $applied === 'no' ? ' IS NULL' : ' = 1';
|
2015-02-22 23:44:35 +00:00
|
|
|
|
2020-10-15 10:33:57 +00:00
|
|
|
$query->where($db->quoteName('applied') . $value);
|
2015-02-22 23:44:35 +00:00
|
|
|
}
|
|
|
|
|
2017-04-22 16:55:17 +00:00
|
|
|
$branch = $this->getState()->get('filter.branch');
|
|
|
|
|
|
|
|
if (!empty($branch))
|
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where(
|
2021-10-30 19:12:04 +00:00
|
|
|
$db->quoteName('pulls.branch') . ' IN (' . implode(',', $db->quote($branch)) . ')'
|
2020-10-10 15:05:13 +00:00
|
|
|
);
|
2017-04-22 16:55:17 +00:00
|
|
|
}
|
|
|
|
|
2016-03-27 18:39:34 +00:00
|
|
|
$applied = $this->getState()->get('filter.rtc');
|
|
|
|
|
|
|
|
if (!empty($applied))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
2020-07-25 14:16:38 +00:00
|
|
|
$value = $applied === 'no' ? '0' : '1';
|
2016-03-27 18:39:34 +00:00
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where($db->quoteName('pulls.is_rtc') . ' = ' . $value);
|
2016-03-27 18:39:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 14:16:38 +00:00
|
|
|
$npm = $this->getState()->get('filter.npm');
|
|
|
|
|
|
|
|
if (!empty($npm))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
|
|
|
$value = $npm === 'no' ? '0' : '1';
|
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->where($db->quoteName('pulls.is_npm') . ' = ' . $value);
|
2020-07-25 14:16:38 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 09:41:15 +00:00
|
|
|
$draft = $this->getState()->get('filter.draft');
|
|
|
|
|
|
|
|
if (!empty($draft))
|
|
|
|
{
|
|
|
|
// Not applied patches have a NULL value, so build our value part of the query based on this
|
|
|
|
$value = $draft === 'no' ? '0' : '1';
|
|
|
|
|
|
|
|
$query->where($db->quoteName('pulls.is_draft') . ' = ' . $value);
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
$labels = $this->getState()->get('filter.label');
|
|
|
|
|
|
|
|
if (!empty($labels) && $labels[0] !== '')
|
|
|
|
{
|
|
|
|
$labelQuery
|
|
|
|
->select($db->quoteName('pulls_labels.pull_id'))
|
|
|
|
->select(
|
|
|
|
'COUNT(' . $db->quoteName('pulls_labels.name') . ') AS '
|
|
|
|
. $db->quoteName('labelCount')
|
|
|
|
)
|
|
|
|
->from(
|
|
|
|
$db->quoteName(
|
|
|
|
'#__patchtester_pulls_labels', 'pulls_labels'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
->where(
|
|
|
|
$db->quoteName('pulls_labels.name') . ' IN (' . implode(
|
|
|
|
',', $db->quote($labels)
|
|
|
|
) . ')'
|
|
|
|
)
|
|
|
|
->group($db->quoteName('pulls_labels.pull_id'));
|
|
|
|
|
|
|
|
$query->leftJoin(
|
2020-10-12 13:59:32 +00:00
|
|
|
'(' . $labelQuery->__toString() . ') AS ' . $db->quoteName(
|
2020-10-10 15:05:13 +00:00
|
|
|
'pulls_labels'
|
|
|
|
)
|
|
|
|
. ' ON ' . $db->quoteName('pulls_labels.pull_id') . ' = '
|
|
|
|
. $db->quoteName('pulls.pull_id')
|
|
|
|
)
|
|
|
|
->where(
|
|
|
|
$db->quoteName('pulls_labels.labelCount') . ' = ' . count(
|
|
|
|
$labels
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$ordering = $this->getState()->get('list.ordering', 'pulls.pull_id');
|
2019-08-28 00:44:51 +00:00
|
|
|
$direction = $this->getState()->get('list.direction', 'DESC');
|
2014-05-03 23:48:08 +00:00
|
|
|
|
|
|
|
if (!empty($ordering))
|
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$query->order(
|
|
|
|
$db->escape($ordering) . ' ' . $db->escape($direction)
|
|
|
|
);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-10-10 15:05:13 +00:00
|
|
|
* Retrieves the array of authorized sort fields
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
2020-10-10 15:05:13 +00:00
|
|
|
* @return array
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
2020-10-10 15:05:13 +00:00
|
|
|
public function getSortFields()
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
return $this->sortFields;
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to request new data from GitHub
|
|
|
|
*
|
2015-02-23 01:49:59 +00:00
|
|
|
* @param integer $page The page of the request
|
|
|
|
*
|
|
|
|
* @return array
|
2014-05-03 23:48:08 +00:00
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
* @throws \RuntimeException
|
|
|
|
*/
|
2015-02-23 01:49:59 +00:00
|
|
|
public function requestFromGithub($page)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
if ($page === 1)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->truncateTable('#__patchtester_pulls');
|
|
|
|
$this->getDbo()->truncateTable('#__patchtester_pulls_labels');
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
try
|
2015-02-22 22:59:02 +00:00
|
|
|
{
|
2015-02-23 01:49:59 +00:00
|
|
|
// TODO - Option to configure the batch size
|
2016-06-25 16:54:03 +00:00
|
|
|
$batchSize = 100;
|
|
|
|
|
2021-10-31 09:41:15 +00:00
|
|
|
$pullsResponse = Helper::initializeGithub()->getOpenPulls(
|
2020-07-26 18:00:05 +00:00
|
|
|
$this->getState()->get('github_user'),
|
|
|
|
$this->getState()->get('github_repo'),
|
|
|
|
$page,
|
|
|
|
$batchSize
|
2015-02-23 01:49:59 +00:00
|
|
|
);
|
2016-06-25 16:34:48 +00:00
|
|
|
|
|
|
|
$pulls = json_decode($pullsResponse->body);
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
2020-07-25 14:16:38 +00:00
|
|
|
catch (UnexpectedResponse $exception)
|
2015-02-22 22:59:02 +00:00
|
|
|
{
|
2020-07-26 18:00:05 +00:00
|
|
|
throw new \RuntimeException(
|
2020-10-10 15:05:13 +00:00
|
|
|
Text::sprintf(
|
|
|
|
'COM_PATCHTESTER_ERROR_GITHUB_FETCH',
|
2020-07-26 18:00:05 +00:00
|
|
|
$exception->getMessage()
|
|
|
|
),
|
|
|
|
$exception->getCode(),
|
|
|
|
$exception
|
|
|
|
);
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
2015-02-22 22:59:02 +00:00
|
|
|
|
2016-06-25 16:54:03 +00:00
|
|
|
// If this is page 1, let's check to see if we need to paginate
|
|
|
|
if ($page === 1)
|
|
|
|
{
|
|
|
|
// Default this to being a single page of results
|
|
|
|
$lastPage = 1;
|
|
|
|
|
2021-10-30 20:07:02 +00:00
|
|
|
if (isset($pullsResponse->headers['link']))
|
2016-06-25 16:54:03 +00:00
|
|
|
{
|
2021-10-30 20:07:02 +00:00
|
|
|
$linkHeader = $pullsResponse->headers['link'];
|
2017-04-22 17:09:19 +00:00
|
|
|
|
|
|
|
// The `joomla/http` 2.0 package uses PSR-7 Responses which has a different format for headers, check for this
|
|
|
|
if (is_array($linkHeader))
|
|
|
|
{
|
|
|
|
$linkHeader = $linkHeader[0];
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:05:13 +00:00
|
|
|
preg_match(
|
|
|
|
'/(\?page=[0-9]{1,3}&per_page=' . $batchSize
|
|
|
|
. '+>; rel=\"last\")/', $linkHeader, $matches
|
|
|
|
);
|
2016-06-25 16:54:03 +00:00
|
|
|
|
|
|
|
if ($matches && isset($matches[0]))
|
|
|
|
{
|
2020-10-10 15:05:13 +00:00
|
|
|
$pageSegment = str_replace(
|
|
|
|
'&per_page=' . $batchSize, '', $matches[0]
|
|
|
|
);
|
2016-06-25 16:54:03 +00:00
|
|
|
|
|
|
|
preg_match('/\d+/', $pageSegment, $pages);
|
|
|
|
$lastPage = (int) $pages[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 01:49:59 +00:00
|
|
|
// If there are no pulls to insert then bail, assume we're finished
|
2016-06-25 17:57:24 +00:00
|
|
|
if (count($pulls) === 0)
|
2014-05-03 23:48:08 +00:00
|
|
|
{
|
2020-07-25 14:16:38 +00:00
|
|
|
return ['complete' => true];
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2020-07-25 14:16:38 +00:00
|
|
|
$data = [];
|
|
|
|
$labels = [];
|
2015-02-22 22:59:02 +00:00
|
|
|
|
|
|
|
foreach ($pulls as $pull)
|
|
|
|
{
|
2021-10-31 09:41:15 +00:00
|
|
|
// Check if this PR is RTC and has a `PR-` branch label
|
|
|
|
$isRTC = false;
|
|
|
|
$isNPM = false;
|
|
|
|
$branch = $pull->base->ref;
|
2016-03-27 18:39:34 +00:00
|
|
|
|
2021-10-31 09:41:15 +00:00
|
|
|
foreach ($pull->labels as $label)
|
|
|
|
{
|
|
|
|
if (strtolower($label->name) === 'rtc')
|
2016-03-27 18:39:34 +00:00
|
|
|
{
|
2021-10-31 09:41:15 +00:00
|
|
|
$isRTC = true;
|
|
|
|
}
|
|
|
|
elseif (in_array(
|
|
|
|
strtolower($label->name),
|
|
|
|
['npm resource changed', 'composer dependency changed'],
|
|
|
|
true
|
|
|
|
))
|
|
|
|
{
|
|
|
|
$isNPM = true;
|
2016-03-27 18:39:34 +00:00
|
|
|
}
|
|
|
|
|
2021-10-31 09:41:15 +00:00
|
|
|
$labels[] = implode(
|
|
|
|
',',
|
|
|
|
[
|
|
|
|
(int) $pull->number,
|
|
|
|
$this->getDbo()->quote($label->name),
|
|
|
|
$this->getDbo()->quote($label->color),
|
|
|
|
]
|
|
|
|
);
|
2016-03-26 22:42:18 +00:00
|
|
|
}
|
2021-10-31 09:41:15 +00:00
|
|
|
|
|
|
|
// Build the data object to store in the database
|
|
|
|
$pullData = [
|
|
|
|
(int) $pull->number,
|
|
|
|
$this->getDbo()->quote(
|
|
|
|
HTMLHelper::_('string.truncate', $pull->title, 150)
|
|
|
|
),
|
|
|
|
$this->getDbo()->quote(
|
|
|
|
HTMLHelper::_('string.truncate', $pull->body, 100)
|
|
|
|
),
|
|
|
|
$this->getDbo()->quote($pull->html_url),
|
|
|
|
(int) $isRTC,
|
|
|
|
(int) $isNPM,
|
|
|
|
$this->getDbo()->quote($branch),
|
|
|
|
($pull->draft ? 1 : 0)
|
|
|
|
];
|
|
|
|
|
|
|
|
$data[] = implode(',', $pullData);
|
|
|
|
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
|
|
|
|
2016-06-25 17:57:24 +00:00
|
|
|
// If there are no pulls to insert then bail, assume we're finished
|
|
|
|
if (count($data) === 0)
|
|
|
|
{
|
|
|
|
return array('complete' => true);
|
|
|
|
}
|
|
|
|
|
2015-02-22 22:59:02 +00:00
|
|
|
try
|
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->setQuery(
|
|
|
|
$this->getDbo()->getQuery(true)
|
2020-10-10 08:52:20 +00:00
|
|
|
->insert('#__patchtester_pulls')
|
2020-10-10 15:05:13 +00:00
|
|
|
->columns(
|
|
|
|
['pull_id', 'title', 'description', 'pull_url',
|
2021-10-31 09:41:15 +00:00
|
|
|
'is_rtc', 'is_npm', 'branch', 'is_draft']
|
2020-10-10 15:05:13 +00:00
|
|
|
)
|
2020-10-10 08:52:20 +00:00
|
|
|
->values($data)
|
|
|
|
);
|
|
|
|
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->execute();
|
2015-02-22 22:59:02 +00:00
|
|
|
}
|
2020-07-25 14:16:38 +00:00
|
|
|
catch (\RuntimeException $exception)
|
2015-02-22 22:59:02 +00:00
|
|
|
{
|
2020-07-25 14:16:38 +00:00
|
|
|
throw new \RuntimeException(
|
|
|
|
Text::sprintf(
|
|
|
|
'COM_PATCHTESTER_ERROR_INSERT_DATABASE',
|
|
|
|
$exception->getMessage()
|
|
|
|
),
|
|
|
|
$exception->getCode(),
|
|
|
|
$exception
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-10 08:52:20 +00:00
|
|
|
if ($labels)
|
2020-07-25 14:16:38 +00:00
|
|
|
{
|
2020-10-10 08:52:20 +00:00
|
|
|
try
|
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->setQuery(
|
|
|
|
$this->getDbo()->getQuery(true)
|
2020-10-10 08:52:20 +00:00
|
|
|
->insert('#__patchtester_pulls_labels')
|
|
|
|
->columns(['pull_id', 'name', 'color'])
|
|
|
|
->values($labels)
|
|
|
|
);
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->execute();
|
2020-10-10 08:52:20 +00:00
|
|
|
}
|
|
|
|
catch (\RuntimeException $exception)
|
|
|
|
{
|
|
|
|
throw new \RuntimeException(
|
|
|
|
Text::sprintf(
|
|
|
|
'COM_PATCHTESTER_ERROR_INSERT_DATABASE',
|
|
|
|
$exception->getMessage()
|
|
|
|
),
|
|
|
|
$exception->getCode(),
|
|
|
|
$exception
|
|
|
|
);
|
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
2015-02-23 01:49:59 +00:00
|
|
|
|
2020-07-25 14:16:38 +00:00
|
|
|
return [
|
|
|
|
'complete' => false,
|
|
|
|
'page' => ($page + 1),
|
2020-10-10 15:05:13 +00:00
|
|
|
'lastPage' => $lastPage ?? false,
|
2020-07-25 14:16:38 +00:00
|
|
|
];
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 22:08:01 +00:00
|
|
|
/**
|
|
|
|
* Truncates the pulls table
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*
|
|
|
|
* @since 2.0
|
|
|
|
*/
|
|
|
|
public function truncateTable()
|
|
|
|
{
|
2020-11-28 16:09:53 +00:00
|
|
|
$this->getDbo()->truncateTable('#__patchtester_pulls');
|
2020-11-28 13:43:53 +00:00
|
|
|
}
|
2014-05-03 23:48:08 +00:00
|
|
|
}
|