1
0

update extgitgraph

This commit is contained in:
Mike Schwörer 2020-03-05 18:20:27 +01:00
parent e91fc7b61a
commit a7fe74504b
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
5 changed files with 59 additions and 10 deletions

View File

@ -6,6 +6,8 @@ require_once 'Utils.php';
class EGGDatabase class EGGDatabase
{ {
const DB_NAME = "";
/** @var string */ /** @var string */
private $path; private $path;
@ -67,7 +69,9 @@ class EGGDatabase
public function sql_query_assoc(string $query) public function sql_query_assoc(string $query)
{ {
return $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC); $r = $this->pdo->query($query)->fetchAll(PDO::FETCH_ASSOC);
return $r;
} }
public function sql_query_assoc_prep(string $query, array $params) public function sql_query_assoc_prep(string $query, array $params)
@ -80,7 +84,9 @@ class EGGDatabase
} }
$stmt->execute(); $stmt->execute();
return $stmt->fetchAll(PDO::FETCH_ASSOC); $r = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $r;
} }
public function sql_exec_prep(string $query, array $params) public function sql_exec_prep(string $query, array $params)
@ -202,10 +208,15 @@ class EGGDatabase
{ {
$strparents = implode(";", $commit->Parents); $strparents = implode(";", $commit->Parents);
$this->sql_exec_prep("INSERT INTO commits ([branch_id], [hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:brid, :sha, :an, :am, :cn, :cm, :msg, :dat, :prt)", $this->sql_exec_prep("INSERT INTO commits ([branch_id], [hash]) VALUES (:brid, :sha)",
[ [
[":brid", $branch->ID, PDO::PARAM_INT], [":brid", $branch->ID, PDO::PARAM_INT],
[":sha", $commit->Hash, PDO::PARAM_STR], [":sha", $commit->Hash, PDO::PARAM_STR],
]);
$this->sql_exec_prep("INSERT OR IGNORE INTO metadata ([hash], [author_name], [author_email], [committer_name], [committer_email], [message], [date], [parent_commits]) VALUES (:sha, :an, :am, :cn, :cm, :msg, :dat, :prt)",
[
[":sha", $commit->Hash, PDO::PARAM_STR],
[":an", $commit->AuthorName, PDO::PARAM_STR], [":an", $commit->AuthorName, PDO::PARAM_STR],
[":am", $commit->AuthorEmail, PDO::PARAM_STR], [":am", $commit->AuthorEmail, PDO::PARAM_STR],
[":cn", $commit->CommitterName, PDO::PARAM_STR], [":cn", $commit->CommitterName, PDO::PARAM_STR],
@ -320,6 +331,15 @@ class EGGDatabase
} }
} }
public function deleteDanglingCommitdata(string $name)
{
$db = $this->sql_query_assoc_prep("SELECT metadata.hash FROM metadata LEFT JOIN commits WHERE commits.hash IS NULL", []);
if (count($db) === 0) return;
$this->logger->proclog("Delete ".count($db)." dangling commits [" . $name . "] from database (no longer linked)");
}
/** /**
* @param string $source * @param string $source
* @param string $name * @param string $name
@ -416,7 +436,7 @@ class EGGDatabase
*/ */
public function getAllYears(): array public function getAllYears(): array
{ {
$rows = $this->sql_query_assoc("SELECT d FROM (SELECT cast(strftime('%Y', commits.date) as decimal) AS d FROM commits) GROUP BY d ORDER BY d"); $rows = $this->sql_query_assoc("SELECT d FROM (SELECT cast(strftime('%Y', metadata.date) as decimal) AS d FROM commits LEFT JOIN metadata ON commits.hash = metadata.hash) GROUP BY d ORDER BY d");
$r = []; $r = [];
foreach ($rows as $row) $r []= $row['d']; foreach ($rows as $row) $r []= $row['d'];
return $r; return $r;

View File

@ -84,8 +84,6 @@ class SessionLogger implements ILogger
{ {
if (session_status() === PHP_SESSION_DISABLED) return; if (session_status() === PHP_SESSION_DISABLED) return;
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
$_SESSION[$this->sessionvar] .= $text . "\r\n"; $_SESSION[$this->sessionvar] .= $text . "\r\n";
session_commit(); session_commit();
} }

View File

@ -53,6 +53,8 @@ abstract class StandardGitConnection implements IRemoteSource
$repos = $this->listAndUpdateRepositories($db); $repos = $this->listAndUpdateRepositories($db);
$anyChanged = false;
foreach ($repos as $repo) foreach ($repos as $repo)
{ {
$branches = $this->listAndUpdateBranches($db, $repo); $branches = $this->listAndUpdateBranches($db, $repo);
@ -83,6 +85,12 @@ abstract class StandardGitConnection implements IRemoteSource
} }
if ($repo_changed) $db->setChangeDateOnRepository($repo); if ($repo_changed) $db->setChangeDateOnRepository($repo);
if ($repo_changed) $anyChanged = true;
}
if ($anyChanged)
{
$db->deleteDanglingCommitdata($this->name);
} }
$this->postUpdate(); $this->postUpdate();

View File

@ -26,7 +26,14 @@ CREATE TABLE "commits"
( (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
"branch_id" INTEGER NOT NULL, "branch_id" INTEGER NOT NULL,
"hash" TEXT NOT NULL, "hash" TEXT NOT NULL
);
/*----SPLIT----*/
CREATE TABLE "metadata"
(
"hash" TEXT NOT NULL PRIMARY KEY UNIQUE,
"author_name" TEXT NOT NULL, "author_name" TEXT NOT NULL,
"author_email" TEXT NOT NULL, "author_email" TEXT NOT NULL,
"committer_name" TEXT NOT NULL, "committer_name" TEXT NOT NULL,
@ -35,3 +42,18 @@ CREATE TABLE "commits"
"date" TEXT NOT NULL, "date" TEXT NOT NULL,
"parent_commits" TEXT NOT NULL "parent_commits" TEXT NOT NULL
); );
/*----SPLIT----*/
CREATE VIEW alldata AS
SELECT
metadata.[date], commits.hash,
metadata.author_name, metadata.author_email, metadata.committer_name, metadata.committer_email, metadata.message, metadata.parent_commits,
repositories.source, repositories.name AS repository,
branches.name AS branch,
repositories.url,
repositories.last_update, repositories.last_change
FROM commits
LEFT JOIN metadata ON commits.hash = metadata.hash
LEFT JOIN branches ON commits.branch_id = branches.id
LEFT JOIN repositories ON branches.repo_id = repositories.id

View File

@ -1,9 +1,10 @@
SELECT commitdate AS commitdate, COUNT(*) as count FROM SELECT commitdate AS commitdate, COUNT(*) as count FROM
( (
SELECT SELECT
[hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate commits.[hash] AS hash, min([author_email]) AS mail1, min([committer_email]) AS mail2, date(min([date])) AS commitdate
FROM COMMITS FROM commits
GROUP BY hash LEFT JOIN metadata ON commits.hash = metadata.hash
GROUP BY commits.[hash]
HAVING (strftime('%Y', commitdate) = :year AND (/*{INDETITY_COND}*/)) HAVING (strftime('%Y', commitdate) = :year AND (/*{INDETITY_COND}*/))
) )
GROUP BY commitdate GROUP BY commitdate