31
0
mirror of https://github.com/joomla-extensions/patchtester.git synced 2024-06-03 14:10:47 +00:00

Changed parameter of revert from db_id to pull_id. Configured resetController to remove first all git patches and then revert all ci patches in order of patchChain.

This commit is contained in:
datsepp 2019-09-12 09:04:05 +02:00
parent 4f301b2636
commit a321ad0d2f
3 changed files with 46 additions and 13 deletions

View File

@ -13,6 +13,7 @@ use Joomla\CMS\Filesystem\Folder;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\Filesystem\File;
use PatchTester\Helper;
use PatchTester\Model\PullModel;
use PatchTester\Model\PullsModel;
use PatchTester\Model\TestsModel;
@ -41,9 +42,23 @@ class ResetController extends AbstractController
$pullsModel = new PullsModel($this->context, null, Factory::getDbo());
$testsModel = new TestsModel(null, Factory::getDbo());
// Get the CIServer Registry
$ciSettings = Helper::initializeCISettings();
// Get PatchChain as array, remove any EOL set by php
$patchChainPath = $ciSettings->get('folder.backups') . '/' . $ciSettings->get('zip.chain.name');
$patchChain = array_reverse(explode(PHP_EOL, file_get_contents($patchChainPath)));
// Check the applied patches in the database first
$appliedPatches = $testsModel->getAppliedPatches();
if (count($patchChain) && count($appliedPatches))
{
// Get only the pull_id and remove all occurrences with patchChain
$appliedPatches = array_map(function($patch) { return $patch->pull_id; }, $appliedPatches);
$appliedPatches = array_diff($appliedPatches, $patchChain);
}
if (count($appliedPatches))
{
$revertErrored = false;
@ -53,32 +68,50 @@ class ResetController extends AbstractController
{
try
{
$pullModel->revert($patch->id);
$pullModel->revertWithGitHub($patch);
}
catch (\RuntimeException $e)
{
$revertErrored = true;
}
}
}
// If we errored out reverting patches, we'll need to truncate the table
if ($revertErrored)
if (count($patchChain))
{
$revertErrored = false;
// Let's try to cleanly revert all applied patches with ci
foreach ($patchChain as $patch)
{
try
{
$testsModel->truncateTable();
$pullModel->revertWithCIServer($patch);
}
catch (\RuntimeException $e)
{
$hasErrors = true;
$this->getApplication()->enqueueMessage(
Text::sprintf('COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE', $e->getMessage()), 'error'
);
$revertErrored = true;
}
}
}
// If we errored out reverting patches, we'll need to truncate the table
if ($revertErrored)
{
try
{
$testsModel->truncateTable();
}
catch (\RuntimeException $e)
{
$hasErrors = true;
$this->getApplication()->enqueueMessage(
Text::sprintf('COM_PATCHTESTER_ERROR_TRUNCATING_PULLS_TABLE', $e->getMessage()), 'error'
);
}
}
// Now truncate the pulls table
try
{

View File

@ -615,7 +615,7 @@ class PullModel extends AbstractModel
* @since 3.0
* @throws \RuntimeException
*/
private function revertWithCIServer($id)
public function revertWithCIServer($id)
{
// Get the CIServer Registry
$ciSettings = Helper::initializeCISettings();
@ -714,7 +714,7 @@ class PullModel extends AbstractModel
* @since 2.0
* @throws \RuntimeException
*/
private function revertWithGitHub($id)
public function revertWithGitHub($id)
{
$testRecord = $this->getTestRecord($id);
@ -861,7 +861,7 @@ class PullModel extends AbstractModel
$db->getQuery(true)
->select('*')
->from('#__patchtester_tests')
->where('id = ' . (int) $id)
->where('pull_id = ' . (int) $id)
)->loadObject();
}
}

View File

@ -63,7 +63,7 @@ foreach ($this->items as $i => $item) :
</td>
<td class="text-center">
<?php if ($item->applied) : ?>
<button type="button" class="btn btn-sm btn-success submitPatch" data-task="revert-<?php echo (int) $item->applied; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
<button type="button" class="btn btn-sm btn-success submitPatch" data-task="revert-<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_REVERT_PATCH'); ?></button>
<?php else : ?>
<button type="button" class="btn btn-sm btn-primary submitPatch" data-task="apply-<?php echo (int) $item->pull_id; ?>"><?php echo Text::_('COM_PATCHTESTER_APPLY_PATCH'); ?></button>
<?php endif; ?>