start of Enswitch CDR import, RT#11613
[freeside.git] / FS / FS / nas.pm
index 13d0fb8..97b0ea1 100644 (file)
@@ -3,7 +3,7 @@ package FS::nas;
 use strict;
 use vars qw( @ISA );
 use FS::Record qw(qsearchs); #qsearch);
 use strict;
 use vars qw( @ISA );
 use FS::Record qw(qsearchs); #qsearch);
-use FS::UID qw( dbh ); #to lock the tables for heartbeat; ugh, MySQL-specific
+use FS::UID qw( dbh );
 
 @ISA = qw(FS::Record);
 
 
 @ISA = qw(FS::Record);
 
@@ -98,7 +98,7 @@ returns the error, otherwise returns false.
 
 =item check
 
 
 =item check
 
-Checks all fields to make sure this is a valid example.  If there is
+Checks all fields to make sure this is a valid NAS.  If there is
 an error, returns the error, otherwise returns false.  Called by the insert
 and replace methods.
 
 an error, returns the error, otherwise returns false.  Called by the insert
 and replace methods.
 
@@ -114,7 +114,9 @@ sub check {
     || $self->ut_text('nas')
     || $self->ut_ip('nasip')
     || $self->ut_domain('nasfqdn')
     || $self->ut_text('nas')
     || $self->ut_ip('nasip')
     || $self->ut_domain('nasfqdn')
-    || $self->ut_numbern('last');
+    || $self->ut_numbern('last')
+    || $self->SUPER::check
+    ;
 }
 
 =item heartbeat TIMESTAMP
 }
 
 =item heartbeat TIMESTAMP
@@ -126,30 +128,17 @@ Updates the timestamp for this nas
 sub heartbeat {
   my($self, $timestamp) = @_;
   my $dbh = dbh;
 sub heartbeat {
   my($self, $timestamp) = @_;
   my $dbh = dbh;
-  my $sth = $dbh->prepare("LOCK TABLES nas WRITE");
-  $sth->execute or die $sth->errstr; #die?
-  my $lock_self = qsearchs('nas', { 'nasnum' => $self->nasnum } )
-    or die "can't find own record for $self nasnum ". $self->nasnum;
-  if ( $timestamp > $lock_self->last ) {
-    my $new_self = new FS::nas ( { $lock_self->hash } );
-    $new_self->last($timestamp);
-    #is there a reason to? #$self->last($timestamp);
-    $new_self->replace($lock_self);
-  };
-  $sth = $dbh->prepare("UNLOCK TABLES");
-  $sth->execute or die $sth->errstr; #die?
+  my $sth =
+    $dbh->prepare("UPDATE nas SET last = ? WHERE nasnum = ? AND last < ?");
+  $sth->execute($timestamp, $self->nasnum, $timestamp) or die $sth->errstr;
+  $self->last($timestamp);
 }
 
 =back
 
 }
 
 =back
 
-=head1 VERSION
-
-$Id: nas.pm,v 1.4 2001-02-21 01:45:37 ivan Exp $
-
 =head1 BUGS
 
 =head1 BUGS
 
-The B<heartbeat> method is MySQL-specific.  Yuck.  It's also not quite
-perfectly subclassable, which is much less yuck.
+heartbeat method uses SQL directly and doesn't update history tables.
 
 =head1 SEE ALSO
 
 
 =head1 SEE ALSO