[vhffs-dev] [922] Replaced timestamp to int8 and now using DateTime to display human readable dates

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


Revision: 922
Author:   gradator
Date:     2007-09-14 02:04:13 +0000 (Fri, 14 Sep 2007)

Log Message:
-----------
Replaced timestamp to int8 and now using DateTime to display human readable dates

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Functions.pm
    trunk/vhffs-api/src/Vhffs/Mailings.pm
    trunk/vhffs-api/src/Vhffs/Object.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-compat/4.0.sql.in
    trunk/vhffs-panel/admin/object/edit.pl
    trunk/vhffs-panel/group/history.pl
    trunk/vhffs-panel/history.pl
    trunk/vhffs-robots/src/object_cleanup.pl


Modified: trunk/vhffs-api/src/Vhffs/Functions.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Functions.pm	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-api/src/Vhffs/Functions.pm	2007-09-14 02:04:13 UTC (rev 922)
@@ -423,29 +423,6 @@
 }
 
 
-
-sub parse_date
-{
-	my $string = shift;
-    my $result = {};
-
-    if( $string =~ /(\d+)\-(\d+)\-(\d+)\s(\d+):(\d+):(\d+).*/ )
-    {
-        $result->{year} = $1;
-        $result->{month} = $2;
-        $result->{day} = $3;
-        $result->{hours} = $4;
-        $result->{minutes} = $5;
-        $result->{seconds} = $6;
-    }
-    else
-    {
-        return undef;
-    }
-    return $result;
-}
-
-
 sub valid_mail
 {
 	my $mail = shift;

Modified: trunk/vhffs-api/src/Vhffs/Mailings.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Mailings.pm	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-api/src/Vhffs/Mailings.pm	2007-09-14 02:04:13 UTC (rev 922)
@@ -48,9 +48,9 @@
 	
 	return -1 if ( ! defined $vhffs );
 
-	$query = 'INSERT INTO vhffs_mailings (subject,message,date,state) VALUES( ? , ? , NOW() , ? )';
+	$query = 'INSERT INTO vhffs_mailings (subject,message,date,state) VALUES( ? , ? , ? , ? )';
 	$request = $vhffs->{'db'}->prepare( $query );
-	$request->execute($subject, $message, Vhffs::Constants::WAITING_FOR_CREATION) or return -2;
+	$request->execute($subject, $message, time(), Vhffs::Constants::WAITING_FOR_CREATION) or return -2;
 
 	return 1;
 }

Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-api/src/Vhffs/Object.pm	2007-09-14 02:04:13 UTC (rev 922)
@@ -184,8 +184,8 @@
    my ($vhffs, $owner_uid, $owner_gid, $description, $state, $type) = @_;
     $description = '' unless (defined $description);
     $state = ($vhffs->get_config->get_moderation ? Vhffs::Constants::WAITING_FOR_VALIDATION : Vhffs::Constants::WAITING_FOR_CREATION) unless defined $state;
-    my $sth = $vhffs->get_db_object->prepare('INSERT INTO vhffs_object(owner_uid, owner_gid, date_creation, state, description, type) VALUES ( ?, ?, NOW(), ?, ?, ?)');
-    $sth->execute($owner_uid, $owner_gid, $state, $description, $type) or return undef;
+    my $sth = $vhffs->get_db_object->prepare('INSERT INTO vhffs_object(owner_uid, owner_gid, date_creation, state, description, type) VALUES ( ?, ?, ?, ?, ?, ?)');
+    $sth->execute($owner_uid, $owner_gid, time(), $state, $description, $type) or return undef;
     my $oid = $vhffs->get_db_object->last_insert_id(undef, undef, 'vhffs_object', undef);
 
     my $res = get_by_oid($vhffs, $oid);
@@ -358,9 +358,9 @@
 	my $message = shift;
 	$message = $message;
 
-	$query = 'INSERT INTO vhffs_history(object_id, date, message)  VALUES(?, NOW(), ?)';
+	$query = 'INSERT INTO vhffs_history(object_id, date, message)  VALUES(?, ?, ?)';
 	$request = $self->{'db'}->prepare( $query );
-	$request->execute( $self->{'object_id'}, $message ) or return -2;
+	$request->execute( $self->{'object_id'}, time(), $message ) or return -2;
 
 	return $self->{'db'}->last_insert_id(undef, undef, 'vhffs_history', undef);;
 }
@@ -553,7 +553,7 @@
 	my $vhffs = shift;
 	my $name = shift;
 	my $state = shift;
