Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 87e8734c

Von Tamino Steinert vor 10 Monaten hinzugefügt

  • ID 87e8734cc2fe02d956e562b3af81261d46e027ca
  • Vorgänger 470be0b7

FileVersion: Migration: Interaktives Update

FIX: alte Pfadbestimmung kopiert

Unterschiede anzeigen:

locale/de/all
465 465
  'Automatically assigned with bank transaction' => 'Automatisch beim Kontoauszug verbuchen angelegt',
466 466
  'Automatically create new bins' => 'Automatisches Zuweisen der Lagerplätze',
467 467
  'Automatically created invoice for fee and interest for dunning %s' => 'Automatisch erzeugte Rechnung für Gebühren und Zinsen zu Mahnung %s',
468
  'Automatically delete entries for missing files. Ensure that these files are no longer required!' => 'Einträge für fehlende Dateien automatisch löschen. Stellen Sie sicher, dass diese Dateien nicht mehr benötigt werden!',
468 469
  'Available'                   => 'Verfügbar',
469 470
  'Available Prices'            => 'Mögliche Preise',
470 471
  'Available Stock'             => 'verfügbarer Bestand',
......
1558 1559
  'Equity'                      => 'Passiva',
1559 1560
  'Erfolgsrechnung'             => 'Erfolgsrechnung',
1560 1561
  'Error'                       => 'Fehler',
1562
  'Error Message'               => 'Fehlermeldung',
1561 1563
  'Error getting QR-Bill type.' => 'Fehler in QR-Rechnung Varianten Auswahl.',
1562 1564
  'Error handling'              => 'Fehlerbehandlung',
1563 1565
  'Error in database control file \'%s\': %s' => 'Fehler in Datenbankupgradekontrolldatei \'%s\': %s',
......
2382 2384
  'Miscellaneous'               => 'Verschiedenes',
2383 2385
  'Missing \'description\' field.' => 'Fehlendes Feld \'description\'.',
2384 2386
  'Missing \'tag\' field.'      => 'Fehlendes Feld \'tag\'.',
2387
  'Missing Files'               => 'Fehlende Dateien',
2385 2388
  'Missing Method!'             => 'Fehlender Voranmeldungszeitraum',
2386 2389
  'Missing Tax Authoritys Preferences' => 'Fehlende Angaben zum Finanzamt!',
2387 2390
  'Missing amount'              => 'Fehlbetrag',
......
2903 2906
  'Please provide corresponding credentials.' => 'Bitte geben Sie entsprechende Logindaten an.',
2904 2907
  'Please re-run the analysis for broken general ledger entries by clicking this button:' => 'Bitte wiederholen Sie die Analyse der Hauptbucheinträge, indem Sie auf diesen Button klicken:',
2905 2908
  'Please read the file'        => 'Bitte lesen Sie die Datei',
2909
  'Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.' => 'Bitte beheben Sie die Fehler, indem Sie die ungültigen Datenbankeinträge löschen oder die entsprechenden Dateien zu den erwarteten Pfaden hinzufügen.',
2906 2910
  'Please select a customer from the list below.' => 'Bitte einen Endkunden aus der Liste auswählen',
2907 2911
  'Please select a customer.'   => 'Bitte wählen Sie einen Kunden aus.',
2908 2912
  'Please select a deadline date.' => 'Bitte wählen Sie ein Datum für die Fristsetzung aus.',
......
3306 3310
  'Requirement spec template actions' => 'Pflichtenheftvorlagen-Aktionen',
3307 3311
  'Requirement spec text block "#1"; content: "#2"' => 'Pflichtenheft-Textblock "1"; Inhalt: "#2"',
3308 3312
  'Requirement specs'           => 'Pflichtenhefte',
3313
  'Rerun update'                => 'Wiederhole Update',
3309 3314
  'Reset'                       => 'Zurücksetzen',
3310 3315
  'Reset Filter'                => 'Filter zurücksetzen',
3311 3316
  'Result'                      => 'Ergebnis',
locale/en/all
465 465
  'Automatically assigned with bank transaction' => '',
466 466
  'Automatically create new bins' => '',
467 467
  'Automatically created invoice for fee and interest for dunning %s' => '',
468
  'Automatically delete entries for missing files. Ensure that these files are no longer required!' => '',
468 469
  'Available'                   => '',
469 470
  'Available Prices'            => '',
470 471
  'Available Stock'             => '',
......
1558 1559
  'Equity'                      => '',
1559 1560
  'Erfolgsrechnung'             => '',
1560 1561
  'Error'                       => '',
1562
  'Error Message'               => '',
1561 1563
  'Error getting QR-Bill type.' => '',
1562 1564
  'Error handling'              => '',
1563 1565
  'Error in database control file \'%s\': %s' => '',
......
2381 2383
  'Miscellaneous'               => '',
2382 2384
  'Missing \'description\' field.' => '',
2383 2385
  'Missing \'tag\' field.'      => '',
2386
  'Missing Files'               => '',
2384 2387
  'Missing Method!'             => '',
