Fixed fetching data
Signed-off-by: Roland Dalmulder <contact@rolandd.com>
This commit is contained in:
parent
96b8480c51
commit
c1b1209f63
|
@ -47,7 +47,7 @@ class FetchController extends BaseController
|
||||||
try {
|
try {
|
||||||
$page = $session->get('com_patchtester_fetcher_page', 1);
|
$page = $session->get('com_patchtester_fetcher_page', 1);
|
||||||
/** @var PullsModel $model */
|
/** @var PullsModel $model */
|
||||||
$model = $this->app->bootComponent('com_patchtester')->getMVCFactory()->createModel('Pulls', 'Administrator', ['ignore_request' => true]);
|
$model = $this->app->bootComponent('com_patchtester')->getMVCFactory()->createModel('Pulls', 'Administrator');
|
||||||
|
|
||||||
$status = $model->requestFromGithub($page);
|
$status = $model->requestFromGithub($page);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use Joomla\Registry\Registry;
|
||||||
*/
|
*/
|
||||||
trait GithubCredentialsTrait
|
trait GithubCredentialsTrait
|
||||||
{
|
{
|
||||||
protected function getCredentials() {
|
protected function getCredentials(): Registry {
|
||||||
$state = new Registry();
|
$state = new Registry();
|
||||||
$params = ComponentHelper::getParams('com_patchtester');
|
$params = ComponentHelper::getParams('com_patchtester');
|
||||||
$state->set('github_user', $params->get('org', 'joomla'));
|
$state->set('github_user', $params->get('org', 'joomla'));
|
||||||
|
|
|
@ -142,16 +142,16 @@ class PullModel extends BaseDatabaseModel
|
||||||
{
|
{
|
||||||
// Get the CIServer Registry
|
// Get the CIServer Registry
|
||||||
$ciSettings = Helper::initializeCISettings();
|
$ciSettings = Helper::initializeCISettings();
|
||||||
// Get the Github object
|
// Get the Github object
|
||||||
$github = Helper::initializeGithub();
|
$github = Helper::initializeGithub();
|
||||||
// Retrieve pullData for sha later on.
|
// Retrieve pullData for sha later on.
|
||||||
$pull = $this->retrieveGitHubData($github, $id);
|
$pull = $this->retrieveGitHubData($github, $id);
|
||||||
if ($pull->head->repo === null) {
|
if ($pull->head->repo === null) {
|
||||||
throw new RuntimeException(Text::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
throw new RuntimeException(Text::_('COM_PATCHTESTER_REPO_IS_GONE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$sha = $pull->head->sha;
|
$sha = $pull->head->sha;
|
||||||
// Create tmp folder if it does not exist
|
// Create tmp folder if it does not exist
|
||||||
if (!file_exists($ciSettings->get('folder.temp'))) {
|
if (!file_exists($ciSettings->get('folder.temp'))) {
|
||||||
Folder::create($ciSettings->get('folder.temp'));
|
Folder::create($ciSettings->get('folder.temp'));
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ class PullModel extends BaseDatabaseModel
|
||||||
$delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name');
|
$delLogPath = $tempPath . '/' . $ciSettings->get('zip.log.name');
|
||||||
$zipPath = $tempPath . '/' . $ciSettings->get('zip.name');
|
$zipPath = $tempPath . '/' . $ciSettings->get('zip.name');
|
||||||
$serverZipPath = sprintf($ciSettings->get('zip.url'), $id);
|
$serverZipPath = sprintf($ciSettings->get('zip.url'), $id);
|
||||||
// Patch has already been applied
|
// Patch has already been applied
|
||||||
if (file_exists($backupsPath)) {
|
if (file_exists($backupsPath)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ class PullModel extends BaseDatabaseModel
|
||||||
'userAgent',
|
'userAgent',
|
||||||
$version->getUserAgent('Joomla', true, false)
|
$version->getUserAgent('Joomla', true, false)
|
||||||
);
|
);
|
||||||
// Try to download the zip file
|
// Try to download the zip file
|
||||||
try {
|
try {
|
||||||
$http = HttpFactory::getHttp($httpOption);
|
$http = HttpFactory::getHttp($httpOption);
|
||||||
$result = $http->get($serverZipPath);
|
$result = $http->get($serverZipPath);
|
||||||
|
@ -191,9 +191,9 @@ class PullModel extends BaseDatabaseModel
|
||||||
|
|
||||||
// Assign to variable to avlod PHP notice "Indirect modification of overloaded property"
|
// Assign to variable to avlod PHP notice "Indirect modification of overloaded property"
|
||||||
$content = (string)$result->getBody();
|
$content = (string)$result->getBody();
|
||||||
// Write the file to disk
|
// Write the file to disk
|
||||||
File::write($zipPath, $content);
|
File::write($zipPath, $content);
|
||||||
// Check if zip folder could have been downloaded
|
// Check if zip folder could have been downloaded
|
||||||
if (!file_exists($zipPath)) {
|
if (!file_exists($zipPath)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST')
|
Text::_('COM_PATCHTESTER_ZIP_DOES_NOT_EXIST')
|
||||||
|
@ -211,9 +211,9 @@ class PullModel extends BaseDatabaseModel
|
||||||
|
|
||||||
// Remove zip to avoid get listing afterwards
|
// Remove zip to avoid get listing afterwards
|
||||||
File::delete($zipPath);
|
File::delete($zipPath);
|
||||||
// Verify the composer autoloader for any invalid entries
|
// Verify the composer autoloader for any invalid entries
|
||||||
if ($this->verifyAutoloader($tempPath) === false) {
|
if ($this->verifyAutoloader($tempPath) === false) {
|
||||||
// There is something broken in the autoloader, clean up and go back
|
// There is something broken in the autoloader, clean up and go back
|
||||||
Folder::delete($tempPath);
|
Folder::delete($tempPath);
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
Text::_('COM_PATCHTESTER_PATCH_BREAKS_SITE')
|
Text::_('COM_PATCHTESTER_PATCH_BREAKS_SITE')
|
||||||
|
@ -233,7 +233,7 @@ class PullModel extends BaseDatabaseModel
|
||||||
$files = str_replace(Path::clean($tempPath . '\\'), '', $files);
|
$files = str_replace(Path::clean($tempPath . '\\'), '', $files);
|
||||||
$files = array_merge($files, $deletedFiles);
|
$files = array_merge($files, $deletedFiles);
|
||||||
Folder::create($backupsPath);
|
Folder::create($backupsPath);
|
||||||
// Moves existent files to backup and replace them or creates new one if they don't exist
|
// Moves existent files to backup and replace them or creates new one if they don't exist
|
||||||
foreach ($files as $key => $file) {
|
foreach ($files as $key => $file) {
|
||||||
try {
|
try {
|
||||||
$filePath = explode(DIRECTORY_SEPARATOR, Path::clean($file));
|
$filePath = explode(DIRECTORY_SEPARATOR, Path::clean($file));
|
||||||
|
@ -246,7 +246,7 @@ class PullModel extends BaseDatabaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(JPATH_ROOT . '/' . $file)) {
|
if (file_exists(JPATH_ROOT . '/' . $file)) {
|
||||||
// Create directories if they don't exist until file
|
// Create directories if they don't exist until file
|
||||||
if (!file_exists($backupsPath . '/' . $filePath)) {
|
if (!file_exists($backupsPath . '/' . $filePath)) {
|
||||||
Folder::create($backupsPath . '/' . $filePath);
|
Folder::create($backupsPath . '/' . $filePath);
|
||||||
}
|
}
|
||||||
|
@ -258,7 +258,7 @@ class PullModel extends BaseDatabaseModel
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists($tempPath . '/' . $file)) {
|
if (file_exists($tempPath . '/' . $file)) {
|
||||||
// Create directories if they don't exist until file
|
// Create directories if they don't exist until file
|
||||||
if (!file_exists(JPATH_ROOT . '/' . $filePath)
|
if (!file_exists(JPATH_ROOT . '/' . $filePath)
|
||||||
|| !is_dir(
|
|| !is_dir(
|
||||||
JPATH_ROOT . '/' . $filePath
|
JPATH_ROOT . '/' . $filePath
|
||||||
|
@ -288,9 +288,9 @@ class PullModel extends BaseDatabaseModel
|
||||||
// Clear temp folder and store applied patch in database
|
// Clear temp folder and store applied patch in database
|
||||||
Folder::delete($tempPath);
|
Folder::delete($tempPath);
|
||||||
$this->saveAppliedPatch($id, $files, $sha);
|
$this->saveAppliedPatch($id, $files, $sha);
|
||||||
// Update the autoloader file
|
// Update the autoloader file
|
||||||
$this->namespaceMapper->create();
|
$this->namespaceMapper->create();
|
||||||
// Change the media version
|
// Change the media version
|
||||||
$version = new Version();
|
$version = new Version();
|
||||||
$version->refreshMediaVersion();
|
$version->refreshMediaVersion();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue