Akara - do we want the nbproject files ?

Shanti

[email protected] wrote:
Author: akara
Date: Mon Jan 12 17:53:50 2009
New Revision: 733989

URL: http://svn.apache.org/viewvc?rev=733989&view=rev
Log:
Fix for issue OLIO-3 and OLIO-30:
- Fix for OLIO-3 submitted by Damien Cooke
- Fix for OLIO-30 - added database selection mechanism and changed all write 
transaction to write to the write instance of the DB connection obtained via 
DBConnection::getWriteInstance();

Added:
    incubator/olio/webapp/php/trunk/nbproject/   (with props)
    incubator/olio/webapp/php/trunk/nbproject/project.properties
    incubator/olio/webapp/php/trunk/nbproject/project.xml
Modified:
    incubator/olio/webapp/php/trunk/classes/DBConnection.php
    incubator/olio/webapp/php/trunk/classes/MemCached.php
    incubator/olio/webapp/php/trunk/classes/ODBCConnection.php
    incubator/olio/webapp/php/trunk/classes/PDOConnection.php
    incubator/olio/webapp/php/trunk/etc/config.php
    incubator/olio/webapp/php/trunk/public_html/addAttendee.php
    incubator/olio/webapp/php/trunk/public_html/addDeleteFriend.php
    incubator/olio/webapp/php/trunk/public_html/addEventResult.php
    incubator/olio/webapp/php/trunk/public_html/addPersonResult.php
    incubator/olio/webapp/php/trunk/public_html/approveFriendship.php
    incubator/olio/webapp/php/trunk/public_html/deleteAttendee.php
    incubator/olio/webapp/php/trunk/public_html/deleteCommentsRating.php
    incubator/olio/webapp/php/trunk/public_html/deleteEvent.php
    incubator/olio/webapp/php/trunk/public_html/events.php
    incubator/olio/webapp/php/trunk/public_html/index.php
    incubator/olio/webapp/php/trunk/public_html/rejectInvite.php
    incubator/olio/webapp/php/trunk/public_html/revokeInvite.php

Modified: incubator/olio/webapp/php/trunk/classes/DBConnection.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/classes/DBConnection.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/classes/DBConnection.php (original)
+++ incubator/olio/webapp/php/trunk/classes/DBConnection.php Mon Jan 12 
17:53:50 2009
@@ -17,11 +17,37 @@
  * limitations under the License.
*/ -abstract class DBConnection
-{
+abstract class DBConnection {
+
+    var $writeInstance;
+    var $dbTarget;
+
+
     static function getInstance() {
         $classname = Web20::$config['dbDriver'] . 'Connection';
-        return new $classname;
+        $instance = new $classname;
+        $instance->writeInstance = false;
+        return $instance;
+    }
+
+    static function getWriteInstance() {
+        $classname = Web20::$config['dbDriver'] . 'Connection';
+        $instance = new $classname;
+        $instance->writeInstance = true;
+        return $instance;
+    }
+
+    function selectInstance() {
+        $this->dbTarget = Web20::$config['dbTarget'];
+        if (is_array($this->dbTarget)) {
+            if ($this->writeInstance || count($this->dbTarget) == 1) {
+                $this->dbTarget = $this->dbTarget[0];
+            } else {
+                $idx = (getmypid() % (count($this->dbTarget) - 1)) + 1;
+                // $idx = rand(1, count($this->dbTarget) - 1);
+                $this->dbTarget = $this->dbTarget[$idx];
+            }
+        }
     }
abstract function query();

Modified: incubator/olio/webapp/php/trunk/classes/MemCached.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/classes/MemCached.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/classes/MemCached.php (original)
+++ incubator/olio/webapp/php/trunk/classes/MemCached.php Mon Jan 12 17:53:50 
2009
@@ -68,18 +68,15 @@
            $updateSema = $key . 'UpdateSema';
            if (!$this->memcache->get($updateSema)) {
                $updateLock = $key . 'UpdateLock';
-               if (!$this->memcache->get($updateLock)) {
-                   $hostPid = php_uname('n') . ':' . getmypid();
-                   // The updateLock times out in 5 secs.
-                   $this->memcache->set($updateLock, $hostPid, 0, 5);
-                   if ($this->memcache->get($updateLock) == $hostPid) {
-                        error_log('Verified updateLock');
-                       return true;
-                    }
-               }
+               $hostPid = php_uname('n') . ':' . getmypid();
+            if ($this->memcache->add($updateLock, $hostPid, 0, 5)) {
+                error_log($hostPid." obtained ".$updateLock);
+                return true;
+            }
            }
            return false;
-       }
+    }
+
        
        function doneRefresh($key, $timeToNextRefresh) {
            $updateSema = $key . 'UpdateSema';
@@ -90,6 +87,7 @@
                                    ' not locked by this process!');
            $this->memcache->set($updateSema, 1, 0, $timeToNextRefresh);
            $this->memcache->delete($updateLock);
