Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 90bb521a

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID 90bb521a25eeb37c5bbae1ff68c38e6c142b6e6b
  • Vorgänger b49ec094
  • Nachfolger 66c08b64

Alle Vorkommen von dbdriver, sid, Oracle entfernt

...und gegen das hardcodierte Werte für PostgreSQL ersetzt.

Unterschiede anzeigen:

SL/User.pm
93 93

  
94 94
sub login {
95 95
  my ($self, $form) = @_;
96
  our $sid;
97 96

  
98 97
  return -3 if !$self->{login} || !$::auth->client;
99 98

  
......
103 102
  my $dbh = $form->dbconnect_noauto;
104 103

  
105 104
  # we got a connection, check the version
106
  my $query = qq|SELECT version FROM defaults|;
107
  my $sth   = $dbh->prepare($query);
108
  $sth->execute || $form->dberror($query);
109

  
110
  my ($dbversion) = $sth->fetchrow_array;
111
  $sth->finish;
105
  my ($dbversion) = $dbh->selectrow_array(qq|SELECT version FROM defaults|);
112 106

  
113 107
  $self->create_employee_entry($form, $dbh, \%myconfig);
114 108

  
115 109
  $self->create_schema_info_table($form, $dbh);
116 110

  
117 111
  # Auth DB upgrades available?
118
  my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, dbdriver => 'Pg', auth => 1)->parse_dbupdate_controls;
112
  my $dbupdater_auth = SL::DBUpgrade2->new(form => $form, auth => 1)->parse_dbupdate_controls;
119 113
  return -3 if $dbupdater_auth->unapplied_upgrade_scripts($::auth->dbconnect);
120 114

  
121
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $myconfig{dbdriver})->parse_dbupdate_controls;
115
  my $dbupdater = SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls;
122 116

  
123 117
  $form->{$_} = $::auth->client->{$_} for qw(dbname dbhost dbport dbuser dbpasswd);
124 118
  $form->{$_} = $myconfig{$_}         for qw(dateformat);
......
155 149

  
156 150
  $self->dbupdate($form);
157 151
  $self->dbupdate2($form, $dbupdater);
158
  SL::DBUpgrade2->new(form => $::form, dbdriver => 'Pg', auth => 1)->apply_admin_dbupgrade_scripts(0);
152
  SL::DBUpgrade2->new(form => $::form, auth => 1)->apply_admin_dbupgrade_scripts(0);
159 153

  
160 154
  close($fh);
161 155

  
......
173 167
  my ($form, $db) = @_;
174 168

  
175 169
  my %dboptions = (
176
        'Pg' => { 'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
177
                  'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
178
                  'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
179
                  'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
180
                  'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
181
        },
182
        'Oracle' => {
183
          'yy-mm-dd'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YY-MM-DD\'',
184
          'yyyy-mm-dd' => 'ALTER SESSION SET NLS_DATE_FORMAT = \'YYYY-MM-DD\'',
185
          'mm/dd/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'MM/DD/YY\'',
186
          'dd/mm/yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD/MM/YY\'',
187
          'dd.mm.yy'   => 'ALTER SESSION SET NLS_DATE_FORMAT = \'DD.MM.YY\'',
188
        });
189

  
190
  $form->{dboptions} = $dboptions{ $form->{dbdriver} }{ $form->{dateformat} };
191

  
192
  if ($form->{dbdriver} eq 'Pg') {
193
    $form->{dbconnect} = "dbi:Pg:dbname=$db";
194
  }
195

  
196
  if ($form->{dbdriver} eq 'Oracle') {
197
    $form->{dbconnect} = "dbi:Oracle:sid=$form->{sid}";
198
  }
199

  
200
  if ($form->{dbhost}) {
201
    $form->{dbconnect} .= ";host=$form->{dbhost}";
202
  }
203
  if ($form->{dbport}) {
204
    $form->{dbconnect} .= ";port=$form->{dbport}";
205
  }
206

  
207
  $main::lxdebug->leave_sub();