2385 2388
  'Missing Tax Authoritys Preferences' => '',
2386 2389
  'Missing amount'              => '',
......
2902 2905
  'Please provide corresponding credentials.' => '',
2903 2906
  'Please re-run the analysis for broken general ledger entries by clicking this button:' => '',
2904 2907
  'Please read the file'        => '',
2908
  'Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.' => '',
2905 2909
  'Please select a customer from the list below.' => '',
2906 2910
  'Please select a customer.'   => '',
2907 2911
  'Please select a deadline date.' => '',
......
3305 3309
  'Requirement spec template actions' => '',
3306 3310
  'Requirement spec text block "#1"; content: "#2"' => '',
3307 3311
  'Requirement specs'           => '',
3312
  'Rerun update'                => '',
3308 3313
  'Reset'                       => '',
3309 3314
  'Reset Filter'                => '',
3310 3315
  'Result'                      => '',
sql/Pg-upgrade2/add_file_version.pl
9 9
use SL::DB::File;
10 10
use SL::File::Backend::Webdav;
11 11

  
12
use SL::Locale::String qw(t8);
12 13
use SL::System::Process;
13 14

  
14 15
use UUID::Tiny ':std';
......
16 17
use parent qw(SL::DBUpgrade2::Base);
17 18

  
18 19
sub get_all_versions {
19
  my ($fileobj) = @_;
20
  my ($dbfile) = @_;
20 21

  
21 22
  my @versionobjs;
23
  my $fileobj = SL::File::Object->new(
24
    db_file => $dbfile,
25
    id => $dbfile->id,
26
    loaded => 1,
27
  );
22 28

  
23
  my $maxversion = $fileobj->version_count;
29
  my $maxversion = $fileobj->backend eq 'Filesystem' ? $fileobj->db_file->backend_data : 1;
24 30
  $fileobj->version($maxversion);
25 31
  push @versionobjs, $fileobj;
26 32
  if ($maxversion > 1) {
......
31 37
      push @versionobjs, $clone;
32 38
    }
33 39
  }
40

  
41
  return @versionobjs;
42
}
43

  
44
sub get_filepath {
45
  my ($file_obj) = @_;
46

  
47
  my $file_id = $file_obj->id;
48
  my $backend = $file_obj->backend
49
    or die "File with ID '$file_id' has no backend specified.";
50
  my $db_file   = $file_obj->db_file;
51
  my $file_name = $file_obj->file_name;
52
  my $version   = $file_obj->version;
53

  
54
  my $path;
55
  if ($backend eq 'Webdav') {
56
    ($path) = $file_obj->backend_class->webdav_path($db_file);
57
  } elsif ($backend eq 'Filesystem') {
58
    # use filesystem with depth 3
59
    my $iddir   = sprintf("%04d", $db_file->id % 1000);
60
    my $base_path    = File::Spec->catdir($::lx_office_conf{paths}->{document_path}, $::auth->client->{id}, $iddir, $db_file->id);
61
    $path = File::Spec->catdir($base_path, $db_file->id . '_' . $version);
62
  } else {
63
    die "Unknown backend '$backend' for file with ID '$file_id'.";
64
  }
65

  
66
  die "No file found at $path. Expected: $file_name, file.id: $file_id" if !-f $path;
67
  return $path;
68
}
69

  
70
sub test_all_files_exists {
71
  my @errors;
72

  
73
  my $all_dbfiles = SL::DB::Manager::File->get_all;
74

  
75
  foreach my $dbfile (@{$all_dbfiles}) {
76
    my @versions = get_all_versions($dbfile);
77
    foreach my $version (@versions) {
78
      eval {
79
        get_filepath($version);
80
      } or do {
81
        push @errors, $@;
82
      }
83
    }
84
  }
85

  
86
  return @errors;
87
}
88

  
89
sub print_errors {
90
  my ($self, $errors) = @_;
91

  
92
  print $::form->parse_html_template("dbupgrade/add_file_version_form", {
93
      ERRORS => $errors
94
    });
34 95
}
35 96

  
36 97
sub run {
37 98
  my ($self) = @_;
38 99

  
100
  my $query = <<SQL;
101
SELECT f.id
102
FROM files f
103
FULL OUTER JOIN file_versions fv ON (f.id = fv.file_id)
104
GROUP BY f.id
105
HAVING count(fv.file_id) = 0
106
SQL
107
  my @file_ids_without_version = map {$_->[0]} @{$self->dbh->selectall_arrayref($query)};
108

  
109
  unless ($::form->{delete_file_entries_of_missing_files}) {
110
    my @errors = $self->test_all_files_exists();
111
    if (scalar @errors) {
112
      $self->print_errors(\@errors);
113
      return 2;
114
    }
115
  }
116

  
39 117
  SL::DB->client->with_transaction(sub {
40 118
    my @errors;
41 119
    my $all_dbfiles = SL::DB::Manager::File->get_all;
......
57 135
      foreach my $version (@versions) {
58 136
        my $tofile;
59 137
        eval {
60
          $tofile = $version->get_file();
138
          $tofile = get_filepath($version);
61 139
        } or do {
62
          my @values;
63
          push @values, $@; # error message
64
          push @values, $version->file_name;
65
          push @values, $version->id;
66
          push @errors, '<td>' . join('</td><td>', @values) . '</td>';;
67 140
          next;
68 141
        };
69 142
        my $rel_file = $tofile;
70 143
        $rel_file    =~ s/$doc_path//;
71 144

  
72 145
        my $fv = SL::DB::FileVersion->new(
73
                              file_id       => $dbfile->id,
74
                              version       => $version->version || 1,
75
                              file_location => $rel_file,
76
                              doc_path      => $doc_path,
77
                              backend       => $dbfile->backend,
78
                              guid          => create_uuid_as_string(UUID_V4),
79
                            )->save;
146
          file_id       => $dbfile->id,
147
          version       => $version->version || 1,
148
          file_location => $rel_file,
149
          doc_path      => $doc_path,
150
          backend       => $dbfile->backend,
151
          guid          => create_uuid_as_string(UUID_V4),
152
        )->save;
80 153
      }
81 154
    }
82
    if (scalar @errors) {
83
      my $error_message = <<MESSAGE;
84
Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.
85
To delete the invalid database entries, run the 'RemoveInvalidFileEntries' background job. Before running the background job, ensure that these files are no longer required.
86
<table class="tbl-list" border="1" style="border-collapse: collapse">
87
  <thead><tr>
88
    <th>error message</th>
89
    <th>file_name</th>
90
    <th>file_id</th>
91
  </tr></thead>
92
MESSAGE
93
      $error_message .= '<tr>' . join('</tr><tr>', @errors) . '</tr>';
94
      $error_message .= '</table>';
95
      die $error_message;
155

  
156
    my $query = <<SQL;
157
SELECT f.id
158
FROM files f
159
FULL OUTER JOIN file_versions fv ON (f.id = fv.file_id)
160
GROUP BY f.id
161
HAVING count(fv.file_id) = 0
162
SQL
163
    my @file_ids_without_version =
164
      map {$_->[0]}
165
      @{SL::DB::->client->dbh->selectall_arrayref($query)};
166
    if (scalar @file_ids_without_version) {
167
      if ($::form->{delete_file_entries_of_missing_files}) {
168
        SL::DB::Manager::File->delete_all(where => [id => \@file_ids_without_version]);
169
      } else {
170
        die "Files without versions: " . join(', ', @file_ids_without_version);
171
      }
96 172
    }
173

  
97 174
    1;
98 175
  }) or do { die SL::DB->client->error };