+        error_log($hostPid." released ".$updateLock);
        }
 }
 ?>

Modified: incubator/olio/webapp/php/trunk/classes/ODBCConnection.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/classes/ODBCConnection.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/classes/ODBCConnection.php (original)
+++ incubator/olio/webapp/php/trunk/classes/ODBCConnection.php Mon Jan 12 
17:53:50 2009
@@ -21,6 +21,18 @@
var $connection; + private function ensureConnection() {
+        if (!isset($this->dbTarget)) {
+            $this->selectInstance();
+        }
+       if (!isset($this->connection)) {
+            $this->connection = odbc_connect($this->dbTarget,
+                Web20::$config['dbUser'], Web20::$config['dbPass']);
+            if (is_resource($this->connection))
+                throw new Exception("Unable to connect ".$this->dbTarget."!");
+        }
+    }
+
     function query() {
        if (func_num_args() > 1) {
            $args = func_get_args();
@@ -30,13 +42,7 @@
        } else {
                $sql = func_get_arg(0);
        }
-       if (!isset($this->connection)) {
-            $this->connection = odbc_connect(Web20::$config['dbTarget'],
-                Web20::$config['dbUser'], Web20::$config['dbPass']);
-            if (is_resource($this->connection))
-                throw new Exception("Unable to connect " .
-                                     Web20::$config['dbTarget']."!");
-        }
+        $this->ensureConnection();
         if (isset($args)) {
                error_log("You are using prepared statements. This is extremely 
slow!");
                $result = odbc_prepare($this->connection, $sql);
@@ -65,13 +71,7 @@
        } else {
                $sql = func_get_arg(0);
        }
-       if (!isset($this->connection)) {
-            $this->connection = odbc_connect(Web20::$config['dbTarget'],
-                Web20::$config['dbUser'], Web20::$config['dbPass']);
-            if (!$this->connection)
-                throw new Exception("Unable to connect " .
-                                     Web20::$config['dbTarget'] . "!");
-        }
+        $this->ensureConnection();
         if (isset($args)) {
                $result = odbc_prepare($this->connection, $sql);
                if (!odbc_execute($result, $args))

Modified: incubator/olio/webapp/php/trunk/classes/PDOConnection.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/classes/PDOConnection.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/classes/PDOConnection.php (original)
+++ incubator/olio/webapp/php/trunk/classes/PDOConnection.php Mon Jan 12 
17:53:50 2009
@@ -22,16 +22,18 @@
     var $connection;
private function ensureConnection() {
+        if (!isset($this->dbTarget)) {
+            $this->selectInstance();
+        }
        if (!isset($this->connection)) {
-            $this->connection = new PDO(Web20::$config['dbTarget'],
+            $this->connection = new PDO($this->dbTarget,
Web20::$config['dbUser'], Web20::$config['dbPass'], array(PDO::ATTR_PERSISTENT => true));
             
$this->connection->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
             $this->connection->setAttribute( // throw exception on error.
PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); if (!$this->connection)
-                throw new Exception("Unable to connect " .
-                                     Web20::$config['dbTarget']."!");
+                throw new Exception("Unable to connect " . 
$this->dbTarget."!");
         }      
     }
Modified: incubator/olio/webapp/php/trunk/etc/config.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/etc/config.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/etc/config.php (original)
+++ incubator/olio/webapp/php/trunk/etc/config.php Mon Jan 12 17:53:50 2009
@@ -23,6 +23,10 @@
// $web20config['dbTarget'] = 'myodbc3'; // ODBC target in odbc.ini.
 $web20config['dbTarget'] = 'mysql:host=localhost;dbname=web20load'; // PDO 
target.
+// For master/slave clusters, specify dbTarget as an array, listing the master 
first.
+// $web20config['dbTarget'] = array('mysql:host=master;dbname=web20load',
+//                                  'mysql:host=slave1;dbname=web20load',
+//                                  'mysql:host=slave2;dbname=web20load');
$web20config['dbUser'] = 'web20'; // DB user name.
Propchange: incubator/olio/webapp/php/trunk/nbproject/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Jan 12 17:53:50 2009
@@ -0,0 +1 @@
+private

Added: incubator/olio/webapp/php/trunk/nbproject/project.properties
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/nbproject/project.properties?rev=733989&view=auto
==============================================================================
--- incubator/olio/webapp/php/trunk/nbproject/project.properties (added)
+++ incubator/olio/webapp/php/trunk/nbproject/project.properties Mon Jan 12 
17:53:50 2009
@@ -0,0 +1,6 @@
+include.path=${php.global.include.path}
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.

Added: incubator/olio/webapp/php/trunk/nbproject/project.xml
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/nbproject/project.xml?rev=733989&view=auto
==============================================================================
--- incubator/olio/webapp/php/trunk/nbproject/project.xml (added)
+++ incubator/olio/webapp/php/trunk/nbproject/project.xml Mon Jan 12 17:53:50 
2009
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://www.netbeans.org/ns/project/1";>
+    <type>org.netbeans.modules.php.project</type>
+    <configuration>
+        <data xmlns="http://www.netbeans.org/ns/php-project/1";>
+            <name>Olio PHP Application</name>
+        </data>
+    </configuration>
+</project>

Modified: incubator/olio/webapp/php/trunk/public_html/addAttendee.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/addAttendee.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/addAttendee.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/addAttendee.php Mon Jan 12 
17:53:50 2009
@@ -23,19 +23,23 @@
  */
 session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
 $se = $_REQUEST['id'];
 $username = $HTTP_SESSION_VARS["uname"];
-if(!is_null($username)){
+if (!is_null($username)) {
+    $connection = DBConnection::getWriteInstance();
     $checkuserIfAttending = "select count(username) as count from 
PERSON_SOCIALEVENT where socialeventid = '$se' and username = '$username'";
     $result = $connection->query($checkuserIfAttending);
     $row = $result->getArray();
     $userExists = $row['count'];
-    if($userExists <= 0){
+    if ($userExists <= 0) {
         $insertuser = "insert into PERSON_SOCIALEVENT 
values('$username','$se')";
         $connection->exec($insertuser);
     }
 }
+
+if (!isset($connection)) { // If connection not there, we're read-only.
+    $connection = DBConnection::getInstance();
+}
 $listquery = "select username from PERSON_SOCIALEVENT where socialeventid = 
'$se'";
 $listqueryresult = $connection->query($listquery);
 $username = $HTTP_SESSION_VARS["uname"];

Modified: incubator/olio/webapp/php/trunk/public_html/addDeleteFriend.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/addDeleteFriend.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/addDeleteFriend.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/addDeleteFriend.php Mon Jan 12 
17:53:50 2009
@@ -24,7 +24,7 @@
session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $friends = Users_Controller::getInstance();
 $person = $_REQUEST['person'];
 $friend = $_REQUEST['friend'];

Modified: incubator/olio/webapp/php/trunk/public_html/addEventResult.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/addEventResult.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/addEventResult.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/addEventResult.php Mon Jan 12 
17:53:50 2009
@@ -19,7 +19,7 @@
session_start(); require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
// 1. Get data from submission page.
        $description=$_POST['description'];

Modified: incubator/olio/webapp/php/trunk/public_html/addPersonResult.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/addPersonResult.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/addPersonResult.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/addPersonResult.php Mon Jan 12 
17:53:50 2009
@@ -18,7 +18,7 @@
*/ require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
if(isset($_POST['addpersonsubmit'])) {
        //insert into person table using the data from addPerson page

Modified: incubator/olio/webapp/php/trunk/public_html/approveFriendship.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/approveFriendship.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/approveFriendship.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/approveFriendship.php Mon Jan 
12 17:53:50 2009
@@ -23,7 +23,7 @@
*/ session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $friends = Users_Controller::getInstance();
 $person = $_REQUEST['person'];
 $friend = $_REQUEST['friend'];

Modified: incubator/olio/webapp/php/trunk/public_html/deleteAttendee.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/deleteAttendee.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/deleteAttendee.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/deleteAttendee.php Mon Jan 12 
17:53:50 2009
@@ -25,13 +25,17 @@
session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
 $se = $_REQUEST['id'];
 $username = $HTTP_SESSION_VARS["uname"];
 if(!is_null($username)){
+    $connection = DBConnection::getWriteInstance();
     $deleteuser = "delete from PERSON_SOCIALEVENT where username='$username' and 
socialeventid='$se'";
     $connection->exec($deleteuser);
 }
+
+if (!isset($connection)) {
+    $connection = DBConnection::getInstance();
+}
 $listquery = "select username from PERSON_SOCIALEVENT where socialeventid = 
'$se'";
 $listqueryresult = $connection->query($listquery);
 $username = $HTTP_SESSION_VARS["uname"];

Modified: incubator/olio/webapp/php/trunk/public_html/deleteCommentsRating.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/deleteCommentsRating.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/deleteCommentsRating.php 
(original)
+++ incubator/olio/webapp/php/trunk/public_html/deleteCommentsRating.php Mon 
Jan 12 17:53:50 2009
@@ -25,7 +25,7 @@
session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $events = Events_Controller::getInstance();
 $dateFormat = "l,  F j,  Y,  h:i A";
 $commentid = $_REQUEST['commentid'];

Modified: incubator/olio/webapp/php/trunk/public_html/deleteEvent.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/deleteEvent.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/deleteEvent.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/deleteEvent.php Mon Jan 12 
17:53:50 2009
@@ -24,7 +24,7 @@
*/ session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $se = $_REQUEST['socialEventID'];
 $deleteEvent = "delete from SOCIALEVENT where socialeventid='$se'";
 $connection->exec($deleteEvent);

Modified: incubator/olio/webapp/php/trunk/public_html/events.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/events.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/events.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/events.php Mon Jan 12 17:53:50 
2009
@@ -28,7 +28,12 @@
 $comments = $_POST['comments'];
 $cid = $_POST['editingcid'];
 $editcomments = $_POST['editcomments'];
-$connection = DBConnection::getInstance();
+if (isset($_POST['commentsratingsubmit']) || + (isset($_POST['editcommentsratingsubmit']) && isset($_POST['editingcid']))) {
+    $connection = DBConnection::getWriteInstance();
+} else {
+    $connection = DBConnection::getInstance();
+}
 $tagslist = Tags_Controller::getInstance();
 $events = Events_Controller::getInstance();
 $username = $HTTP_SESSION_VARS["uname"];
@@ -80,11 +85,10 @@
 }
 unset($listqueryresult);
-$editCRforCid = $_POST['editcommentsratingsubmit'].$cid;
 if (isset($_POST['commentsratingsubmit'])) {
         $insertSql = "insert into COMMENTS_RATING 
(username,socialeventid,comments,ratings) values 
('$username','$se','$comments','$rating')";
         $connection->exec($insertSql);
-}else if (isset($editCRforCid)) {
+} else if (isset($_POST['editcommentsratingsubmit']) && 
isset($_POST['editingcid'])) {
         $updateSql = "update COMMENTS_RATING set comments='$editcomments', 
ratings='$rating' where username='$username' and socialeventid='$se' and 
commentid='$cid'";
          $connection->exec($updateSql);
 }

Modified: incubator/olio/webapp/php/trunk/public_html/index.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/index.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/index.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/index.php Mon Jan 12 17:53:50 
2009
@@ -24,22 +24,23 @@
  */
session_start();
-require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
-$eventlist = Events_Controller::getInstance();
-$tagcloud = Tags_Controller::getInstance();
-$url = RequestUrl::getInstance();
+require("../etc/config.php");
+
 $signedinuser = $HTTP_SESSION_VARS["uname"];
 $page= $_REQUEST['page'];
 $flag = $_REQUEST['flag'];
+$url = RequestUrl::getInstance();
+
 $href = $url->getGetRequest();
-if(!is_null($page)){
-$href = substr($href, 0, strrpos($href,"&"));
-}
+if(!is_null($page)) {
+    $href = substr($href, 0, strrpos($href,"&"));
+} // else {
+  //  error_log('$page is null.',0);
+  //}
-if($href==""){
-$href = "?";
+if($href=="") {
+    $href = "?";
 }
if(!is_null($page)){
@@ -53,47 +54,185 @@
     $next_page = $HTTP_SESSION_VARS["currentpage"] + 1;
     $offset = ($page * 10) - 10;
     if($offset < 0) {
-    $offset = 0;
+        $offset = 0;
     }
     if($prev_page < 0) {
-    $prev_page = 1;
+        $prev_page = 1;
     }
     if($next_page >  $numPages) {
-    $next_page = $numPages;
+        $next_page = $numPages;
     }
-}else{
+    $cacheType = 0;
+} else {
+    // error_log('$page is still null.',0);
     $zipcode = $_REQUEST['zipcode'];
     $order = $_REQUEST['order'];
     $m= $_REQUEST['month'];
     $d= $_REQUEST['day'];
     $y= $_REQUEST['year'];
- if(!is_null($_REQUEST['month']) && !is_null($_REQUEST['day']) && !is_null($_REQUEST['year']) ){
-    $eventdate= $y."-".$m."-".$d;
+    if(!is_null($_REQUEST['month']) && !is_null($_REQUEST['day'])  &&
+            !is_null($_REQUEST['year'])) {
+        $eventdate= $y."-".$m."-".$d;
+ } + if (is_null($zipcode) && is_null($order) &&
+            !isset($eventdate)) {
+        //if (is_null($signedinuser)) { // Get whole page if not logged in...
+        if($HTTP_SESSION_VARS["uname"] == ''){
+            $cacheType = 2;
+        } else { // And just the page content if logged in.
+            $cacheType = 1;
+        }
+    } else {
+        $HTTP_SESSION_VARS["eventdate"]= $eventdate;
+        $HTTP_SESSION_VARS["zipcode"] = $zipcode;
+        $HTTP_SESSION_VARS["order"] = $order;
+
+        $connection = DBConnection::getInstance();
+        $eventlist = Events_Controller::getInstance();
+        $numPages  = $eventlist->getNumPages($zipcode,$eventdate,$connection);
+        $tagcloud = Tags_Controller::getInstance();
+        $HTTP_SESSION_VARS["numPages"] = $numPages;
+        // error_log("numPages = $numPages",0);
+        $cacheType = 0;
     }
-    $HTTP_SESSION_VARS["eventdate"]= $eventdate;
-    $HTTP_SESSION_VARS["zipcode"] = $zipcode;
-    $HTTP_SESSION_VARS["order"] = $order;
-    $numPages  = $eventlist->getNumPages($zipcode,$eventdate,$connection);
-    $HTTP_SESSION_VARS["numPages"] = $numPages;
-
     $prev_page = 1;
     $next_page = 2;
     $curr_page = 1;
     $offset = 0;
     session_unregister ("currentpage");
 }
-$indexEvents = 
$eventlist->getIndexEvents($zipcode,$order,$eventdate,$offset,null,$signedinuser,$connection);
-ob_start();
-require("../views/paginate.php");
-$paginateView = ob_get_clean();
-
-ob_start();
-require("../views/index.php");
-$fillContent = ob_get_clean();
-if($flag == "authenticated"){
-$fillMessage ="<font color=green>Successfully logged in!</font>";
+switch ($cacheType) {
+    case 0: noCachePage(); break;
+    case 1: contentCachePage(); break;
+    case 2: fullCachePage();
+}
+
+
+function fullCachePage() {
+    // error_log('fullCachePage Called',0);
+    global $signedinuser, $page, $flag, $url, $href, $eventdate, $zipcode;
+    global $order, $numPages, $curr_page, $prev_page, $next_page, $offset;
+    global $HTTP_SESSION_VARS;
+
+    // error_log('Accesssing Cache subsystem to collect the page if 
possible.',0);
+    $cache = CacheSystem::getInstance();
+    $pageContent = $cache->get('Home');
+    // error_log("Checking the Cache status for logged in and normal Home 
pages",0);
+    if ($pageContent != '') {
+        echo $pageContent;
+        // error_log("Cache hit for Home page...",0);
+    }
+
+    $needsRefresh = false;
+    for (;;) {
+        // error_log('refresh logic accessed.');
+        if ($cache->needsRefresh('Home')) {
+            $needsRefresh = true;
+            // error_log('Home needs refresh.');
+            break;
+        } else if ($pageContent == '') {
+            error_log('index.php waiting for cache.');
+            usleep(200000);
+            $pageContent = $cache->get('Home');
+            if ($pageContent != '') {
+                echo $pageContent;
+                break;
+ } + } else {
+            // error_log('.');
+            break;
+        }
+    }
+
+    if ($needsRefresh) {
+        // error_log("Regenerating page................");
+        $connection = DBConnection::getInstance();
+        $eventlist = Events_Controller::getInstance();
+        $numPages  = $eventlist->getNumPages($zipcode,$eventdate,$connection);
+        $indexEvents = $eventlist->getIndexEvents($zipcode,$order,$eventdate,
+                $offset,null,$signedinuser,$connection);
+        $tagcloud = Tags_Controller::getInstance();
+
+        ob_start();
+        require("../views/paginate.php");
+        $paginateView = ob_get_clean();
+
+        ob_start();
+        require("../views/index.php");
+        $fillContent = ob_get_clean();
+
+        ob_start();
+
+        require("../views/site.php");
+
+        // error_log('refreshing cache contents',0);
+        $newPageContent = ob_get_contents();
+        $cache->set('Home', $newPageContent, 0, 0);
+        $cache->set('HomeContent', $fillContent, 0, 0);
+        $cache->doneRefresh('Home', 300);
+
+        if ($pageContent == '') { // Not displayed yet, just display now.
+            // error_log("Display newly generated page");
+            ob_end_flush();
+        } else {
+            // error_log("Display of cache generated page has occured");
+            ob_end_clean(); // Otherwise just don't display the new one.
+        }
+    }
+}
+
+function contentCachePage() {
+    // error_log('ContentCachePage Called',0);
+    global $signedinuser, $page, $flag, $url, $href, $eventdate, $zipcode;
+    global $order, $numPages, $curr_page, $prev_page, $next_page, $offset;
+    global $HTTP_SESSION_VARS;
+
+    $cache = CacheSystem::getInstance();
+    for (;;) {
+        $fillContent = $cache->get('HomeContent');
+        if ($fillContent != '') {
+            break;
+        }
+        usleep(20000);
+        error_log('Retry loading fillContent from cache.');
+    }
+
+    if ($flag == "authenticated") {
+        $fillMessage ="<font color=green>Successfully logged in!</font>";
+    }
+    require("../views/site.php");
+}
+
+function noCachePage() {
+    // error_log('noCachePage Called',0);
+    global $signedinuser, $page, $flag, $url, $href, $eventdate, $zipcode;
+    global $order, $numPages, $curr_page, $prev_page, $next_page, $offset;
+    global $HTTP_SESSION_VARS;
+
+    $connection = DBConnection::getInstance();
+    $eventlist = Events_Controller::getInstance();
+    $tagcloud = Tags_Controller::getInstance();
+
+    if (!is_null($page)) {
+        $numPages  = $eventlist->getNumPages($zipcode,$eventdate,$connection);
+    }
+    $indexEvents = $eventlist->getIndexEvents($zipcode,$order,$eventdate,
+                                        
$offset,null,$signedinuser,$connection);
+
+    ob_start();
+    require("../views/paginate.php");
+    $paginateView = ob_get_clean();
+
+    ob_start();
+    require("../views/index.php");
+    $fillContent = ob_get_clean();
+
+    if($flag == "authenticated") {
+        $fillMessage ="<font color=green>Successfully logged in!</font>";
+    }
+
+    require("../views/site.php");
 }
-require_once("../views/site.php");
 ?>

Modified: incubator/olio/webapp/php/trunk/public_html/rejectInvite.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/rejectInvite.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/rejectInvite.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/rejectInvite.php Mon Jan 12 
17:53:50 2009
@@ -24,7 +24,7 @@
*/ session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $friends = Users_Controller::getInstance();
 $person = $_REQUEST['person'];
 $friend = $_REQUEST['friend'];

Modified: incubator/olio/webapp/php/trunk/public_html/revokeInvite.php
URL: 
http://svn.apache.org/viewvc/incubator/olio/webapp/php/trunk/public_html/revokeInvite.php?rev=733989&r1=733988&r2=733989&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/revokeInvite.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/revokeInvite.php Mon Jan 12 
17:53:50 2009
@@ -24,7 +24,7 @@
*/ session_start();
 require_once("../etc/config.php");
-$connection = DBConnection::getInstance();
+$connection = DBConnection::getWriteInstance();
 $friends = Users_Controller::getInstance();
 $person = $_REQUEST['person'];
 $friend = $_REQUEST['friend'];


Reply via email to