-	my $age = shift; #arg for postgresql interval function
+	my $age = shift; #seconds late
 
 	my $query = 'SELECT o.object_id, o.owner_uid, o.owner_gid, o.date_creation , o.description, o.refuse_reason, o.state, o.type FROM vhffs_object o';
 	my @params;
@@ -580,13 +580,15 @@
 	}
 	if( defined $age )
 	{
+		my $ts = time() - $age;
+
 		if( $query =~ /WHERE/ )  {
-			$query .= ' AND age(current_timestamp, date_creation) > CAST(? AS interval) ';
+			$query .= ' AND date_creation < ? ';
 		}
 		else {
-			$query .= ' WHERE age(current_timestamp, date_creation) > CAST(? AS interval) ';
+			$query .= ' WHERE date_creation < ? ';
 		}
-		push(@params, $age);
+		push(@params, $ts);
 	}
 
 	$query .= ' ORDER BY object_id';

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2007-09-14 02:04:13 UTC (rev 922)
@@ -35,7 +35,7 @@
 	object_id serial,
 	owner_uid int4 NOT NULL,
 	owner_gid int4 NOT NULL,
-	date_creation timestamp NOT NULL,
+	date_creation int8 NOT NULL,
 	state int4 NOT NULL,
 	description TEXT,
 	refuse_reason TEXT,
@@ -171,7 +171,7 @@
 	id_mailing serial,
 	subject VARCHAR NOT NULL,
 	message TEXT NOT NULL,
-	date timestamp,
+	date int8,
 	state int4 NOT NULL,
 	CONSTRAINT vhffs_mailings_pkey PRIMARY KEY (id_mailing)
 ) WITH OIDS;
@@ -230,7 +230,7 @@
 (
 	history_id serial,
 	object_id int4 NOT NULL,
-	date timestamp NOT NULL,
+	date int8 NOT NULL,
 	message varchar(200),
 	CONSTRAINT vhffs_history_pkey PRIMARY KEY (history_id)
 ) WITH OIDS;

Modified: trunk/vhffs-compat/4.0.sql.in
===================================================================
--- trunk/vhffs-compat/4.0.sql.in	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-compat/4.0.sql.in	2007-09-14 02:04:13 UTC (rev 922)
@@ -330,3 +330,27 @@
 -- vhffs_boxes
 ALTER TABLE vhffs_boxes DROP COLUMN password;
 ALTER TABLE vhffs_boxes RENAME COLUMN password_hash TO password;
+
+-- change timestamps to int8 (Perl has very good date modules)
+BEGIN;
+ALTER TABLE vhffs_object ADD COLUMN date_creation_new int8;
+UPDATE vhffs_object SET date_creation_new = EXTRACT(EPOCH FROM date_creation)::int8;
+ALTER TABLE vhffs_object DROP COLUMN date_creation CASCADE;
+ALTER TABLE vhffs_object RENAME COLUMN date_creation_new TO date_creation;
+ALTER TABLE vhffs_object ALTER COLUMN date_creation SET NOT NULL;
+COMMIT;
+
+BEGIN;
+ALTER TABLE vhffs_mailings ADD COLUMN date_new int8;
+UPDATE vhffs_mailings SET date_new = EXTRACT(EPOCH FROM date)::int8;
+ALTER TABLE vhffs_mailings DROP COLUMN date CASCADE;
+ALTER TABLE vhffs_mailings RENAME COLUMN date_new TO date;
+COMMIT;
+
+BEGIN;
+ALTER TABLE vhffs_history ADD COLUMN date_new int8;
+UPDATE vhffs_history SET date_new = EXTRACT(EPOCH FROM date)::int8;
+ALTER TABLE vhffs_history DROP COLUMN date CASCADE;
+ALTER TABLE vhffs_history RENAME COLUMN date_new TO date;
+ALTER TABLE vhffs_history ALTER COLUMN date SET NOT NULL;
+COMMIT;

