Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 71c1b574

Von Tamino Steinert vor 7 Monaten hinzugefügt

  • ID 71c1b57464aa3e1aa8235321ee1c7896baf43ea6
  • Vorgänger b3cc7b97
  • Nachfolger 6da526ef

FileVersion: Migration: Interaktives Update

FIX: alte Pfadbestimmung kopiert

Unterschiede anzeigen:

locale/de/all
467 467
  'Automatically assigned with bank transaction' => 'Automatisch beim Kontoauszug verbuchen angelegt',
468 468
  'Automatically create new bins' => 'Automatisches Zuweisen der Lagerplätze',
469 469
  'Automatically created invoice for fee and interest for dunning %s' => 'Automatisch erzeugte Rechnung für Gebühren und Zinsen zu Mahnung %s',
470
  '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!',
470 471
  'Available'                   => 'Verfügbar',
471 472
  'Available Prices'            => 'Mögliche Preise',
472 473
  'Available Stock'             => 'verfügbarer Bestand',
......
1565 1566
  'Equity'                      => 'Passiva',
1566 1567
  'Erfolgsrechnung'             => 'Erfolgsrechnung',
1567 1568
  'Error'                       => 'Fehler',
1569
  'Error Message'               => 'Fehlermeldung',
1568 1570
  'Error getting QR-Bill type.' => 'Fehler in QR-Rechnung Varianten Auswahl.',
1569 1571
  'Error handling'              => 'Fehlerbehandlung',
1570 1572
  'Error in database control file \'%s\': %s' => 'Fehler in Datenbankupgradekontrolldatei \'%s\': %s',
......
2394 2396
  'Miscellaneous'               => 'Verschiedenes',
2395 2397
  'Missing \'description\' field.' => 'Fehlendes Feld \'description\'.',
2396 2398
  'Missing \'tag\' field.'      => 'Fehlendes Feld \'tag\'.',
2399
  'Missing Files'               => 'Fehlende Dateien',
2397 2400
  'Missing Method!'             => 'Fehlender Voranmeldungszeitraum',
2398 2401
  'Missing Tax Authoritys Preferences' => 'Fehlende Angaben zum Finanzamt!',
2399 2402
  'Missing amount'              => 'Fehlbetrag',
......
2921 2924
  'Please provide corresponding credentials.' => 'Bitte geben Sie entsprechende Logindaten an.',
2922 2925
  '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:',
2923 2926
  'Please read the file'        => 'Bitte lesen Sie die Datei',
2927
  '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.',
2924 2928
  'Please select a customer from the list below.' => 'Bitte einen Endkunden aus der Liste auswählen',
2925 2929
  'Please select a customer.'   => 'Bitte wählen Sie einen Kunden aus.',
2926 2930
  'Please select a deadline date.' => 'Bitte wählen Sie ein Datum für die Fristsetzung aus.',
......
3326 3330
  'Requirement spec template actions' => 'Pflichtenheftvorlagen-Aktionen',
3327 3331
  'Requirement spec text block "#1"; content: "#2"' => 'Pflichtenheft-Textblock "1"; Inhalt: "#2"',
3328 3332
  'Requirement specs'           => 'Pflichtenhefte',
3333
  'Rerun update'                => 'Wiederhole Update',
3329 3334
  'Reset'                       => 'Zurücksetzen',
3330 3335
  'Reset Filter'                => 'Filter zurücksetzen',
3331 3336
  'Result'                      => 'Ergebnis',
locale/en/all
467 467
  'Automatically assigned with bank transaction' => '',
468 468
  'Automatically create new bins' => '',
469 469
  'Automatically created invoice for fee and interest for dunning %s' => '',
470
  'Automatically delete entries for missing files. Ensure that these files are no longer required!' => '',
470 471
  'Available'                   => '',
471 472
  'Available Prices'            => '',
472 473
  'Available Stock'             => '',
......
1565 1566
  'Equity'                      => '',
1566 1567
  'Erfolgsrechnung'             => '',
1567 1568
  'Error'                       => '',
1569
  'Error Message'               => '',
1568 1570
  'Error getting QR-Bill type.' => '',
1569 1571
  'Error handling'              => '',
1570 1572
  'Error in database control file \'%s\': %s' => '',
......
2393 2395
  'Miscellaneous'               => '',
2394 2396
  'Missing \'description\' field.' => '',
2395 2397
  'Missing \'tag\' field.'      => '',
2398
  'Missing Files'               => '',
2396 2399
  'Missing Method!'             => '',
2397 2400
  'Missing Tax Authoritys Preferences' => '',
2398 2401
  'Missing amount'              => '',
......
2920 2923
  'Please provide corresponding credentials.' => '',
2921 2924
  'Please re-run the analysis for broken general ledger entries by clicking this button:' => '',
2922 2925
  'Please read the file'        => '',
2926
  'Please resolve the errors by deleting the invalid database entries or by adding the corresponding files to the expected paths.' => '',
2923 2927
  'Please select a customer from the list below.' => '',
2924 2928
  'Please select a customer.'   => '',
2925 2929
  'Please select a deadline date.' => '',
......
3325 3329
  'Requirement spec template actions' => '',
3326 3330
  'Requirement spec text block "#1"; content: "#2"' => '',
3327 3331
  'Requirement specs'           => '',
3332
  'Rerun update'                => '',
3328 3333
  'Reset'                       => '',
3329 3334
  'Reset Filter'                => '',
3330 3335
  '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