From: Paul J R Date: Tue, 2 Oct 2012 00:07:04 +0000 (+1000) Subject: Activity log is now working X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=b35dc95efeb3c44390afc4eaa0aa295949ef2f9e;p=gwvp-mini.git Activity log is now working --- diff --git a/bin/gwvpminicmdtool.php b/bin/gwvpminicmdtool.php index 1b53265..c42c8bf 100644 --- a/bin/gwvpminicmdtool.php +++ b/bin/gwvpminicmdtool.php @@ -13,8 +13,12 @@ else $noconfig = true; if(file_exists("$WEB_ROOT_FS/../gwvpmini/gwvpmini.php")) require_once("$WEB_ROOT_FS/../gwvpmini/gwvpmini.php"); else if(file_exists("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php")) require_once("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php"); -if(isset($argv["1"])) { - switch($argv["1"]) { + +echo "ARGS: ".print_r($argv,true); +echo "CWD: ".getcwd()."\n"; + +if(isset($argv["3"])) { + switch($argv["3"]) { case "update": gwvpcmdtool_UpdateHook(); break; @@ -28,13 +32,39 @@ if(isset($argv["1"])) { return; +/* + * remote: ARGS: Array +remote: ( +remote: [0] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php +remote: [1] => asfd +remote: [2] => admin +remote: [3] => pre-receive +remote: [4] => fc781c4ef5bfeae8ec01bb527db1b6ce6f65d03c +remote: [5] => 7d45d43f04276fc9addb77ba8bf753329eab018d +remote: [6] => refs/heads/master +remote: ) +remote: ARGS: Array +remote: ( +remote: [0] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php +remote: [1] => asfd +remote: [2] => admin +remote: [3] => pre-receive +remote: [4] => /nfs/export/src/local/eclipse-workspace/gwvp-mini/bin/gwvpminicmdtool.php +remote: [5] => asfd +remote: [6] => admin +remote: [7] => update +remote: [8] => refs/heads/master +remote: [9] => fc781c4ef5bfeae8ec01bb527db1b6ce6f65d03c +remote: [10] => 7d45d43f04276fc9addb77ba8bf753329eab018d + + */ + function gwvpcmdtool_Usage() { global $argv; - echo "Usage: ".$argv[0]."\n"; - echo "\tupdatehook \n"; + echo "Usage: ".$argv[0]." this tool should not be called directly by user\n"; } @@ -43,15 +73,20 @@ function gwvpcmdtool_UpdateHook() { global $argv; //echo "got ".$argv[2].", ".$argv[3].", ".$argv[4]."\n"; - if(preg_match("/^000000+$/", $argv[3])) { + if(preg_match("/^000000+$/", $argv[5])) { // createion of tag or branch - $vals = explode("/", $argv[2]); + $vals = explode("/", $argv[4]); $type = "unknowncreate"; - if($vals == "heads") $type = "branchcreate"; - if($vals == "tags") $type = "tagcreate"; - gwvpmini_AddActivityLog("$type", "1", "1", $argv[4], "somelogs"); + if($vals[1] == "heads") $type = "branchcreate"; + if($vals[1] == "tags") $type = "tagcreate"; + + //gwvpmini_AddRefActivityForRepo(); + gwvpmini_AddRefActivityForRepo($argv[1], $argv[2], $vals[2], $type); + echo "REFSUP: ".$vals[2].", $type\n"; + } //gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog) + //gwvpmini_AddRefActivityForRepo($reponame, $byusername, $branchname, $acttype="branch") } // pre-receive logs all commit info @@ -61,6 +96,44 @@ function gwvpcmdtool_PreReceive() //echo "got from prereceive ".$argv[2].", ".$argv[3].", ".$argv[4]."\n"; - //passthru("git rev-list --reverse ".$argv[3]." --not --all "); + $lns = 0; + $ref = $argv[6]; + + $regspl = explode("/", $ref); + $branch = $regspl[2]; + + $fp = popen("git rev-list --reverse ".$argv[5]." --not --all ", "r"); + if($fp) while(!feof($fp)) { + $line = trim(fgets($fp)); + if($line != "") { + $cdd[$lns] = gwvpcmdtool_getCommitIdDetails($line); + echo "FORCID $line we get \n".print_r($cdd[$lns], true); + gwvpmini_AddCommitActivityForRepo($argv[1], $argv[2], $line, $cdd[$lns]["log"], $branch); + $lns++; + } + } + + + //echo "Called git rev-list --reverse ".$argv[5]." --not --all\n\n"; + //gwvpmini_AddCommitActivityForRepo($reponame, $byusername, $commitid, $desc) +} + +function gwvpcmdtool_getCommitIdDetails($commitid) +{ + $rs = popen("git log --pretty=format:\"%at%n%ce%n%an%n%s\" $commitid -1 2> /dev/null", "r"); + $ret = array(); + if($rs) { + $ret["date"] = trim(fgets($rs)); + $ret["email"] = trim(fgets($rs)); + $ret["fullname"] = trim(fgets($rs)); + $ret["log"] = ""; + while(!feof($rs)) { + $ret["log"] .= fread($rs, 8192); + } + } else { + $ret = false; + } + + return $ret; } ?> \ No newline at end of file diff --git a/gwvpmini/gwvpmini_activity.php b/gwvpmini/gwvpmini_activity.php index 4f07fc5..107cb48 100644 --- a/gwvpmini/gwvpmini_activity.php +++ b/gwvpmini/gwvpmini_activity.php @@ -1,4 +1,8 @@ $val) { + if($key!="b") $st .= "$key:"; + } + return $st; } // gets the activity log as it would be viewed by // the user id of "$forid" -function gwvpmini_GetActivityLogFor($forid) +function gwvpmini_HomePageActivityLog() +{ + global $BASE_URL; + + $id = $_SESSION["id"]; + + if($id < 0) { + $ents = gwvpmini_GetActivityLog(); + } else { + $ents = gwvpmini_GetActivityLog(20, $id); + } + + echo "

News

"; + echo ""; + foreach($ents as $vals) { + /* + * $ret[$nent]["type"] = $vals["activity_type"]; + $ret[$nent]["date"] = $vals["activity_date"]; + $ret[$nent]["userid"] = $vals["activity_user"]; + $ret[$nent]["repoid"] = $vals["activity_repo"]; + $ret[$nent]["commitid"] = $vals["activity_commitid"]; + $ret[$nent]["commitlog"] = $vals["activitiy_commitlog"]; + + */ + $type = $vals["type"]; + //$rest = $vals["date"].", ".$vals["userid"].", ".$vals["repoid"].", ".$vals["commitid"].", ".$vals["commitlog"]; + + if($vals["type"] == "commit") { + $udets = gwvpmini_getUser(null, null, $vals["userid"]); + $rdets = gwvpmini_getRepo(null, null, $vals["repoid"]); + $reponame = $rdets["name"]; + $uname = $udets["username"]; + $fname = $udets["fullname"]; + $br_spl = explode(":", $vals["commitid"]); + $branch = $br_spl[0]; + $cid = $br_spl[1]; + $compressedcid = gwvpmini_CompressCommitId($cid); + $log = $vals["commitlog"]; + $tdiff = gwvpmini_TimeDiffText($vals["date"]); + $col1 = "$reponame
".gwvpmini_HtmlGravatar($udets["email"], 30, "
")."$uname"; + $col2 = $tdiff."
Commited change $compressedcid
$log

"; + } else if($vals["type"] == "refs") { + $udets = gwvpmini_getUser(null, null, $vals["userid"]); + $rdets = gwvpmini_getRepo(null, null, $vals["repoid"]); + $reponame = $rdets["name"]; + $uname = $udets["username"]; + $fname = $udets["fullname"]; + $tdiff = gwvpmini_TimeDiffText($vals["date"]); + $tp_spl = explode(":", $vals["commitid"]); + $col1 = "$reponame
".gwvpmini_HtmlGravatar($udets["email"], 30, "
")."$uname"; + if($tp_spl[0] == "tagcreate") { + $colapp = "$tdiff
Created Tag ".$tp_spl[1].""; + } else if($tp_spl[0] == "branchcreate") { + $colapp = "$tdiff
Created Branch ".$tp_spl[1].""; + } else { + $colapp = "$tdiff
Performed some unknown action."; + } + $col2 = $colapp; + + } + + echo "$col1$col2"; + } + echo ""; +} + +function gwvpmini_TimeDiffText($time) { + $tdiff = time() - $time; + if($tdiff < 10) return "Now"; + if($tdiff < 60) return "$tdiff Seconds Ago"; + if($tdiff < 3600) return "".(int)($tdiff/60)." Minutes Ago"; + if($tdiff < 86400) return "".(int)($tdiff/3600)." Hours Ago"; + return "".(int)($tdiff/86400)." Days Ago"; } ?> \ No newline at end of file diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index 0f11ec9..82abfda 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -55,6 +55,46 @@ function gwvpmini_getUser($username=null, $email=null, $id=null) } +function gwvpmini_GetActivityLog($nentries = 20, $forid=-1) +{ + /* + * "activity_id" INTEGER PRIMARY KEY AUTOINCREMENT, + "activity_type" TEXT, + "activity_date" TEXT, + "activity_user" TEXT, + "activity_repo" TEXT, + "activity_commitid" TEXT, + "activity_commitlog" TEXT, + "activity_visibleto" TEXT + + */ + $conn = gwvpmini_ConnectDB(); + + if($forid == -1) { + // we're searching for anonymous ones + $sql = "select * from activity where activity_visibleto='a' order by activity_date desc limit $nentries"; + } else { + $sql = "select * from activity where activity_visibleto='a' or activity_visibleto='r' or activity_visibleto like '%:$forid:%' order by activity_date desc limit $nentries"; + } + + $vls = $conn->query($sql); + + $nent = 0; + $ret = array(); + if($vls !== false) foreach($vls as $vals) { + $ret[$nent]["type"] = $vals["activity_type"]; + $ret[$nent]["date"] = $vals["activity_date"]; + $ret[$nent]["userid"] = $vals["activity_user"]; + $ret[$nent]["repoid"] = $vals["activity_repo"]; + $ret[$nent]["commitid"] = $vals["activity_commitid"]; + $ret[$nent]["commitlog"] = $vals["activity_commitlog"]; + $nent++; + } + + if($nent == 0) return false; + else return $ret; +} + function gwvpmini_getRepo($ownerid=null, $name=null, $id=null) { @@ -431,31 +471,7 @@ function gwvpmini_AddUser($username, $password, $fullname, $email, $desc, $level return $retval; } -function gwvpmini_GetActivityLog($nentries = 100) -{ - $conn = gwvpmini_ConnectDB(); - - $sql = "select * from activity order by activity_date desc limit 100"; - - $res = $conn->query($sql); - - $logs = null; - $i = 0; - foreach($res as $row) { - $logs[$i]["type"] = $row["activity_type"]; - $logs[$i]["date"] = $row["activity_date"]; - $logs[$i]["userid"] = $row["activity_user"]; - $logs[$i]["repoid"] = $row["activity_repo"]; - $logs[$i]["commitid"] = $row["activity_commitid"]; - $logs[$i]["commitlog"] = $row["activity_commitlog"]; - $logs[$i]["visibleto"] = $row["activity_visibleto"]; - $i++; - } - - return $logs; -} - -function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog) +function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog, $visibleto="a") { /* * CREATE TABLE "activity" ( @@ -474,7 +490,7 @@ function gwvpmini_AddActivityLog($type, $userid, $repoid, $commitid, $commitlog) $conn = gwvpmini_ConnectDB(); // TODO: implement visibility - $visibleto = "a"; + //$visibleto = "a"; $sql = "insert into 'activity' values ( null, '$type', '".time()."', '$userid', '$repoid', '$commitid', '$commitlog', '$visibleto')"; diff --git a/gwvpmini/gwvpmini_gitbackend.php b/gwvpmini/gwvpmini_gitbackend.php index 4cb53b8..8e4dc5f 100644 --- a/gwvpmini/gwvpmini_gitbackend.php +++ b/gwvpmini/gwvpmini_gitbackend.php @@ -26,16 +26,15 @@ function gwvpmini_gitControlCallMe() } -function gwvpmini_CreateRepoHooks($repopath, $cmdpath) +function gwvpmini_CreateRepoHooks($repopath, $cmdpath, $reponame) { $fp = fopen("$repopath/hooks/pre-receive", "w"); - if(!$fp) // error_log("could not create pre-receive hook"); + if(!$fp) error_log("could not create pre-receive hook"); // TODO: think about this one - $script = '#!/bin/bash'."\n\n".'DCOMMIT=`cat`'."\n".'START=`echo $DCOMMIT|cut -d " " -f 1`'."\n".'END=`echo $DCOMMIT|cut -d " " -f 2`'."\n".'REF=`echo $DCOMMIT|cut -d " " -f 3`'."\n\n"; - $script .= "php $cmdpath pre-receive "; - $script .= '$START $END $REF'."\n\n"; + //$script = '#!/bin/bash'."\n\n".'DCOMMIT=`cat`'."\n".'START=`echo $DCOMMIT|cut -d " " -f 1`'."\n".'END=`echo $DCOMMIT|cut -d " " -f 2`'."\n".'REF=`echo $DCOMMIT|cut -d " " -f 3`'."\n\n"; + $script = "#!/bin/bash\n\nDCOMMIT=".'`cat`'."\n\nphp $cmdpath $reponame \$REMOTE_USER pre-receive \$DCOMMIT\n\n"; fwrite($fp, $script); fclose($fp); @@ -45,12 +44,11 @@ function gwvpmini_CreateRepoHooks($repopath, $cmdpath) $fp = fopen("$repopath/hooks/update", "w"); - if(!$fp) // error_log("could not create update hook"); + if(!$fp) error_log("could not create update hook"); // TODO: think about this one - $script = "#!/bin/bash\n\n"; - $script .= "php $cmdpath update "; - $script .= '$1 $2 $3'."\n\n"; + unset($script); + $script = "#!/bin/bash\n\nphp $cmdpath $reponame \$REMOTE_USER update \$1 \$2 \$3\n\n"; fwrite($fp, $script); fclose($fp); @@ -86,7 +84,7 @@ function gwvpmini_gitBackendInterface() // error_log("FLAP: donut hole"); }*/ - + error_log("REQUESTINBACKEND: ".print_r($_REQUEST, true)); $repo = ""; $repoid = false; @@ -113,7 +111,7 @@ function gwvpmini_gitBackendInterface() if(!file_exists("$repo_base/$repo.git/hooks/pre-receive") || !file_exists("$repo_base/$repo.git/hooks/update")) { // error_log("WRITING HOOKS"); - gwvpmini_CreateRepoHooks("$repo_base/$repo.git", $cmd_line_tool); + gwvpmini_CreateRepoHooks("$repo_base/$repo.git", $cmd_line_tool, $repo); } @@ -128,7 +126,7 @@ function gwvpmini_gitBackendInterface() $write = true; } } - + if(preg_match("/.*git-receive-pack$/", $_REQUEST["q"])) $write = true; //$write = true; // THIS MAY CAUSE ISSUES LATER ON but we do it cause the git client ignores our 403 when it uses git-receive-pack after an auth // no, this isnt a solution cause auth'd read attempts will come up as writes... @@ -182,8 +180,11 @@ function gwvpmini_gitBackendInterface() } // if its a write, we check (before and after) the branch/tag info to see if they were updated - //if($write) { - //} + if($write) { + error_log("REQUESTINBACKEND: processed as write"); + } else { + error_log("REQUESTINBACKEND: processed as read"); + } gwvpmini_callGitBackend($person, $repo); diff --git a/gwvpmini/gwvpmini_gitrepo.php b/gwvpmini/gwvpmini_gitrepo.php index edf8fd6..46c4f95 100644 --- a/gwvpmini/gwvpmini_gitrepo.php +++ b/gwvpmini/gwvpmini_gitrepo.php @@ -3,7 +3,7 @@ global $HOME_PAGE_PROVIDERS; $CALL_ME_FUNCTIONS["repoadmin"] = "gwvpmini_RepoCallMe"; -$HOME_PAGE_PROVIDERS["gitlog"] = "gwvpmini_GitLogProvider"; +$HOME_PAGE_PROVIDERS["00gitlog"] = "gwvpmini_GitLogProvider"; // the home_page_provders bit is an array @@ -169,15 +169,6 @@ function gwvpmini_GitLogProvider() echo ""; } } - - $logs = gwvpmini_GetActivityLog(); - if($logs !== null) { - echo "

Global Log

"; - foreach($logs as $ents) { - echo ""; - } - echo "
".$ents["type"]."".$ents["commitid"]."
"; - } } function gwvpmini_GitCreateRepoForm() @@ -281,5 +272,12 @@ function gwvpmini_RecursiveDelete($fpath) return @rmdir($fpath); } } + +function gwvpmini_CompressCommitId($cid) +{ + $compressedcid = substr($cid, 0, 5)."...".substr($cid, strlen($cid)-5, strlen($cid)); + + return $compressedcid; +} ?> \ No newline at end of file