BranchMerger: log change author

fixes #2606
This commit is contained in:
Thomas Gelf 2022-09-21 08:50:45 +02:00
parent e4fdb02de8
commit 05de5b171b
3 changed files with 26 additions and 2 deletions

View File

@ -33,6 +33,7 @@ v1.10.0 (unreleased)
### Configuration Branches
* FEATURE: merge comments can now be proposed (#2604)
* FEATURE: activity log now shows author and committer (#2606)
### Integrations
* FIX: Monitoring Hooks are no longer provided with disable Director UI (#2597)

View File

@ -85,7 +85,8 @@ class BranchMerger
*/
public function merge($comment = null)
{
$this->connection->runFailSafeTransaction(function () use ($comment) {
$username = DirectorActivityLog::username();
$this->connection->runFailSafeTransaction(function () use ($comment, $username) {
$formerActivityId = (int) DirectorActivityLog::loadLatest($this->connection)->get('id');
$query = $this->db->select()
->from(BranchActivity::DB_TABLE)
@ -94,6 +95,10 @@ class BranchMerger
$rows = $this->db->fetchAll($query);
foreach ($rows as $row) {
$activity = BranchActivity::fromDbRow($row);
$author = $activity->getAuthor();
if ($username !== $author) {
DirectorActivityLog::overrideUsername("$author/$username");
}
$this->applyModification($activity);
}
(new BranchStore($this->connection))->deleteByUuid($this->branchUuid);
@ -109,6 +114,7 @@ class BranchMerger
]);
}
});
DirectorActivityLog::restoreUsername();
}
/**

View File

@ -41,6 +41,9 @@ class DirectorActivityLog extends DbObject
'parent_checksum'
];
/** @var ?string */
protected static $overriddenUsername = null;
/**
* @param $name
*
@ -59,8 +62,12 @@ class DirectorActivityLog extends DbObject
return $this->reallySet('object_name', $name);
}
protected static function username()
public static function username()
{
if (self::$overriddenUsername) {
return self::$overriddenUsername;
}
if (Icinga::app()->isCli()) {
return 'cli';
}
@ -212,4 +219,14 @@ class DirectorActivityLog extends DbObject
Logger::info('(director) ' . implode(' ', $log));
}
public static function overrideUsername($username)
{
self::$overriddenUsername = $username;
}
public static function restoreUsername()
{
self::$overriddenUsername = null;
}
}