[vhffs-dev] [470] Removed all references to vhffs_notes.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 470
Author:   beuss
Date:     2007-02-17 11:27:06 +0000 (Sat, 17 Feb 2007)

Log Message:
-----------
Removed all references to vhffs_notes. Migration script sets note to 0 to non noted users.
Moderation scripts use user's uid instead of oid.

Modified Paths:
--------------
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Note.pm
    branches/vhffs_4.1/vhffs-compat/4.0.sql
    branches/vhffs_4.1/vhffs-panel/admin/moderation.pl
    branches/vhffs_4.1/vhffs-panel/admin/moderation_submit.pl
    branches/vhffs_4.1/vhffs-panel/templates/admin/misc/mailings_part.tmpl


Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Note.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Note.pm	2007-02-17 10:48:42 UTC (rev 469)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Note.pm	2007-02-17 11:27:06 UTC (rev 470)
@@ -42,17 +42,15 @@
 sub set_note
 {
 	my $vhffs		=	shift;
-	my $entity		=	shift;
+	my $user		=	shift;
 	my $value		=	shift;
 
-    my $query = 'UPDATE vhffs_notes SET note = ? WHERE object_id = ?';
-    my $request = $vhffs->{'db'}->prepare( $query );
-    my $rows = $request->execute( $value, $entity->get_oid );
-    if($rows == 0) {
-        $query = 'INSERT INTO vhffs_notes(object_id, note) VALUES(?, ?)';
-        $request = $vhffs->{'db'}->prepare( $query );
-        $request->execute($entity->get_oid, $value);
-    }
+    my $sql = 'UPDATE vhffs_user SET note = ? WHERE uid = ?';
+    my $dbh = $user->get_db_object;
+    my $sth = $sbh->prepare($sql);
+    $sth->execute($value, $user->get_uid());
+
+    return 1;
 }
 
 
@@ -60,36 +58,29 @@
 sub inc_note
 {
 	my $vhffs        	= shift;
-	my $entity 			= shift;
+	my $user 			= shift;
 	my $increase 		= shift;
 	my $note   			= 0;
 	my $already_exists 	= 0;
 
 	return -1 if( $entity->fetch < 0 );
 
-    my $query = 'UPDATE vhffs_notes SET note = note + ? WHERE object_id = ?';
-    my $request = $vhffs->{'db'}->prepare( $query );
-    my $rows = $request->execute( $increase, $entity->get_oid );
-    if($rows == 0) {
-        # No row was updated => create note
-        $query = 'INSERT INTO vhffs_notes(object_id, note) VALUES (?, ?)';
-        $request = $vhffs->{'db'}->prepare( $query );
-        $request->execute( $entity->get_oid, $increase );
+    my $sql = 'UPDATE vhffs_users SET note = note + ? WHERE uid = ?';
+    my $sth = $vhffs->{'db'}->prepare( $sql );
+    $sth->execute( $increase, $user->get_uid );
 
-    }
-
 	return 1;
 }
 
 sub get_note
 {
 	my $vhffs			=	shift;
-	my $entity 			= 	shift;
+	my $user 			= 	shift;
 
-    my $query = 'SELECT note FROM vhffs_notes WHERE object_id = ?';	
+    my $query = 'SELECT note FROM vhffs_users WHERE uid = ?';	
 
 	my $request = $vhffs->{'db'}->prepare( $query );
-	$request->execute($entity->get_oid);
+	$request->execute($entity->get_uid);
     my ($note) = $request->fetchrow();
     return ($note || 0);
 }
@@ -110,28 +101,28 @@
 	$vhffs = init Vhffs::Main;
 
 	...
-	(considers that you have a VHFFS object in $object)
+	(considers that you have a VHFFS user in $user)
 	...
 
-	print "Current note for your object : " . Vhffs::Note::get_note( $vhffs , $object );
+	print "Current note for your user : " . Vhffs::Note::get_note( $vhffs , $user );
 	
 	#We add 3 to the current note
-	Vhffs::Note::inc_note( $vhffs , $object , 3 );
+	Vhffs::Note::inc_note( $vhffs , $user , 3 );
 
 	#We set the note to 0
-	Vhffs::Note::set_note( $vhffs , $object , 0 );
+	Vhffs::Note::set_note( $vhffs , $user, 0 );
 
 	#We decrease the note of 1
-	Vhffs::Note::inc_note( $vhffs , $object , -1 );
+	Vhffs::Note::inc_note( $vhffs , $user, -1 );
 
 
 =head1 METHODS
 
-	get_note( $vhffs , $object ) : return the note for the given object
+	get_note( $vhffs , $user ) : return the note for the given object
 
-	set_note( $vhffs , $object , $value ) : set the note
+	set_note( $vhffs , $user , $value ) : set the note
 
-	inc_note( $vhffs , $object , $inc ) : add $inc to the current not of object $object
+	inc_note( $vhffs , $user , $inc ) : add $inc to the current not of object $object
 
 =head1 AUTHOR
 

Modified: branches/vhffs_4.1/vhffs-compat/4.0.sql
===================================================================
--- branches/vhffs_4.1/vhffs-compat/4.0.sql	2007-02-17 10:48:42 UTC (rev 469)
+++ branches/vhffs_4.1/vhffs-compat/4.0.sql	2007-02-17 11:27:06 UTC (rev 470)
@@ -73,6 +73,7 @@
 
 -- merge vhffs_notes to vhffs_users
 ALTER TABLE vhffs_users ADD COLUMN note int4;
