- # 7. notes - put them into the common format:
- # "by" = 0 for Ikano; 1 for ISP
- # "priority" = 1 for high priority; 0 otherwise
- my @notes = $result->{'OrderNotes'};
-# XXX
-
- if($wechanged) { # you can't check ->modified, the replace above screws it
- # noexport_hack and AutoCommit are set correctly above
- $result = $svc_dsl->replace;
- return 'Error updating DSL data' if $result;
+ # 7. notes - put them into the common format and compare
+ my $tnotes = $result->{'OrderNotes'};
+ my @tnotes = @$tnotes;
+ my @inotes = (); # all Ikano OrderNotes as FS::dsl_note objects
+ my $notesChanged = 0;
+ foreach $tnote ( @tnotes ) {
+ my $inote = $self->ikano2fsnote($tnote,$svc_dsl->svcnum);
+ return 'Cannot parse note' unless ref($inote);
+ push @inotes, $inote;
+ }
+ my @onotes = $svc_dsl->notes;
+ # assume notes we already have don't change & no notes added from our side
+ # so using the horrible code below just find what we're missing and add it
+ my $error;
+ foreach $inote ( @inotes ) {
+ my $found = 0;
+ foreach $onote ( @onotes ) {
+ if($onote->date == $inote->date && $onote->note eq $inote->note) {
+ $found = 1;
+ last;
+ }
+ }
+ $error = $inote->insert unless ( $found );
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Cannot add note: $error";
+ }
+ }
+
+ $svc_dsl->last_pull((time));
+ local $FS::svc_Common::noexport_hack = 1;
+ $error = $svc_dsl->replace;
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ return "Cannot update DSL data: $error";