1
0
Fork 0

update extgitgraph

This commit is contained in:
Mike Schwörer 2020-04-22 11:24:48 +02:00
parent a7fe74504b
commit 058ea5695a
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
7 changed files with 93 additions and 12 deletions

View File

@ -7,6 +7,19 @@ require_once (__DIR__ . '/../internals/website.php');
set_time_limit(900); // 15min
$SITE->modules->ExtendedGitGraph()->update();
$SITE->modules->ExtendedGitGraph()->updateCache();
$r1 = $SITE->modules->ExtendedGitGraph()->update();
if (!$r1)
{
http_response_code(500);
echo 'EGG::update failed.';
}
$r2 = $SITE->modules->ExtendedGitGraph()->updateCache();
if (!$r2)
{
http_response_code(500);
echo 'EGG::updateCache failed.';
}
http_response_code(200);
echo 'Done.';

View File

@ -45,6 +45,26 @@ class EGGDatabase
if(!$exists) $this->init();
}
public function openReadOnly()
{
$this->open();
}
public function beginTransaction()
{
$this->pdo->beginTransaction();
}
public function commitTransaction()
{
$this->pdo->commit();
}
public function abortTransactionIfExists()
{
if ($this->pdo !== null) $this->pdo->rollBack();
}
private function init()
{
$this->logger->proclog("Initialize new database '" . $this->path . "'");
@ -133,7 +153,7 @@ class EGGDatabase
[":url", $url, PDO::PARAM_STR],
]);
if (count($repo) === 0) throw new Exception("No repo after insert [" . $source . "|" . $name . "]");
if (count($repo) === 0) throw new EGGException("No repo after insert [" . $source . "|" . $name . "]");
$this->logger->proclog("Inserted (new) repository [" . $source . "|" . $name . "] into database");
}
@ -180,7 +200,7 @@ class EGGDatabase
[":nam", $name, PDO::PARAM_STR],
]);
if (count($branch) === 0) throw new Exception("No branch after insert [" . $source . "|" . $repo->Name . "|" . $name . "]");
if (count($branch) === 0) throw new EGGException("No branch after insert [" . $source . "|" . $repo->Name . "|" . $name . "]");
$this->logger->proclog("Inserted (new) branch [" . $source . "|" . $repo->Name . "|" . $name . "] into database");
}

14
www/extern/egg/EGGException.php vendored Normal file
View File

@ -0,0 +1,14 @@
<?php
class EGGException extends Exception
{
public $egg_message;
public function __construct($message)
{
parent::__construct($message);
$this->egg_message = $message;
}
}

View File

@ -1,6 +1,7 @@
<?php
require_once 'Logger.php';
require_once 'EGGException.php';
require_once 'RemoteSource.php';
require_once 'OutputGenerator.php';
require_once 'EGGDatabase.php';
@ -43,9 +44,9 @@ class ExtendedGitGraph2 implements ILogger
else if ($rmt['type'] === 'gitea')
$newsrc = new GiteaConnection($this, $rmt['name'], $rmt['url'], $rmt['filter'], $rmt['exclusions'], $rmt['username'], $rmt['password'] );
else
throw new Exception("Unknown remote-type: " . $rmt['type']);
throw new EGGException("Unknown remote-type: " . $rmt['type']);
if (array_key_exists($newsrc->getName(), $sourcenames)) throw new Exception("Duplicate source name: " . $newsrc->getName());
if (array_key_exists($newsrc->getName(), $sourcenames)) throw new EGGException("Duplicate source name: " . $newsrc->getName());
$this->sources []= $newsrc;
$sourcenames []= $newsrc->getName();
@ -61,6 +62,7 @@ class ExtendedGitGraph2 implements ILogger
try
{
$this->db->open();
$this->db->beginTransaction();
$this->proclog("Start incremental data update");
$this->proclog();
@ -78,7 +80,21 @@ class ExtendedGitGraph2 implements ILogger
$this->proclog("Update finished.");
$this->db->commitTransaction();
$this->proclog("Data written.");
$this->db->close();
return true;
}
catch (EGGException $exception)
{
$this->proclog("ExtendedGitGraph2::update failed:");
$this->proclog($exception->egg_message);
$this->db->abortTransactionIfExists();
return false;
}
catch (Exception $exception)
{
@ -87,14 +103,19 @@ class ExtendedGitGraph2 implements ILogger
$this->proclog($exception->getMessage());
$this->proclog();
$this->proclog($exception->getTraceAsString());
$this->db->abortTransactionIfExists();
return false;
}
}
public function updateCache(): string
public function updateCache(): ?string
{
try
{
$this->db->open();
$this->db->openReadOnly();
$this->db->beginTransaction();
$this->proclog("Start update cache");
$this->proclog();
@ -106,6 +127,15 @@ class ExtendedGitGraph2 implements ILogger
return $data;
}
catch (EGGException $exception)
{
$this->proclog("ExtendedGitGraph2::updateCache failed:");
$this->proclog($exception->egg_message);
$this->db->abortTransactionIfExists();
return null;
}
catch (Exception $exception)
{
$this->proclog("(!) FATAL ERROR -- UNCAUGHT EXCEPTION THROWN");
@ -113,6 +143,8 @@ class ExtendedGitGraph2 implements ILogger
$this->proclog($exception->getMessage());
$this->proclog();
$this->proclog($exception->getTraceAsString());
return null;
}
}
@ -123,10 +155,12 @@ class ExtendedGitGraph2 implements ILogger
{
try
{
$this->db->open();
$this->db->openReadOnly();
$data = $this->outputter->loadFromCache();
$this->db->close();
return $data;
}
catch (Exception $exception)

View File

@ -379,13 +379,13 @@ class GithubConnection extends StandardGitConnection
$url = Utils::sharpFormat(self::URL_OAUTH_TOKEN, ['id'=>$this->oauth_id, 'secret'=>$this->oauth_secret, 'code'=>'egg']);
$fullresult = $result = file_get_contents($url);
if (Utils::startsWith($fullresult, 'error=')) throw new EGGException('GitHub Auth failed: ' . $fullresult);
$result = str_replace('access_token=', '', $result);
$result = str_replace('&scope=&token_type=bearer', '', $result);
$this->logger->proclog("Updated Github API token");
if (Utils::startsWith($result, "error=")) throw new Exception($fullresult);
if ($result!=='' && $result !== null && $this->apitokenpath !== null)
file_put_contents($this->apitokenpath, $result);

View File

@ -136,7 +136,7 @@ class Utils
{
$logger->proclog("Error recieving json: '" . $url . "'");
$logger->proclog(print_r(error_get_last(), true));
return [];
throw new EGGException("Error recieving json: '" . $url . "'");
}
return json_decode($response);

0
www/protected/vendor/.gitkeep vendored Normal file
View File