incubator-olio-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ak...@apache.org
Subject svn commit: r805254 - /incubator/olio/webapp/php/trunk/public_html/addPersonResult.php
Date Tue, 18 Aug 2009 02:07:31 GMT
Author: akara
Date: Tue Aug 18 02:07:31 2009
New Revision: 805254

URL: http://svn.apache.org/viewvc?rev=805254&view=rev
Log:
Issue OLIO-40: addPersonResult broken into 2 transactions. One insert grabbing user id which
is then used for the image file names. Then the image name is updated back to the DB in a
separate transactions. This follows the convention of addEventResult.

Modified:
    incubator/olio/webapp/php/trunk/public_html/addPersonResult.php

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=805254&r1=805253&r2=805254&view=diff
==============================================================================
--- incubator/olio/webapp/php/trunk/public_html/addPersonResult.php (original)
+++ incubator/olio/webapp/php/trunk/public_html/addPersonResult.php Tue Aug 18 02:07:31 2009
@@ -20,56 +20,30 @@
 require_once("../etc/config.php");
 $connection = DBConnection::getWriteInstance();
 
-if(isset($_POST['addpersonsubmit'])) {
-	//insert into person table using the data from addPerson page
-	$username=$_POST['add_user_name'];
-	$pwd    =$_POST['psword'];
-	$summary=$_POST['summary'];
-	$fname=$_POST['first_name'];
-	$lname=$_POST['last_name'];
-	$email=$_POST['email'];
-	$strt1= $_POST['street1'];
-	$street2= $_POST['street2'];
-	$cty  = $_POST['city'];
-	$street1=str_replace(" ","+",$strt1);
-	$city = str_replace(" ","+",$cty);
-	$state=$_POST['state'];
-	$zip=$_POST['zip'];
-	$country=$_POST['country'];
-	$telephone=$_POST['telephone'];
-	$timezone=$_POST['timezone'];
-
-	$imagethumb = "";
-
-	$image_name= basename($_FILES['user_image']['name']);
-
-	if ($image_name != "") {
-		$pos=strpos($image_name,'.');
-		$img_ext = substr($image_name,$pos,strlen($image_name));
-		$modified_image_name = "P".$username.$img_ext;
-		$resourcedir = '/tmp/';
-        $imagethumb = "P".$username."T".$img_ext;
-		$user_image_location = $resourcedir . $modified_image_name;
-		if (!move_uploaded_file($_FILES['user_image']['tmp_name'], $user_image_location)) {
-			throw new Exception("Error moving uploaded file to $user_image_location");
-		}
-        $thumb_location = $resourcedir . $imagethumb;
-        ImageUtil::createThumb($user_image_location, $thumb_location, 133, 99);
-		$fs = FileSystem::getInstance();
-        if (!$fs->create($user_image_location, "NO_OP", "NO_OP")) {
-            error_log("Error copying image " . $user_image_location);
-        }
-        if (!$fs->create($thumb_location, "NO_OP", "NO_OP")) {
-            error_log("Error copying thumb " . $thumb_location);
-        }
-        unlink($user_image_location);
-        unlink($thumb_location);
-	} else {
-		$modified_image_name = Olio::$config['includes'] . "userphotomissing.gif";
-		$imagethumb = Olio::$config['includes'] . "userphotomissing.gif";
-	}
+// 1. Get data from submission page.
+$username=$_POST['add_user_name'];
+$pwd    =$_POST['psword'];
+$summary=$_POST['summary'];
+$fname=$_POST['first_name'];
+$lname=$_POST['last_name'];
+$email=$_POST['email'];
+$strt1= $_POST['street1'];
+$street2= $_POST['street2'];
+$cty  = $_POST['city'];
+$street1=str_replace(" ","+",$strt1);
+$city = str_replace(" ","+",$cty);
+$state=$_POST['state'];
+$zip=$_POST['zip'];
+$country=$_POST['country'];
+$telephone=$_POST['telephone'];
+$timezone=$_POST['timezone'];
+$image_name= basename($_FILES['user_image']['name']);
 
-	$geocode = new Geocoder($street1, $city, $state, $zip);
+// 2. Get coordinates of the address.
+$geocode = new Geocoder($street1, $city, $state, $zip);
+
+// 3. Insert address and get the address id, or update the address.
+if(isset($_POST['addpersonsubmit'])) {
 
 	$insertaddr = "insert into ADDRESS (street1, street2, city, state, zip, country, latitude,
longitude) ".
                       "values ('$strt1', '$street2', '$cty', '$state', '$zip', '$country',
".
@@ -84,67 +58,25 @@
 	}
 	unset($idres);
 
-	if ($imagethumb != "") {
-		$insertsql ="insert into PERSON (username,password,firstname,lastname,email,telephone,imageurl,imagethumburl,summary,timezone,ADDRESS_addressid)
 values('$username','$pwd', '$fname','$lname','$email','$telephone','$modified_image_name','$imagethumb','$summary','$timezone','$addrid')";
-	} else {
-		$insertsql ="insert into PERSON (username,password,firstname,lastname,email,telephone,imageurl,summary,timezone,ADDRESS_addressid)
 values('$username','$pwd', '$fname','$lname','$email','$telephone','$modified_image_name','$summary','$timezone','$addrid')";
-	}
+    // At least temporary place holder for the image.
+    $modified_image_name = Olio::$config['includes'] . "userphotomissing.gif";
+    $imagethumb = Olio::$config['includes'] . "userphotomissing.gif";
+
+    $insertsql = "insert into PERSON (username, password, firstname, lastname,".
+                 " email, telephone, imageurl, imagethumburl, summary,".
+                 " timezone,"."ADDRESS_addressid) values('$username', '$pwd',".
+                 " '$fname', '$lname', '$email', '$telephone',".
+                 " '$modified_image_name', '$imagethumb', '$summary',".
+                 " '$timezone', '$addrid')";
 	$insertresult = $connection->exec($insertsql);
