View | Details | Raw Unified | Return to bug 20271
Collapse All | Expand All

(-)a/installer/data/mysql/atomicupdate/bug_20271_-_merge_deletedbiblio_and_deleteitems_tables_with_their_alive_cousins.perl (-17 / +18 lines)
Lines 6-14 if( CheckVersion( $DBversion ) ) { Link Here
6
    $dbh->do( "ALTER TABLE items ADD COLUMN deleted_at datetime DEFAULT NULL" ) or warn $DBI::errstr;
6
    $dbh->do( "ALTER TABLE items ADD COLUMN deleted_at datetime DEFAULT NULL" ) or warn $DBI::errstr;
7
7
8
    # Need to disable foreign keys on deletedbiblio_metadata to avoid cascading deletes from deletedbiblio
8
    # Need to disable foreign keys on deletedbiblio_metadata to avoid cascading deletes from deletedbiblio
9
    # Bug 17196 introduced a mismatch in foreign keys of deletedbiblio_metadata, so dropping would fail
9
    # Bug 17196 introduced a mismatch in foreign keys of deletedbiblio_metadata, so any key must be dropped
10
    $dbh->do( "ALTER TABLE deletedbiblio_metadata DISABLE KEYS" );
10
    DropAllForeignKeys('deletedbiblio_metadata');
11
12
    $dbh->do( "INSERT IGNORE INTO biblio SELECT *, timestamp AS deleted_at FROM deletedbiblio" ) or warn $DBI::errstr;
11
    $dbh->do( "INSERT IGNORE INTO biblio SELECT *, timestamp AS deleted_at FROM deletedbiblio" ) or warn $DBI::errstr;
13
    $dbh->do( "INSERT IGNORE INTO biblioitems SELECT *, timestamp AS deleted_at FROM deletedbiblioitems" ) or warn $DBI::errstr;
12
    $dbh->do( "INSERT IGNORE INTO biblioitems SELECT *, timestamp AS deleted_at FROM deletedbiblioitems" ) or warn $DBI::errstr;
14
    $dbh->do( "INSERT IGNORE INTO biblio_metadata SELECT *, timestamp AS deleted_at FROM deletedbiblio_metadata" ) or warn $DBI::errstr;
13
    $dbh->do( "INSERT IGNORE INTO biblio_metadata SELECT *, timestamp AS deleted_at FROM deletedbiblio_metadata" ) or warn $DBI::errstr;
Lines 22-28 if( CheckVersion( $DBversion ) ) { Link Here
22
        $sth->execute();
21
        $sth->execute();
23
        my $row = $sth->fetchrow_hashref;
22
        my $row = $sth->fetchrow_hashref;
24
        if ($row->{count}) {
23
        if ($row->{count}) {
25
            warn "There were $row->{count} deleteditems that could not be moved, please check '_deleteditems'.";
24
            print "Warning to database administrator:\n"
25
                . "There were $row->{count} deleteditems that could not be moved, please check '_deleteditems'.\n";
26
            $dbh->do("RENAME TABLE deleteditems TO _deleteditems");
26
            $dbh->do("RENAME TABLE deleteditems TO _deleteditems");
27
        } else {
27
        } else {
28
            $dbh->do("DROP TABLE deleteditems");
28
            $dbh->do("DROP TABLE deleteditems");
Lines 36-42 if( CheckVersion( $DBversion ) ) { Link Here
36
        $sth->execute();
36
        $sth->execute();
37
        my $row = $sth->fetchrow_hashref;
37
        my $row = $sth->fetchrow_hashref;
38
        if ($row->{count}) {
38
        if ($row->{count}) {
39
            warn "There were $row->{count} deletedbiblio_metadata that could not be moved, please check '_deletedbiblio_metadata'.";
39
            print "Warning to database administrator:\n"
40
                . "There were $row->{count} deletedbiblio_metadata that could not be moved, please check '_deletedbiblio_metadata'.\n";
40
            $dbh->do("RENAME TABLE deletedbiblio_metadata TO _deletedbiblio_metadata");
41
            $dbh->do("RENAME TABLE deletedbiblio_metadata TO _deletedbiblio_metadata");
41
        } else {
42
        } else {
42
            $dbh->do("DROP TABLE deletedbiblio_metadata");
43
            $dbh->do("DROP TABLE deletedbiblio_metadata");
Lines 44-77 if( CheckVersion( $DBversion ) ) { Link Here
44
    }
45
    }
45
46
46
    {
47
    {
47
        my $sth = $dbh->prepare("DELETE FROM deletedbiblio WHERE biblionumber IN (SELECT biblionumber FROM biblio)");
48
        my $sth = $dbh->prepare("DELETE FROM deletedbiblioitems WHERE biblioitemnumber IN (SELECT biblioitemnumber FROM biblioitems)");
48
        $sth->execute();
49
        $sth->execute();
49
        $sth = $dbh->prepare("SELECT COUNT(*) AS count FROM deletedbiblio WHERE biblionumber NOT IN (SELECT biblionumber FROM deletedbiblioitems)");
50
        $sth = $dbh->prepare("SELECT COUNT(*) AS count FROM deletedbiblioitems");
50
        $sth->execute();
51
        $sth->execute();
51
        my $row = $sth->fetchrow_hashref;
52
        my $row = $sth->fetchrow_hashref;
52
        if ($row->{count}) {
53
        if ($row->{count}) {
53
            warn "There were $row->{count} deletedbiblio that could not be moved, please check '_deletedbiblio'.";
54
            print "Warning to database administrator:\n"
54
            $dbh->do("RENAME TABLE deletedbiblio TO _deletedbiblio");
55
                . "There were $row->{count} deletedbiblioitems that could not be moved, please check '_deletedbiblioitems'.\n";
56
            $dbh->do("RENAME TABLE deletedbiblioitems TO _deletedbiblioitems");
55
        } else {
57
        } else {
56
            $dbh->do("DROP TABLE deletedbiblio");
58
            $dbh->do("DROP TABLE deletedbiblioitems");
57
        }
59
        }
58
    }
60
    }
59
61
60
    {
62
    {
61
        my $sth = $dbh->prepare("DELETE FROM deletedbiblioitems WHERE biblioitemnumber IN (SELECT biblioitemnumber FROM biblioitems)");
63
        my $sth = $dbh->prepare("DELETE FROM deletedbiblio WHERE biblionumber IN (SELECT biblionumber FROM biblio)");
62
        $sth->execute();
64
        $sth->execute();
63
        $sth = $dbh->prepare("SELECT COUNT(*) AS count FROM deletedbiblioitems");
65
        $sth = $dbh->prepare("SELECT COUNT(*) AS count FROM deletedbiblio");
64
        $sth->execute();
66
        $sth->execute();
65
        my $row = $sth->fetchrow_hashref;
67
        my $row = $sth->fetchrow_hashref;
66
        if ($row->{count}) {
68
        if ($row->{count}) {
67
            warn "There were $row->{count} deletedbiblioitems that could not be moved, please check '_deletedbiblioitems'.";
69
            print "Warning to database administrator:\n"
68
            $dbh->do("RENAME TABLE deletedbiblioitems TO _deletedbiblioitems");
70
            . "There were $row->{count} deletedbiblio that could not be moved, please check '_deletedbiblio'.\n";
71
            $dbh->do("RENAME TABLE deletedbiblio TO _deletedbiblio");
69
        } else {
72
        } else {
70
            $dbh->do("DROP TABLE deletedbiblioitems");
73
            $dbh->do("DROP TABLE deletedbiblio");
71
        }
74
        }
72
    }
75
    }
73
76
74
75
    SetVersion( $DBversion );
77
    SetVersion( $DBversion );
76
    print "Upgrade to $DBversion done (Bug 20271 - Merge deletedbiblio* and deleteitems tables with their alive cousins)\n";
78
    print "Upgrade to $DBversion done (Bug 20271 - Merge deletedbiblio* and deleteitems tables with their alive cousins)\n";
77
}
79
}
78
- 

Return to bug 20271