added a message via db commit path
authorPaul J R <me@pjr.cc>
Thu, 25 Oct 2012 07:29:08 +0000 (18:29 +1100)
committerPaul J R <me@pjr.cc>
Thu, 25 Oct 2012 07:29:08 +0000 (18:29 +1100)
bin/gwvpminicmdtool.php
gwvpmini/gwvpmini_db.php
gwvpmini/gwvpmini_debug.php
gwvpmini/gwvpmini_gitrepo.php
gwvpmini/gwvpmini_web.php

index 9781a8e..afc372a 100644 (file)
@@ -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";
index 88c7ee2..fc6babc 100644 (file)
@@ -546,7 +546,16 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc)
        "repos_status" TEXT,
        "repos_origin" TEXT,
        UNIQUE(repos_name)\r
-       )';\r
+       )';
+       
+       $msgsql = '
+       CREATE TABLE "messages" (
+       "msgs_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+       "msgs_type" TEXT,
+       "msgs_data" TEXT,
+       "msgs_to_id" TEXT
+       )';
+       \r
 \r
        // this looks like null, <repoid>, <read|visible|write>, user:<uid>|group:<gid>|authed|anon\r
        // where authed = any authenticated user, anon = everyone (logged in, not logged in, etc)\r
@@ -591,7 +600,8 @@ function gwvpmini_dbCreateSQLiteStructure($dbloc)
        $DB_CONNECTION->query($initialuser_user);
        $DB_CONNECTION->query($reposql);\r
        $DB_CONNECTION->query($configsql);
-       $DB_CONNECTION->query($activitysql);\r
+       $DB_CONNECTION->query($activitysql);
+       $DB_CONNECTION->query($msgsql);\r
 }
 
 function gwvpmini_getConfigVal($confname)\r
@@ -695,6 +705,59 @@ function gwvpmini_GetRepoDescFromName($reponame)
 \r
        return $retval;\r
 }
+
+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();\r
+       \r
+       $sql = "select * from messages where msgs_to_id='$uid'";\r
+       // error_log("desc for name sql: $sql");\r
+       \r
+       $res = $conn->query($sql);
+       
+       error_log("request message for uid, $uid with sql $sql");\r
+       
+       $i = 0;\r
+       if(!$res) return 0;\r
+       foreach($res as $row) {
+               $retval[$i]["id"] = $row["msgs_id"];
+               $retval[$i]["type"] = $row["msgs_type"];
+               $retval[$i]["data"] = $row["msgs_data"];
+               $i++;\r
+       }
+       
+       \r
+       return $retval;\r
+       
+}
+
+function gwvpmini_DeleteMessagesById($mid)
+{
+       $conn = gwvpmini_ConnectDB();\r
+       \r
+       $sql = "delete from messages where msgs_id='$mid'";
+       
+       return $conn->query($sql);
+}
 \r
 function gwvpmini_GetRepoOwnerDetailsFromName($reponame)\r
 {\r
@@ -848,7 +911,7 @@ function gwvpmini_GetOwnedRepos($username)
                // error_log(print_r($row, true));
        }
        
-       // error_log(print_r($retval, true));\r
+       error_log(print_r($retval, true));\r
        return $retval;\r
 }
 
index 80cf2e0..cd70c6f 100644 (file)
@@ -42,5 +42,13 @@ function gwvpmini_DebugPageBody()
                print_r(unserialize(base64_decode($perms)));
                echo "</pre>";
        }
+       
+       echo "<hr>Sending some messages for db<br>";
+       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<br>";
 }
 ?>
\ No newline at end of file
index d9d9fef..e20532e 100644 (file)
@@ -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<br>";  
                } else {
@@ -63,26 +64,37 @@ function gwvpmini_RepoMainPageBody()
                        foreach($repos as $repo) {
                                $name = $repo["name"];
                                $desc = $repo["desc"];
+                               $stat = $repo["status"];
+                               $llog = "";\r
+                               if($stat != 0) {\r
+                                       switch($stat) {\r
+                                               case 1:\r
+                                                       $llog = "Repo Administratively Disabled";\r
+                                                       break;\r
+                                               case 2:\r
+                                                       $llog = "Repo Cloning from remote";\r
+                                                       break;\r
+                                       }\r
+                               } 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 "<tr><td><a href=\"$BASE_URL/view/$name\">$name</a></td><td>$desc</td>";
-                               echo "<td>";\r
-                               // 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 "</td>";
-                               echo "</tr>";
+                               echo "<tr><td><a href=\"$BASE_URL/view/$name\">$name</a></td><td>$desc</td><td>$llog</td></tr>";
                        }
                        echo "</table>";
                }
@@ -97,20 +109,32 @@ function gwvpmini_RepoMainPageBody()
                        foreach($contreps as $repo) {
                                $name = $repo["name"];\r
                                $desc = $repo["desc"];
-                               $repo_base = gwvpmini_getConfigVal("repodir");\r
-                               $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");\r
+                                       $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 = "<a href=\"$BASE_URL/view/$name\">$name</a>";
                                $repown = gwvpmini_HtmlGravatar($owner["email"], 30, "<br>")."<a href=\"$BASE_URL/user/".$owner["username"]."\">".$owner["username"]."</a>";
index 71a931f..92005b3 100644 (file)
@@ -104,8 +104,11 @@ function gwvpmini_goMainPage($bodyFunction = null)
        gwvpmini_SearchBuilder();
        echo "</td></tr>";\r
        
-
-       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 "<tr width=\"100%\"><td colspan=\"2\">";
                gwvpmini_MessageBuilder();
                echo "</td></tr>";
@@ -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"]) {\r
+                               case "info":\r
+                                       echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#AAFFAA\">$data</td></tr></table>";\r
+                                       break;\r
+                               case "error":\r
+                                       echo "<table border=\"1\" width=\"100%\"><tr width=\"100%\"><td bgcolor=\"#FFAAAA\">$data</td></tr></table>";\r
+                                       break;\r
+                       }
+                       gwvpmini_DeleteMessagesById($mgval["id"]);
+               }
+       } 
        if($message != "") {
                switch($messagetype) {
                        case "info":