208
}
209

  
210
sub dbdrivers {
211
  $main::lxdebug->enter_sub();
170
    'yy-mm-dd'   => 'set DateStyle to \'ISO\'',
171
    'yyyy-mm-dd' => 'set DateStyle to \'ISO\'',
172
    'mm/dd/yy'   => 'set DateStyle to \'SQL, US\'',
173
    'dd/mm/yy'   => 'set DateStyle to \'SQL, EUROPEAN\'',
174
    'dd.mm.yy'   => 'set DateStyle to \'GERMAN\''
175
  );
212 176

  
213
  my @drivers = DBI->available_drivers();
177
  $form->{dboptions} = $dboptions{ $form->{dateformat} };
178
  $form->{dbconnect} = "dbi:Pg:dbname=${db};host=" . ($form->{dbhost} || 'localhost') . ";port=" . ($form->{dbport} || 5432);
214 179

  
215 180
  $main::lxdebug->leave_sub();
216

  
217
  return (grep { /(Pg|Oracle)/ } @drivers);
218 181
}
219 182

  
220 183
sub dbsources {
......
226 189
  my ($sth, $query);
227 190

  
228 191
  $form->{dbdefault} = $form->{dbuser} unless $form->{dbdefault};
229
  $form->{sid} = $form->{dbdefault};
230 192
  &dbconnect_vars($form, $form->{dbdefault});
231 193

  
232 194
  my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
233 195
    or $form->dberror;
234 196

  
235
  if ($form->{dbdriver} eq 'Pg') {
236
    $query =
237
      qq|SELECT datname FROM pg_database | .
238
      qq|WHERE NOT datname IN ('template0', 'template1')|;
239
    $sth = $dbh->prepare($query);
240
    $sth->execute() || $form->dberror($query);
241

  
242
    while (my ($db) = $sth->fetchrow_array) {
243

  
244
      if ($form->{only_acc_db}) {
245

  
246
        next if ($db =~ /^template/);
247

  
248
        &dbconnect_vars($form, $db);
249
        my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
250
          or $form->dberror;
251

  
252
        $query =
253
          qq|SELECT tablename FROM pg_tables | .
254
          qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
255
        my $sth = $dbh->prepare($query);
256
        $sth->execute($form->{dbuser}) ||
257
          $form->dberror($query . " ($form->{dbuser})");
258

  
259
        if ($sth->fetchrow_array) {
260
          push(@dbsources, $db);
261
        }
262
        $sth->finish;
263
        $dbh->disconnect;
264
        next;
265
      }
266
      push(@dbsources, $db);
267
    }
268
  }
197
  $query =
198
    qq|SELECT datname FROM pg_database | .
199
    qq|WHERE NOT datname IN ('template0', 'template1')|;
200
  $sth = $dbh->prepare($query);
201
  $sth->execute() || $form->dberror($query);
202

  
203
  while (my ($db) = $sth->fetchrow_array) {
269 204

  
270
  if ($form->{dbdriver} eq 'Oracle') {
271 205
    if ($form->{only_acc_db}) {
272
      $query =
273
        qq|SELECT owner FROM dba_objects | .
274
        qq|WHERE object_name = 'DEFAULTS' AND object_type = 'TABLE'|;
275
    } else {
276
      $query = qq|SELECT username FROM dba_users|;
277
    }
278 206

  
279
    $sth = $dbh->prepare($query);
280
    $sth->execute || $form->dberror($query);
207
      next if ($db =~ /^template/);
208

  
209
      &dbconnect_vars($form, $db);
210
      my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
211
        or $form->dberror;
281 212

  
282
    while (my ($db) = $sth->fetchrow_array) {
283
      push(@dbsources, $db);
213
      $query =
214
        qq|SELECT tablename FROM pg_tables | .
215
        qq|WHERE (tablename = 'defaults') AND (tableowner = ?)|;
216
      my $sth = $dbh->prepare($query);
217
      $sth->execute($form->{dbuser}) ||
218
        $form->dberror($query . " ($form->{dbuser})");
219

  
220
      if ($sth->fetchrow_array) {
221
        push(@dbsources, $db);
222
      }
223
      $sth->finish;
224
      $dbh->disconnect;
225
      next;
284 226
    }
227
    push(@dbsources, $db);
285 228
  }
286 229

  
287 230
  $sth->finish;
......
316 259

  
317 260
  my ($self, $form) = @_;
318 261

  
319
  $form->{sid} = $form->{dbdefault};
320 262
  &dbconnect_vars($form, $form->{dbdefault});
321 263
  my $dbh =
322 264
    SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
323 265
    or $form->dberror;
324 266
  $form->{db} =~ s/\"//g;
325
  my %dbcreate = (
326
    'Pg'     => qq|CREATE DATABASE "$form->{db}"|,
327
    'Oracle' =>
328
    qq|CREATE USER "$form->{db}" DEFAULT TABLESPACE USERS | .
329
    qq|TEMPORARY TABLESPACE TEMP IDENTIFIED BY "$form->{db}"|
330
  );
331 267

  
332
  my %dboptions = (
333
    'Pg' => [],
334
  );
268
  my @dboptions;
335 269

  
336
  push(@{$dboptions{"Pg"}}, "ENCODING = " . $dbh->quote($form->{"encoding"}))
337
    if ($form->{"encoding"});
270
  push @dboptions, "ENCODING = " . $dbh->quote($form->{"encoding"}) if $form->{"encoding"};
338 271
  if ($form->{"dbdefault"}) {
339 272
    my $dbdefault = $form->{"dbdefault"};
340 273
    $dbdefault =~ s/[^a-zA-Z0-9_\-]//g;
341
    push(@{$dboptions{"Pg"}}, "TEMPLATE = $dbdefault");
274
    push @dboptions, "TEMPLATE = $dbdefault";
342 275
  }
343 276

  
344
  my $query = $dbcreate{$form->{dbdriver}};
345
  $query .= " WITH " . join(" ", @{$dboptions{"Pg"}}) if (@{$dboptions{"Pg"}});
277
  my $query = qq|CREATE DATABASE "$form->{db}"|;
278
  $query   .= " WITH " . join(" ", @dboptions) if @dboptions;
346 279

  
347 280
  # Ignore errors if the database exists.
348 281
  $dbh->do($query);
349 282

  
350
  if ($form->{dbdriver} eq 'Oracle') {
351
    $query = qq|GRANT CONNECT, RESOURCE TO "$form->{db}"|;
352
    do_query($form, $dbh, $query);
353
  }
354 283
  $dbh->disconnect;
355 284

  
356
  # setup variables for the new database
357
  if ($form->{dbdriver} eq 'Oracle') {
358
    $form->{dbuser}   = $form->{db};
359
    $form->{dbpasswd} = $form->{db};
360
  }
361

  
362 285
  &dbconnect_vars($form, $form->{db});
363 286

  
364 287
  $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
......
367 290
  my $db_charset = $Common::db_encoding_to_charset{$form->{encoding}};
368 291
  $db_charset ||= Common::DEFAULT_CHARSET;
369 292

  
370
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver});
293
  my $dbupdater = SL::DBUpgrade2->new(form => $form);