Modified: trunk/vhffs-panel/admin/object/edit.pl
===================================================================
--- trunk/vhffs-panel/admin/object/edit.pl	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-panel/admin/object/edit.pl	2007-09-14 02:04:13 UTC (rev 922)
@@ -207,17 +207,10 @@
         foreach( keys %{$history} )
         {
             my $subtemplate = new HTML::Template( filename => $templatesdir."/panel/misc/history_part.tmpl" );
-			my $date =  Vhffs::Functions::parse_date( $history->{$_}{date} );
-            if( defined $date )
-            {
-                $string = $date->{day}."/".$date->{month}."/".$date->{year}." @ ".$date->{hours}.":".$date->{minutes}.":".$date->{seconds};
-				
-			}
-            else
-            {
-                $string = gettext("no information about date");
-            }
-            $subtemplate->param( DATE => $string );
+            use DateTime;
+            use DateTime::Locale;
+            use Encode;
+            $subtemplate->param( DATE => Encode::encode_utf8( DateTime->from_epoch( epoch => $history->{$_}{date} , locale => $user->get_lang )->strftime("%a, %d %b %Y %H:%M:%S %z") ) );
             $subtemplate->param( EVENT => $history->{$_}{message} );
             $output .= $subtemplate->output;
         }

Modified: trunk/vhffs-panel/group/history.pl
===================================================================
--- trunk/vhffs-panel/group/history.pl	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-panel/group/history.pl	2007-09-14 02:04:13 UTC (rev 922)
@@ -95,17 +95,10 @@
 		foreach( sort { $a <=> $b } keys %{$history} )
 		{
 			$subtemplate = new HTML::Template( filename => $templatedir."/panel/group/history_part.tmpl" );
-			my $date = Vhffs::Functions::parse_date( $history->{$_}{date} );
-			my $datestr;
-			if( defined $date )
-			{
-				$datestr = $date->{day}."/".$date->{month}."/".$date->{year}." @ ".$date->{hours}.":".$date->{minutes}.":".$date->{seconds};
-			}
-			else
-			{
-				$datestr = gettext("no information about date");
-			}
-			$subtemplate->param( DATE => $datestr );
+			use DateTime;
+			use DateTime::Locale;
+			use Encode;
+			$subtemplate->param( DATE => Encode::encode_utf8( DateTime->from_epoch( epoch => $history->{$_}{date}, locale => $user->get_lang )->strftime("%a, %d %b %Y %H:%M:%S %z") ) );			
 			$subtemplate->param( TYPE => Vhffs::Functions::type_string_from_type_id( $history->{$_}{type} ) );
 			my $object = Vhffs::ObjectFactory::fetch_object( $vhffs , $history->{$_}{object_id} );
 			$subtemplate->param( NAME => $object->get_label );

Modified: trunk/vhffs-panel/history.pl
===================================================================
--- trunk/vhffs-panel/history.pl	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-panel/history.pl	2007-09-14 02:04:13 UTC (rev 922)
@@ -119,16 +119,10 @@
 		foreach( sort { $a <=> $b } keys %{$history} )
 		{
 			$subtemplate = new HTML::Template( filename => $templatesdir."/panel/misc/history_part.tmpl" );
-			$date =  Vhffs::Functions::parse_date( $history->{$_}{date} );
-			if( defined $date )
-			{
-				$string = $date->{day}."/".$date->{month}."/".$date->{year}." @ ".$date->{hours}.":".$date->{minutes}.":".$date->{seconds};
-			}
-			else
-			{
-				$string = gettext("no information about date");
-			}
-			$subtemplate->param( DATE => $string );
+			use DateTime;
+			use DateTime::Locale;
+			use Encode;
+			$subtemplate->param( DATE => Encode::encode_utf8( DateTime->from_epoch( epoch => $history->{$_}{date} , locale => $user->get_lang )->strftime("%a, %d %b %Y %H:%M:%S %z") ) );
 			$subtemplate->param( EVENT => $history->{$_}{message} );
 			$output .= $subtemplate->output;
 		}

Modified: trunk/vhffs-robots/src/object_cleanup.pl
===================================================================
--- trunk/vhffs-robots/src/object_cleanup.pl	2007-09-13 22:37:24 UTC (rev 921)
+++ trunk/vhffs-robots/src/object_cleanup.pl	2007-09-14 02:04:13 UTC (rev 922)
@@ -42,7 +42,7 @@
 
 Vhffs::Robots::lock( $vhffs , 'object' );
 
-my $objects = Vhffs::Object::getall( $vhffs , undef, Vhffs::Constants::VALIDATION_REFUSED , '15 day' );
+my $objects = Vhffs::Object::getall( $vhffs , undef, Vhffs::Constants::VALIDATION_REFUSED , 1296000 );   # 15 days
 foreach my $object ( @{$objects} )
 {
 	$object = Vhffs::ObjectFactory::fetch_object( $vhffs , $object->get_oid );


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