+UPDATE vhffs_users SET note = 0 WHERE object_id NOT IN (SELECT object_id FROM vhffs_notes);
 UPDATE vhffs_users SET note = n.note FROM vhffs_notes n WHERE n.object_id = vhffs_users.object_id;
 
 DROP TABLE vhffs_notes;

Modified: branches/vhffs_4.1/vhffs-panel/admin/moderation.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/moderation.pl	2007-02-17 10:48:42 UTC (rev 469)
+++ branches/vhffs_4.1/vhffs-panel/admin/moderation.pl	2007-02-17 11:27:06 UTC (rev 470)
@@ -101,7 +101,7 @@
             {
                 $subtemplate->param( OWNER  => $temp->get_user->get_username);
 				$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
             }
             else
             {
@@ -144,7 +144,7 @@
 				{
                 $subtemplate->param( OWNER  => $temp->get_user->get_username);
 				$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-					$subtemplate->param( OID_ASKER	=> $temp->get_user->get_oid);
+					$subtemplate->param( UID_ASKER	=> $temp->get_user->get_uid);
 				}
 				else
 				{
@@ -185,7 +185,7 @@
             {
                 $subtemplate->param( OWNER  => $temp->get_user->get_username);
 				$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
             }
             else
             {
@@ -229,7 +229,7 @@
 	            {
                 	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-           		    $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+           		    $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
             	}
             	else
             	{
@@ -273,7 +273,7 @@
                 {
                 	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                    $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                    $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
                 }
                 else
                 {
@@ -317,7 +317,7 @@
                 {
                 	$subtemplate->param( OWNER  => $svn->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $svn->get_user ) );
-                    $subtemplate->param( OID_ASKER  => $svn->get_user->get_oid);
+                    $subtemplate->param( UID_ASKER  => $svn->get_user->get_uid);
                 }
                 else
                 {
@@ -362,7 +362,7 @@
                 {
                 	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                    $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                    $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
                 }
                 else
                 {
@@ -404,7 +404,7 @@
                 {
                 	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                    $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                    $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
                 }
                 else
                 {
@@ -446,7 +446,7 @@
                 {
                 	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-                    $subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+                    $subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
                 }
                 else
                 {
@@ -488,7 +488,7 @@
 		                {
 		                	$subtemplate->param( OWNER  => $temp->get_user->get_username);
 					$subtemplate->param( NOTE   => Vhffs::Note::get_note( $vhffs , $temp->get_user ) );
-					$subtemplate->param( OID_ASKER  => $temp->get_user->get_oid);
+					$subtemplate->param( UID_ASKER  => $temp->get_user->get_uid);
 		                }
 		                else
 		                {

Modified: branches/vhffs_4.1/vhffs-panel/admin/moderation_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/moderation_submit.pl	2007-02-17 10:48:42 UTC (rev 469)
+++ branches/vhffs_4.1/vhffs-panel/admin/moderation_submit.pl	2007-02-17 11:27:06 UTC (rev 470)
@@ -82,7 +82,7 @@
 {
 	use Vhffs::Object;
 	my $oid = $cgi->param("OID");
-	my $oidasker = $cgi->param("OID_ASKER");
+	my $uidasker = $cgi->param("UID_ASKER");
 	my $object = Vhffs::Object::get_by_oid( $vhffs , $oid );
 
 	if( ( ! defined $oid ) || ( ! defined $object ) || ( ! defined $accept ) )
@@ -116,13 +116,13 @@
 		}
 		else
 		{
-			my $askerobject = Vhffs::Object::get_by_oid( $vhffs , $oidasker );
+            my $askeruser = Vhffs::User::get_by_uid($vhffs, $uidasker),
 		    $object->set_description( $reason );
 		    $object->set_status( Vhffs::Constants::VALIDATION_REFUSED );
 	        if( $vhffs->get_config->use_notation == 1 )
 			{
 				use Vhffs::Note;
-				Vhffs::Note::inc_note( $vhffs , $askerobject , -1 );
+				Vhffs::Note::inc_note( $vhffs , $askeruser , -1 );
 			}
 		}
 		

Modified: branches/vhffs_4.1/vhffs-panel/templates/admin/misc/mailings_part.tmpl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/templates/admin/misc/mailings_part.tmpl	2007-02-17 10:48:42 UTC (rev 469)
+++ branches/vhffs_4.1/vhffs-panel/templates/admin/misc/mailings_part.tmpl	2007-02-17 11:27:06 UTC (rev 470)
@@ -14,7 +14,7 @@
 	<td>
 		<form method="post" action="moderation_submit.pl">
 			<input type="hidden" name="OID" value="<TMPL_VAR NAME="OID">" />
-			<input type="hidden" name="OID_ASKER" value="<TMPL_VAR NAME="OID_ASKER">" />
+			<input type="hidden" name="UID_ASKER" value="<TMPL_VAR NAME="UID_ASKER">" />
 			<input type="hidden" name="ACCEPT" value="1" />
 			<input type="submit" value="<TMPL_VAR NAME="ACCEPT">" />
 		</form>
@@ -24,7 +24,7 @@
 		<form method="post" action="moderation_submit.pl">
 			<textarea name="reason" cols="30" rows="4"></textarea>
 			<input type="hidden" name="OID" value="<TMPL_VAR NAME="OID">" />
-			<input type="hidden" name="OID_ASKER" value="<TMPL_VAR NAME="OID_ASKER">" />
+			<input type="hidden" name="UID_ASKER" value="<TMPL_VAR NAME="UID_ASKER">" />
 			<input type="hidden" name="ACCEPT" value="0" />
 			<input type="submit" value="<TMPL_VAR NAME="REFUSE">" />
 		</form>


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/