371 294
  # create the tables
372 295
  $dbupdater->process_query($dbh, "sql/lx-office.sql", undef, $db_charset);
373 296

  
......
395 318

  
396 319
  my ($self, $form) = @_;
397 320
  $form->{db} =~ s/\"//g;
398
  my %dbdelete = ('Pg'     => qq|DROP DATABASE "$form->{db}"|,
399
                  'Oracle' => qq|DROP USER "$form->{db}" CASCADE|);
400 321

  
401
  $form->{sid} = $form->{dbdefault};
402 322
  &dbconnect_vars($form, $form->{dbdefault});
403 323
  my $dbh = SL::DBConnect->connect($form->{dbconnect}, $form->{dbuser}, $form->{dbpasswd}, SL::DBConnect->get_options)
404 324
    or $form->dberror;
405
  my $query = $dbdelete{$form->{dbdriver}};
325
  my $query = qq|DROP DATABASE "$form->{db}"|;
406 326
  do_query($form, $dbh, $query);
407 327

  
408 328
  $dbh->disconnect;
......
436 356
  my ($self, $form) = @_;
437 357

  
438 358
  my %members   = $main::auth->read_all_users();
439
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver})->parse_dbupdate_controls;
359
  my $dbupdater = SL::DBUpgrade2->new(form => $form)->parse_dbupdate_controls;