+    $idres = $connection->query($cq);
+    while ($idres->next()) {
+        $userid = $idres->get(1);
+    }
 
 } else if (isset($_POST['addpersonsubmitupdate'])) {
-	//update person table using the data from addPerson page
-	$username=$_POST['add_user_name'];
-	$pwd    =$_POST['psword'];
-	$summary=$_POST['summary'];
-	$fname=$_POST['first_name'];
-	$lname=$_POST['last_name'];
-	$email=$_POST['email'];
-	$strt1= $_POST['street1'];
-	$street2= $_POST['street2'];
-	$cty  = $_POST['city'];
-	$street1=str_replace(" ","+",$strt1);
-	$city = str_replace(" ","+",$cty);
-	$state=$_POST['state'];
-	$zip=$_POST['zip'];
-	$country=$_POST['country'];
-	$telephone=$_POST['telephone'];
-	$timezone=$_POST['timezone'];
-
-	$image_name= basename($_FILES['user_image']['name']);
-
-    $geocode = new Geocoder($street1, $city, $state, $zip);
-
-	if ($image_name != "") {
-		$pos=strpos($image_name,'.');
-		$img_ext = substr($image_name,$pos,strlen($image_name));
-		$modified_image_name = "P".$username.$img_ext;
-		$resourcedir = '/tmp/';
-		$user_image_location = $resourcedir . $modified_image_name;
-		if (!move_uploaded_file($_FILES['user_image']['tmp_name'], $user_image_location)) {
-			throw new Exception("Error moving uploaded file to $user_image_location");
-		}
-                $imagethumb = "P".$username."T".$img_ext;
-                $thumb_location = $resourcedir . $imagethumb;
-                ImageUtil::createThumb($user_image_location, $thumb_location, 133, 99);
-		$fs = FileSystem::getInstance();
-        if (!$fs->create($user_image_location, "NO_OP", "NO_OP")) {
-            error_log("Error copying image " . $user_image_location);
-        }
-        if (!$fs->create($thumb_location, "NO_OP", "NO_OP")) {
-            error_log("Error copying thumb " . $thumb_location);
-        }
-        unlink($user_image_location);
-        unlink($thumb_location);
-	} else {
-		$imgquery = "select imageurl from PERSON where username='$username' ";
-        $connection->beginTransaction();
-		$imgresult=$connection->query($imgquery);
-		while ($imgresult->next()) {
-			$modified_image_name = $imgresult->get(1);
-		}
-		unset($imgresult);
-	}
-	if ($summary == "" ) {
+
+ 	if ($summary == "" ) {
 		$sumquery = "select summary from PERSON where username='$username' ";
 		$sumresult = $connection->query($sumquery);
 		while ($sumresult->next()) {
@@ -164,11 +96,58 @@
 	}
 	unset($idres);
 
-	$updatesql ="update PERSON set password='$pwd',firstname='$fname',lastname='$lname',email='$email',telephone='$telephone',imageurl='$modified_image_name',summary='$summary',timezone='$timezone',ADDRESS_addressid='$addrid'
where username='$username' ";
+	$updatesql ="update PERSON set password='$pwd', firstname='$fname', lastname='$lname', email='$email',
telephone='$telephone',";
+    if ($summary != "") {
+        $updatesql .= " summary='$summary',";
+    }
+    $updatesql .= " timezone='$timezone', ADDRESS_addressid='$addrid' where username='$username'
";
 	$connection->exec($updatesql);
 
+    $userid_query = "select userid from PERSON where username='$username'";
+    $idres = $connection->query($userid_query);
+    while ($idres->next()) {
+        $userid = $idres.get(1);
+    }
+    unset($idres);
 }
 
+// 4. End the DB transaction here.
 $connection->commit();
+
+if ($image_name != "") {
+    // 5. Determine the image id.
+    $pos=strpos($image_name,'.');
+    $img_ext = substr($image_name,$pos,strlen($image_name));
+    $modified_image_name = "P".$userid.$img_ext;
+    $resourcedir = '/tmp/';
+    $imagethumb = "P".$userid."T".$img_ext;
+    $user_image_location = $resourcedir . $modified_image_name;
+    if (!move_uploaded_file($_FILES['user_image']['tmp_name'], $user_image_location)) {
+        throw new Exception("Error moving uploaded file to $user_image_location");
+    }
+
+    // 6. Generate the thumbnails.
+    $thumb_location = $resourcedir . $imagethumb;
+    ImageUtil::createThumb($user_image_location, $thumb_location, 133, 99);
+
+    // 7. Store the image.
+    $fs = FileSystem::getInstance();
+
+    if (!$fs->create($user_image_location, "NO_OP", "NO_OP")) {
+        error_log("Error copying image " . $user_image_location);
+    }
+    if (!$fs->create($thumb_location, "NO_OP", "NO_OP")) {
+        error_log("Error copying thumb " . $thumb_location);
+    }
+    unlink($user_image_location);
+    unlink($thumb_location);
+
+    // 8. Update the DB.
+    $updateimage = "update PERSON set imageurl = '$modified_image_name', ".
+                   "imagethumburl = '$imagethumb' ".
+                   "where userid = '$userid'";
+    $updated = $connection->exec($updateimage);
+}
+
 header("Location:users.php?username=".$username);
 ?>



Mime
View raw message