update extgitgraph
This commit is contained in:
parent
a7fe74504b
commit
058ea5695a
@ -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.';
|
24
www/extern/egg/EGGDatabase.php
vendored
24
www/extern/egg/EGGDatabase.php
vendored
@ -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
14
www/extern/egg/EGGException.php
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
|
||||
class EGGException extends Exception
|
||||
{
|
||||
public $egg_message;
|
||||
|
||||
public function __construct($message)
|
||||
{
|
||||
parent::__construct($message);
|
||||
|
||||
$this->egg_message = $message;
|
||||
}
|
||||
}
|
44
www/extern/egg/ExtendedGitGraph2.php
vendored
44
www/extern/egg/ExtendedGitGraph2.php
vendored
@ -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)
|
||||
|
4
www/extern/egg/RemoteSource.php
vendored
4
www/extern/egg/RemoteSource.php
vendored
@ -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);
|
||||
|
||||
|
2
www/extern/egg/Utils.php
vendored
2
www/extern/egg/Utils.php
vendored
@ -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
0
www/protected/vendor/.gitkeep
vendored
Normal file
Loading…
Reference in New Issue
Block a user