From: Paul J R Date: Thu, 25 Oct 2012 07:29:08 +0000 (+1100) Subject: added a message via db commit path X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=3849628899cd35b87f8908f240e09e1075176db4;p=gwvp-mini.git added a message via db commit path --- diff --git a/bin/gwvpminicmdtool.php b/bin/gwvpminicmdtool.php index 9781a8e..afc372a 100644 --- a/bin/gwvpminicmdtool.php +++ b/bin/gwvpminicmdtool.php @@ -78,6 +78,8 @@ function gwvpcmdtool_BackGroundClone() $repo_base = gwvpmini_getConfigVal("repodir"); + sleep(60); + $from = $argv[1]; $to = $argv[2]; echo "Would actually clone $from to $to in $data_directory\n"; diff --git a/gwvpmini/gwvpmini_db.php b/gwvpmini/gwvpmini_db.php index 88c7ee2..fc6babc 100644 --- a/gwvpmini/gwvpmini_db.php +++ b/gwvpmini/gwvpmini_db.php @@ -546,7 +546,16 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc) "repos_status" TEXT, "repos_origin" TEXT, UNIQUE(repos_name) - )'; + )'; + + $msgsql = ' + CREATE TABLE "messages" ( + "msgs_id" INTEGER PRIMARY KEY AUTOINCREMENT, + "msgs_type" TEXT, + "msgs_data" TEXT, + "msgs_to_id" TEXT + )'; + // this looks like null, , , user:|group:|authed|anon // where authed = any authenticated user, anon = everyone (logged in, not logged in, etc) @@ -591,7 +600,8 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc) $DB_CONNECTION->query($initialuser_user); $DB_CONNECTION->query($reposql); $DB_CONNECTION->query($configsql); - $DB_CONNECTION->query($activitysql); + $DB_CONNECTION->query($activitysql); + $DB_CONNECTION->query($msgsql); } function gwvpmini_getConfigVal($confname) @@ -695,6 +705,59 @@ function gwvpmini_GetRepoDescFromName($reponame) return $retval; } + +function gwvpmini_SendMessageByDb($type, $data, $forid) +{ + $conn = gwvpmini_ConnectDB(); + + $sql = "insert into messages values (null, '$type', '$data', '$forid')"; + + return $conn->query($sql); +} + +function gwvpmini_GetMessagesForId($uid) +{ + /* + * $msgsql = ' + CREATE TABLE "messages" ( + "msgs_id" INTEGER PRIMARY KEY AUTOINCREMENT, + "msgs_type" TEXT, + "msgs_data" TEXT, + "msgs_to_id" TEXT, + )'; + + */ + $conn = gwvpmini_ConnectDB(); + + $sql = "select * from messages where msgs_to_id='$uid'"; + // error_log("desc for name sql: $sql"); + + $res = $conn->query($sql); + + error_log("request message for uid, $uid with sql $sql"); + + $i = 0; + if(!$res) return 0; + foreach($res as $row) { + $retval[$i]["id"] = $row["msgs_id"]; + $retval[$i]["type"] = $row["msgs_type"]; + $retval[$i]["data"] = $row["msgs_data"]; + $i++; + } + + + return $retval; + +} + +function gwvpmini_DeleteMessagesById($mid) +{ + $conn = gwvpmini_ConnectDB(); + + $sql = "delete from messages where msgs_id='$mid'"; + + return $conn->query($sql); +} function gwvpmini_GetRepoOwnerDetailsFromName($reponame) { @@ -848,7 +911,7 @@ function gwvpmini_GetOwnedRepos($username) // error_log(print_r($row, true)); } - // error_log(print_r($retval, true)); + error_log(print_r($retval, true)); return $retval; } diff --git a/gwvpmini/gwvpmini_debug.php b/gwvpmini/gwvpmini_debug.php index 80cf2e0..cd70c6f 100644 --- a/gwvpmini/gwvpmini_debug.php +++ b/gwvpmini/gwvpmini_debug.php @@ -42,5 +42,13 @@ function gwvpmini_DebugPageBody() print_r(unserialize(base64_decode($perms))); echo ""; } + + echo "
Sending some messages for db
"; + gwvpmini_SendMessageByDb("info", "message 1", $_SESSION["id"]); + gwvpmini_SendMessageByDb("error", "message 1", $_SESSION["id"]); + gwvpmini_SendMessageByDb("info", "message 1", $_SESSION["id"]); + gwvpmini_SendMessageByDb("error", "message really really reallyrea rea asdf asdf asdf asdf asdf qwef asdf asdr qwef asdf qwef asdf asd fqwe fqs dfa sdf qwe fa sdf asd fq wef qdwf asdf qwe fa sdf asdf a ewfqa wesf awefqefd", $_SESSION["id"]); + gwvpmini_SendMessageByDb("info", "message 1 sdfg sdfgs fdg sdfg sdfg sdfg sdfg sdfg sdfgwqerg fb sdvbefd wqerg zsdafg asdfgargf aerg afg agfs qrgasg agf wergafgs sag arg arg asgd arg argsa garg aerg sad gf ar gfasdg asd aweg asasd", $_SESSION["id"]); + echo "done
"; } ?> \ No newline at end of file diff --git a/gwvpmini/gwvpmini_gitrepo.php b/gwvpmini/gwvpmini_gitrepo.php index d9d9fef..e20532e 100644 --- a/gwvpmini/gwvpmini_gitrepo.php +++ b/gwvpmini/gwvpmini_gitrepo.php @@ -55,6 +55,7 @@ function gwvpmini_RepoMainPageBody() if(gwvpmini_isLoggedIn()) { $repos = gwvpmini_GetOwnedRepos($_SESSION["username"]); + error_log("repos, ".print_r($repos, true)); if(!$repos) { echo "You currently own no repos
"; } else { @@ -63,26 +64,37 @@ function gwvpmini_RepoMainPageBody() foreach($repos as $repo) { $name = $repo["name"]; $desc = $repo["desc"]; + $stat = $repo["status"]; + $llog = ""; + if($stat != 0) { + switch($stat) { + case 1: + $llog = "Repo Administratively Disabled"; + break; + case 2: + $llog = "Repo Cloning from remote"; + break; + } + } else { - if($desc == "") $desc = "none"; - - $repo_base = gwvpmini_getConfigVal("repodir"); - $cmd = "git --git-dir=\"$repo_base/$name.git\" log --all -1 2> /dev/null"; - echo "$name$desc"; - echo ""; - // error_log("CMD: $cmd"); - //system("$cmd"); - $fls = popen($cmd, "r"); - $tks = ""; - if($fls !== false) while(!feof($fls)) { - $tks .= fread($fls,1024); + if($desc == "") $desc = "none"; + + $repo_base = gwvpmini_getConfigVal("repodir"); + $cmd = "git --git-dir=\"$repo_base/$name.git\" log --all -1 2> /dev/null"; + // error_log("CMD: $cmd"); + //system("$cmd"); + $fls = popen($cmd, "r"); + $tks = ""; + if($fls !== false) while(!feof($fls)) { + $tks .= fread($fls,1024); + } + + if($tks == "") { + $llog = "No Log Info Yet"; + } else $llog = $tks; + } - - if($tks == "") { - echo "No Log Info Yet"; - } else echo $tks; - echo ""; - echo ""; + echo "$name$desc$llog"; } echo ""; } @@ -97,20 +109,32 @@ function gwvpmini_RepoMainPageBody() foreach($contreps as $repo) { $name = $repo["name"]; $desc = $repo["desc"]; - $repo_base = gwvpmini_getConfigVal("repodir"); - $cmd = "git --git-dir=\"$repo_base/$name.git\" log --all -1 2> /dev/null"; - // error_log("CMD: $cmd"); - //system("$cmd"); - $fls = popen($cmd, "r"); - $tks = ""; - if($fls !== false) while(!feof($fls)) { - $tks .= fread($fls,1024); + $stat = $repo["status"]; + if($stat != 0) { + switch($stat) { + case 1: + $lastlog = "Repo Administratively Disabled"; + break; + case 2: + $lastlog = "Repo Cloning from remote"; + break; + } + } else { + $repo_base = gwvpmini_getConfigVal("repodir"); + $cmd = "git --git-dir=\"$repo_base/$name.git\" log --all -1 2> /dev/null"; + // error_log("CMD: $cmd"); + //system("$cmd"); + $fls = popen($cmd, "r"); + $tks = ""; + if($fls !== false) while(!feof($fls)) { + $tks .= fread($fls,1024); + } + + if($tks == "") { + $lastlog = "No Log Info Yet"; + } else $lastlog = $tks; } - if($tks == "") { - $lastlog = "No Log Info Yet"; - } else $lastlog = $tks; - $owner = gwvpmini_getUser(null, null, $repo["owner"]); $repname = "$name"; $repown = gwvpmini_HtmlGravatar($owner["email"], 30, "
")."".$owner["username"].""; diff --git a/gwvpmini/gwvpmini_web.php b/gwvpmini/gwvpmini_web.php index 71a931f..92005b3 100644 --- a/gwvpmini/gwvpmini_web.php +++ b/gwvpmini/gwvpmini_web.php @@ -104,8 +104,11 @@ function gwvpmini_goMainPage($bodyFunction = null) gwvpmini_SearchBuilder(); echo ""; - - if(isset($_SESSION["message"])) { + $havemessage = false; + if(isset($_SESSION["message"])) $havemessage = true; + if(isset($_SESSION["id"])) if(gwvpmini_GetMessagesForId($_SESSION["id"]) !== 0) $havemessage = true; + + if($havemessage) { echo ""; gwvpmini_MessageBuilder(); echo ""; @@ -155,11 +158,30 @@ function gwvpmini_goMainPage($bodyFunction = null) // builds the message builder if its needed function gwvpmini_MessageBuilder() { + + error_log("begin message building?"); $message = ""; $messagetype = "info"; if(isset($_SESSION["message"])) $message = $_SESSION["message"]; if(isset($_SESSION["messagetype"])) $messagetype = $_SESSION["messagetype"]; - + if(isset($_SESSION["id"])) $dbmsgs = gwvpmini_GetMessagesForId($_SESSION["id"]); + + error_log("dbmsgs was 0 - ".print_r($_SESSION,true)); + + if($dbmsgs !== 0) { + foreach($dbmsgs as $mgkey => $mgval) { + $data = $mgval["data"]; + switch($mgval["type"]) { + case "info": + echo "
$data
"; + break; + case "error": + echo "
$data
"; + break; + } + gwvpmini_DeleteMessagesById($mgval["id"]); + } + } if($message != "") { switch($messagetype) { case "info":