99 176

  
templates/design40_webpages/dbupgrade/add_file_version_form.html
1
[%- USE T8 %]
2
[%- USE P %]
3
[%- USE LxERP %]
4
[%- USE HTML %]
5

  
6
<div class="wrapper">
7
  <h1>[% 'Missing Files' | $T8 %]</h1>
8
  <form name="Form" method="post" action="login.pl">
9
    <input type="hidden" name="action" value="login">
10

  
11
    [% 'Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.' | $T8 %]
12
    <table class="tbl-list">
13
      <thead><tr>
14
        <th>[% 'Error Message' | $T8 %]</th>
15
      </tr></thead>
16
      <tbody>
17
        [% FOREACH error = ERRORS %]
18
        <tr><td>
19
          [% error | html %]
20
        </td></tr>
21
        [% END %]
22
      </tbody>
23
    </table>
24
    [% P.checkbox_tag(
25
      "delete_file_entries_of_missing_files", value=1,
26
      label=LxERP.t8("Automatically delete entries for missing files. Ensure that these files are no longer required!")
27
    ) %]
28
    <br>
29
    [% P.submit_tag("rerun_add_file_version", LxERP.t8("Rerun update")) %]
30
  </form>
31
</div>
templates/webpages/dbupgrade/add_file_version_form.html
1
[%- USE T8 %]
2
[%- USE P %]
3
[%- USE LxERP %]
4
[%- USE HTML %]
5

  
6
<h1>[% 'Missing Files' | $T8 %]</h1>
7
<form name="Form" method="post" action="login.pl">
8
  <input type="hidden" name="action" value="login">
9

  
10
  [% 'Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.' | $T8 %]
11
  <table border="1" style="border-collapse: collapse">
12
    <thead><tr>
13
      <th>[% 'Error Message' | $T8 %]</th>
14
    </tr></thead>
15
    <tbody>
16
      [% FOREACH error = ERRORS %]
17
      <tr><td>
18
        [% error | html %]
19
      </td></tr>
20
      [% END %]
21
    </tbody>
22
  </table>
23
  [% P.checkbox_tag(
24
    "delete_file_entries_of_missing_files", value=1,
25
    label=LxERP.t8("Automatically delete entries for missing files. Ensure that these files are no longer required!")
26
  ) %]
27
  <br>
28
  [% P.submit_tag("rerun_add_file_version", LxERP.t8("Rerun update")) %]
29
</form>

Auch abrufbar als: Unified diff