mirror of
https://github.com/joomla-extensions/patchtester.git
synced 2024-12-23 03:19:00 +00:00
Remove the patch chain Fixed #234
This commit is contained in:
parent
34e4271a71
commit
ab56101511
@ -31,7 +31,7 @@ class ResetController extends AbstractController
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function execute()
|
||||
public function execute(): void
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -43,12 +43,12 @@ class ResetController extends AbstractController
|
||||
$testsModel = new TestsModel(null, Factory::getDbo());
|
||||
|
||||
// Check the applied patches in the database first
|
||||
$appliedPatches = $pullModel->getPatchesDividedInProcs();
|
||||
$appliedPatches = $testsModel->getAppliedPatches();
|
||||
|
||||
if (count($appliedPatches['git']))
|
||||
{
|
||||
// Let's try to cleanly revert all applied patches
|
||||
foreach ($appliedPatches['git'] as $patch)
|
||||
foreach ($appliedPatches as $patch)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -250,7 +250,7 @@ class PullModel extends AbstractModel
|
||||
{
|
||||
Folder::delete($tempPath);
|
||||
|
||||
Folder::move($backupsPath, $backupsPath . "_failed");
|
||||
Folder::move($backupsPath, $backupsPath . '_failed');
|
||||
throw new RuntimeException(
|
||||
Text::sprintf('COM_PATCHTESTER_FAILED_APPLYING_PATCH', $file, $exception->getMessage())
|
||||
);
|
||||
@ -260,10 +260,7 @@ class PullModel extends AbstractModel
|
||||
// Clear temp folder and store applied patch in database
|
||||
Folder::delete($tempPath);
|
||||
|
||||
$lastInserted = $this->saveAppliedPatch($id, $files, $sha);
|
||||
|
||||
// Write or create patch chain for correct order of patching
|
||||
$this->appendPatchChain($lastInserted, $id);
|
||||
$this->saveAppliedPatch($id, $files, $sha);
|
||||
|
||||
// Remove the autoloader file
|
||||
if (file_exists(JPATH_CACHE . '/autoload_psr4.php'))
|
||||
@ -375,30 +372,6 @@ class PullModel extends AbstractModel
|
||||
return $insertId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a value to the patch chain in the database
|
||||
*
|
||||
* @param integer $insertId ID of the patch in the database
|
||||
* @param integer $pullId ID of the pull request
|
||||
*
|
||||
* @return integer $insertId last inserted element
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private function appendPatchChain(int $insertId, int $pullId): int
|
||||
{
|
||||
$record = (object) array(
|
||||
'insert_id' => $insertId,
|
||||
'pull_id' => $pullId,
|
||||
);
|
||||
|
||||
$db = $this->getDb();
|
||||
|
||||
$db->insertObject('#__patchtester_chain', $record);
|
||||
|
||||
return $db->insertid();
|
||||
}
|
||||
|
||||
/**
|
||||
* Patches the code with the supplied pull request
|
||||
*
|
||||
@ -697,42 +670,6 @@ class PullModel extends AbstractModel
|
||||
return $this->revertWithGitHub($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a chain by specific value, returns the last
|
||||
* element on $id = -1 and the first on $id = null
|
||||
*
|
||||
* @param integer $id specific id of a pull
|
||||
*
|
||||
* @return stdClass $chain last chain of the table
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private function getPatchChain(int $id = null): stdClass
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
$query = $db->getQuery(true)
|
||||
->select('*')
|
||||
->from('#__patchtester_chain');
|
||||
|
||||
if ($id !== null && $id !== -1)
|
||||
{
|
||||
$query = $query->where('insert_id =' . $id);
|
||||
}
|
||||
|
||||
if ($id === -1)
|
||||
{
|
||||
$query = $query->order('id DESC');
|
||||
}
|
||||
|
||||
if ($id === null)
|
||||
{
|
||||
$query = $query->order('id ASC');
|
||||
}
|
||||
|
||||
return $db->setQuery($query, 0, 1)->loadObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverts the specified pull request with CIServer options
|
||||
*
|
||||
@ -750,19 +687,6 @@ class PullModel extends AbstractModel
|
||||
|
||||
$testRecord = $this->getTestRecord($id);
|
||||
|
||||
// Get PatchChain as array, remove any EOL set by php
|
||||
$patchChain = $this->getPatchChain(-1);
|
||||
|
||||
// Allow only reverts in order of the patch chain
|
||||
if ((int) $patchChain->insert_id !== $id)
|
||||
{
|
||||
throw new RuntimeException(
|
||||
Text::sprintf('COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN', $patchChain->pull_id)
|
||||
);
|
||||
}
|
||||
|
||||
$this->removeLastChain($patchChain->insert_id);
|
||||
|
||||
// We don't want to restore files from an older version
|
||||
if ($testRecord->applied_version !== JVERSION)
|
||||
{
|
||||
@ -864,26 +788,6 @@ class PullModel extends AbstractModel
|
||||
)->loadObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the last value of the chain
|
||||
*
|
||||
* @param integer $insertId ID of the patch in the database
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
private function removeLastChain(int $insertId): void
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete('#__patchtester_chain')
|
||||
->where('insert_id = ' . (int) $insertId)
|
||||
)->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the database record for a test
|
||||
*
|
||||
@ -1039,51 +943,4 @@ class PullModel extends AbstractModel
|
||||
|
||||
return $this->removeTest($testRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a two dimensional array with applied patches
|
||||
* by the github or ci procedure
|
||||
*
|
||||
* @return array two-dimensional array with github patches
|
||||
* and ci patches
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
public function getPatchesDividedInProcs(): array
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
$appliedByGit = $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('tests.id, tests.pull_id')
|
||||
->from('#__patchtester_tests tests')
|
||||
->leftJoin('#__patchtester_chain chain', 'tests.id = chain.insert_id')
|
||||
->where('chain.insert_id IS NULL')
|
||||
)->loadObjectList('pull_id');
|
||||
|
||||
$appliedByCI = $this->getPatchChains();
|
||||
|
||||
return array('git' => $appliedByGit, 'ci' => $appliedByCI);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a list of patches in chain
|
||||
*
|
||||
* @return array List of pull IDs
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
private function getPatchChains(): array
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select('*')
|
||||
->from($db->quoteName('#__patchtester_chain'))
|
||||
->order('id DESC')
|
||||
);
|
||||
|
||||
return $db->loadObjectList('pull_id');
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,11 @@ class TestsModel extends AbstractModel
|
||||
/**
|
||||
* Retrieves a list of applied patches
|
||||
*
|
||||
* @return mixed
|
||||
* @return array List of applied patches
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function getAppliedPatches()
|
||||
public function getAppliedPatches(): array
|
||||
{
|
||||
$db = $this->getDb();
|
||||
|
||||
@ -43,7 +43,7 @@ class TestsModel extends AbstractModel
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public function truncateTable()
|
||||
public function truncateTable(): void
|
||||
{
|
||||
$this->getDb()->truncateTable('#__patchtester_tests');
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ class PullsHtmlView extends DefaultHtmlView
|
||||
$this->envErrors[] = Text::_('COM_PATCHTESTER_REQUIREMENT_OPENSSL');
|
||||
}
|
||||
|
||||
if (!in_array('https', stream_get_wrappers()))
|
||||
if (!in_array('https', stream_get_wrappers(), true))
|
||||
{
|
||||
$this->envErrors[] = Text::_('COM_PATCHTESTER_REQUIREMENT_HTTPS');
|
||||
}
|
||||
@ -123,7 +123,7 @@ class PullsHtmlView extends DefaultHtmlView
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
protected function addToolbar()
|
||||
protected function addToolbar(): void
|
||||
{
|
||||
ToolbarHelper::title(Text::_('COM_PATCHTESTER'), 'patchtester icon-apply');
|
||||
|
||||
|
@ -85,7 +85,6 @@ COM_PATCHTESTER_NO_CREDENTIALS="In den Optionen wurden noch keine Benutzerdaten
|
||||
COM_PATCHTESTER_NO_FILES_TO_PATCH="Es sind keine Dateien aus diesem Pull Request zu patchen. Dies kann bedeuten, dass die Dateien des Pull Requests in Ihrer Installation nicht vorhanden sind."
|
||||
COM_PATCHTESTER_NO_ITEMS="Es wurden noch keine Daten von Github abgerufen. Klicken Sie auf 'Daten abrufen' um die aktuellen Daten von Github zu holen."
|
||||
COM_PATCHTESTER_NOT_APPLIED="Nicht angewendet"
|
||||
COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="Der Patch kann nicht zurückgesetzt werden, es muss zunächst erstmal der Patch mit der Pull ID %s zurückgesetzt werden."
|
||||
COM_PATCHTESTER_NOT_RTC="Nicht RTC"
|
||||
COM_PATCHTESTER_PULL_ID="Pull-ID"
|
||||
COM_PATCHTESTER_PULL_ID_ASC="Pull-ID aufsteigend"
|
||||
|
@ -84,7 +84,6 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th
|
||||
COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation."
|
||||
COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests."
|
||||
COM_PATCHTESTER_NOT_APPLIED="Not Applied"
|
||||
COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first."
|
||||
COM_PATCHTESTER_NOT_RTC="Not RTC"
|
||||
COM_PATCHTESTER_PULL_ID="Pull ID"
|
||||
COM_PATCHTESTER_PULL_ID_ASC="Pull ID ascending"
|
||||
|
@ -85,7 +85,6 @@ COM_PATCHTESTER_NO_CREDENTIALS="You have not entered your user credentials in th
|
||||
COM_PATCHTESTER_NO_FILES_TO_PATCH="There are no files to patch from this pull request. This may mean that the files in the pull request are not present in your installation."
|
||||
COM_PATCHTESTER_NO_ITEMS="No data has been retrieved from GitHub, please click the 'Fetch Data' button in the toolbar to retrieve the open pull requests."
|
||||
COM_PATCHTESTER_NOT_APPLIED="Not Applied"
|
||||
COM_PATCHTESTER_NOT_IN_ORDER_OF_PATCHCHAIN="You can't revert this patch, you need to revert the patch with the pull id %s first."
|
||||
COM_PATCHTESTER_NOT_RTC="Not RTC"
|
||||
COM_PATCHTESTER_PULL_ID="Pull ID"
|
||||
COM_PATCHTESTER_PULL_ID_ASC="Pull ID ascending"
|
||||
|
Loading…
Reference in New Issue
Block a user