mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2024-06-07 07:50:48 +00:00
Note if pulled patch is different than expected state (Fix #121)
This commit is contained in:
parent
d59e0227f5
commit
f7bd9029d3
|
@ -28,7 +28,7 @@ class ApplyController extends AbstractController
|
|||
{
|
||||
try
|
||||
{
|
||||
$model = new PullModel;
|
||||
$model = new PullModel($this->context, null, \JFactory::getDbo());
|
||||
|
||||
// Initialize the state for the model
|
||||
$model->setState($this->initializeState($model));
|
||||
|
@ -36,6 +36,19 @@ class ApplyController extends AbstractController
|
|||
if ($model->apply($this->getInput()->getUint('pull_id')))
|
||||
{
|
||||
$msg = \JText::_('COM_PATCHTESTER_APPLY_OK');
|
||||
|
||||
// Check if the SHA's were different and alert the user
|
||||
if ($model->getState()->get('pull.sha_different', false))
|
||||
{
|
||||
$this->getApplication()->enqueueMessage(
|
||||
\JText::sprintf(
|
||||
'COM_PATCHTESTER_DIFFERENT_SHA',
|
||||
substr($model->getState()->get('pull.state_sha'), 0, 10),
|
||||
substr($model->getState()->get('pull.applied_sha'), 0, 10)
|
||||
),
|
||||
'warning'
|
||||
);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -28,7 +28,7 @@ class RevertController extends AbstractController
|
|||
{
|
||||
try
|
||||
{
|
||||
$model = new PullModel;
|
||||
$model = new PullModel($this->context, null, \JFactory::getDbo());
|
||||
|
||||
// Initialize the state for the model
|
||||
$model->setState($this->initializeState($model));
|
||||
|
|
|
@ -17,7 +17,7 @@ use PatchTester\Helper;
|
|||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
class PullModel extends \JModelBase
|
||||
class PullModel extends \JModelDatabase
|
||||
{
|
||||
/**
|
||||
* Array containing top level non-production folders
|
||||
|
@ -179,6 +179,30 @@ class PullModel extends \JModelBase
|
|||
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
// Compare the pull's HEAD SHA to what patch tester has pulled; if it's newer set a flag
|
||||
try
|
||||
{
|
||||
$db = $this->getDb();
|
||||
$stateSha = $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('sha')
|
||||
->from($db->quoteName('#__patchtester_pulls'))
|
||||
->where($db->quoteName('pull_id') . ' = ' . (int) $id)
|
||||
)->loadResult();
|
||||
}
|
||||
catch (\RuntimeException $e)
|
||||
{
|
||||
// Not a fatal error, keep on truckin'
|
||||
$stateSha = false;
|
||||
}
|
||||
|
||||
if ($stateSha && $stateSha !== $pull->head->sha)
|
||||
{
|
||||
$this->getState()->set('pull.sha_different', true);
|
||||
$this->getState()->set('pull.applied_sha', $pull->head->sha);
|
||||
$this->getState()->set('pull.state_sha', $stateSha);
|
||||
}
|
||||
|
||||
$files = $this->parsePatch($patch);
|
||||
|
||||
if (!$files)
|
||||
|
|
|
@ -14,6 +14,7 @@ COM_PATCHTESTER_COMPONENT_LABEL="Joomla! Patch Tester"
|
|||
COM_PATCHTESTER_CONFIGURATION="Joomla! Patch Tester Settings"
|
||||
COM_PATCHTESTER_CONFLICT_S="The patch could not be applied because it conflicts with a previously applied patch: %s"
|
||||
COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB="Could not connect to GitHub: %s"
|
||||
COM_PATCHTESTER_DIFFERENT_SHA="The patch you've applied is in a different state than when data was last pulled from GitHub. Commit %1$s was expected however commit %2$s was applied."
|
||||
COM_PATCHTESTER_ERROR_APPLIED_PATCHES="Cannot fetch data from GitHub while there are applied patches. Please revert those patches before continuing."
|
||||
COM_PATCHTESTER_ERROR_CANNOT_COPY_FILE="Cannot copy source file %1$s to destination %2$s"
|
||||
COM_PATCHTESTER_ERROR_CANNOT_DELETE_FILE="Cannot delete file %s"
|
||||
|
|
Loading…
Reference in New Issue
Block a user