]> git.sesse.net Git - skvidarsync/commitdiff
Use seen_names for the final location.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 28 Oct 2023 11:50:13 +0000 (13:50 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 28 Oct 2023 11:50:13 +0000 (13:50 +0200)
bin/sync.pl

index 5d09c24c893cee9000a564048753dff392b08ca2..3f07537389ce496e1655b2df1e0104f6baa95256 100644 (file)
@@ -396,41 +396,32 @@ if (scalar @diffs > 0) {
                my $real_name = $diff->[0];
 
                # See if we can find them in the spreadsheet.
-               # FIXME use seen_names
-               my $rowno = 8;  # zero-indexed
-               my $found = 0;
-               for my $row (@$main_sheet_rows) {
-                       my $colno = 0;
-                       for my $val (@{$row->{'values'}}) {
-                               my $name = get_spreadsheet_name($val);
-                               if (defined($name) && $real_name eq $name) {
-                                       push @yellow_updates, {
-                                               updateCells => {
-                                                       rows => [{
-                                                               values => [{
-                                                                       userEnteredFormat => $diff->[1]
-                                                               }]
-                                                       }],
-                                                       fields => 'userEnteredFormat.backgroundColor',
-                                                       range => {
-                                                               sheetId => $tab_id,
-                                                               startRowIndex => $rowno,
-                                                               endRowIndex => $rowno + 1,
-                                                               startColumnIndex => $colno,
-                                                               endColumnIndex => $colno + 1
-                                                       }
-                                               }
-                                       };
-                                       $found = 1;
-                               }
-                               ++$colno;
-                       }
-                       ++$rowno;
-               }
-
-               if ($found) {
-               } else {
+               if (!exists($seen_names{lc $real_name})) {
+                       # This can only happen on deletes; we don't add such cases to the positive diff.
+                       # FIXME we'd still delete them from the database.
                        skv_log("Ønsket å fjerne at $real_name skulle på trening, men de var ikke i regnearket lenger.");
+               } else {
+                       my $seen = $seen_names{lc $real_name};
+                       die if (scalar @$seen > 1);
+                       my $rowno = $seen->[0][1];
+                       my $colno = $seen->[0][2];
+                       push @yellow_updates, {
+                               updateCells => {
+                                       rows => [{
+                                               values => [{
+                                                       userEnteredFormat => $diff->[1]
+                                               }]
+                                       }],
+                                       fields => 'userEnteredFormat.backgroundColor',
+                                       range => {
+                                               sheetId => $tab_id,
+                                               startRowIndex => $rowno,
+                                               endRowIndex => $rowno + 1,
+                                               startColumnIndex => $colno,
+                                               endColumnIndex => $colno + 1
+                                       }
+                               }
+                       };
                }
        }
 }