440 360

  
441 361
  my ($query, $sth, %dbs_needing_updates);
442 362

  
......
545 465

  
546 466
  local *SQLDIR;
547 467

  
548
  $form->{sid} = $form->{dbdefault};
549

  
550 468
  my @upgradescripts = ();
551 469
  my $query;
552 470
  my $rc = -2;
......
554 472
  if ($form->{dbupdate}) {
555 473

  
556 474
    # read update scripts into memory
557
    opendir(SQLDIR, "sql/" . $form->{dbdriver} . "-upgrade")
558
      or &error("", "sql/" . $form->{dbdriver} . "-upgrade : $!");
475
    opendir(SQLDIR, "sql/Pg-upgrade")
476
      or &error("", "sql/Pg-upgrade : $!");
559 477
    @upgradescripts =
560 478
      sort(cmp_script_version
561
           grep(/$form->{dbdriver}-upgrade-.*?\.(sql|pl)$/,
479
           grep(/Pg-upgrade-.*?\.(sql|pl)$/,
562 480
                readdir(SQLDIR)));
563 481
    closedir(SQLDIR);
564 482
  }
......
566 484
  my $db_charset = $::lx_office_conf{system}->{dbcharset};
567 485
  $db_charset ||= Common::DEFAULT_CHARSET;
568 486

  
569
  my $dbupdater = SL::DBUpgrade2->new(form => $form, dbdriver => $form->{dbdriver});
487
  my $dbupdater = SL::DBUpgrade2->new(form => $form);
570 488

  
571 489
  foreach my $db (split(/ /, $form->{dbupdate})) {
572 490

  
......
591 509

  
592 510
    foreach my $upgradescript (@upgradescripts) {
593 511
      my $a = $upgradescript;
594
      $a =~ s/^\Q$form->{dbdriver}\E-upgrade-|\.(sql|pl)$//g;
512
      $a =~ s/^Pg-upgrade-|\.(sql|pl)$//g;
595 513

  
596 514
      my ($mindb, $maxdb) = split /-/, $a;
597 515
      my $str_maxdb = $maxdb;
......
605 523

  
606 524
      # apply upgrade
607 525
      $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $upgradescript");
608
      $dbupdater->process_file($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade/$upgradescript", $str_maxdb, $db_charset);
526
      $dbupdater->process_file($dbh, "sql/Pg-upgrade/$upgradescript", $str_maxdb, $db_charset);
609 527

  
610 528
      $version = $maxdb;
611 529

  
......
626 544

  
627 545
  my ($self, $form, $dbupdater) = @_;
628 546

  
629
  $form->{sid} = $form->{dbdefault};
630

  
631 547
  my $rc         = -2;
632 548
  my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET;
633 549

  
......
655 571
      $main::lxdebug->message(LXDebug->DEBUG2(), "Applying Update $control->{file}");
656 572
      print $form->parse_html_template("dbupgrade/upgrade_message2", $control);
657 573

  
658
      $dbupdater->process_file($dbh, "sql/" . $form->{"dbdriver"} . "-upgrade2/$control->{file}", $control, $db_charset);
574
      $dbupdater->process_file($dbh, "sql/Pg-upgrade2/$control->{file}", $control, $db_charset);
659 575
    }
660 576

  
661 577
    $rc = 0;

Auch abrufbar als: Unified diff