Skip to content
Snippets Groups Projects

Added autocommit

Closed Pavel Vyskočil requested to merge github/fork/vyskocilpavel/EPTID_AutoCommit into EPTID_hack
2 files
+ 18
5
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 17
1
@@ -90,7 +90,7 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
$latest = array();
while (($idp = $this->arrayToIdp(fgetcsv($f))) !== false) {
if (isset($latest[$idp['entityid']])) {
if (!isset($latest[$idp['entityid']])) {
$latest[$idp['entityid']] = $idp;
} else {
if ($idp['timestamp'] > $latest[$idp['entityid']]['timestamp']) {
@@ -137,6 +137,8 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
function whitelistIdp($entityID, $reason = null)
{
$changedWhiteList = false;
$changedGreylist = false;
$wf = fopen($this->whitelistFile, 'a');
if (flock($wf, LOCK_EX)) {
$gf = fopen($this->greylistFile, 'c+');
@@ -144,6 +146,7 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
$idp = array(date('Y-m-d H:i:s'), $entityID, $reason);
fputcsv($wf, $idp);
$changedWhiteList = true;
$greylist = array();
while (($idp = $this->arrayToIdp(fgetcsv($gf))) !== false) {
@@ -157,6 +160,7 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
foreach ($greylist as $idp) {
fputcsv($gf, array_values($idp));
$changedGreylist = true;
}
fflush($wf);
@@ -172,6 +176,12 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
}
fclose($wf);
fclose($gf);
if ($changedWhiteList === true) {
$this->commit($this->whitelistFile, $entityID);
}
if ($changedGreylist === true){
$this->commit($this->greylistFile, $entityID);
}
}
@@ -215,4 +225,10 @@ class sspmod_perun_IdpListsServiceCsv implements sspmod_perun_IdpListsService
return $idp;
}
private function commit($file, $entityID){
$idpListsDir = dirname($file);
$fileName = basename($file);
shell_exec("cd $idpListsDir && git add $file && git commit -m\"Updated $fileName \n\n * Added record with entityId: $entityID to $fileName\"");
}
}
Loading