Changeset 1776

Show
Ignore:
Timestamp:
04/04/08 22:48:02 (23 months ago)
Author:
mpaschal
Message:

Update 'virtual' field of fileinfos directly when dynamicity changes
Don't recreate fileinfos when dynamicity changes, only when publishing path does (but when publishing path changes, recreate fileinfos even if publishing statically, as we always keep fileinfos nowadays)
Don't cache fileinfos, so updating directly is not a problem
BugzID: 67300

Location:
branches/release-33/lib/MT
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/release-33/lib/MT/CMS/Blog.pm

    r1753 r1776  
    13711371} 
    13721372 
     1373sub _update_finfos { 
     1374    my ($app, $new_virtual, $where) = @_; 
     1375    my $finfo_class = MT->model('fileinfo'); 
     1376    my $driver = $finfo_class->driver; 
     1377    my $dbd = $driver->dbd; 
     1378 
     1379    my $stmt = MT::ObjectDriver::SQL->new; 
     1380 
     1381    if ($where) { 
     1382        my $new_where = {}; 
     1383        while (my ($key, $val) = each %$where) { 
     1384            my $new_key = $dbd->db_column_name($finfo_class->datasource, $key); 
     1385            $new_where->{$new_key} = $val; 
     1386        } 
     1387        $stmt->add_complex_where([ $new_where ]); 
     1388    } 
     1389    my $virtual_col = $dbd->db_column_name($finfo_class->datasource, 'virtual'); 
     1390    $stmt->add_complex_where([ { $virtual_col => { op => '!=', value => $new_virtual } } ]); 
     1391 
     1392    my $sql = join q{ }, 'UPDATE', $driver->table_for($finfo_class), 'SET', 
     1393        $virtual_col, '= ?', $stmt->as_sql_where(); 
     1394 
     1395    my $dbh = $driver->rw_handle; 
     1396    $dbh->do($sql, {}, $new_virtual, @{ $stmt->{bind} }) 
     1397        or return $app->error($dbh->errstr || $DBI::errstr); 
     1398    1; 
     1399} 
     1400 
    13731401sub post_save { 
    13741402    my $eh = shift; 
     
    14161444            } 
    14171445 
     1446            if (!$dcty_changed || $dcty eq 'custom') { 
     1447                # do nothing 
     1448            } 
     1449            elsif ($dcty eq 'none') { 
     1450                _update_finfos($app, 0); 
     1451            } 
     1452            elsif ($dcty eq 'all') { 
     1453                _update_finfos($app, 1); 
     1454            } 
     1455            elsif ($dcty eq 'archives') { 
     1456                # Only archives have template maps. 
     1457                _update_finfos($app, 1, { templatemap_id => \'is not null' }); 
     1458                _update_finfos($app, 0, { templatemap_id => \'is null' }); 
     1459            } 
     1460 
    14181461            # If either of the publishing paths changed, rebuild the fileinfos. 
    14191462            my $path_changed = 0; 
     
    14221465                    && $app->param($path_field) ne $original->$path_field(); 
    14231466            } 
    1424             if ($dcty ne 'none' && ($dcty_changed || $path_changed)) { 
     1467 
     1468            if ($path_changed) { 
    14251469                $app->rebuild( BlogID => $obj->id, NoStatic => 1 ) 
    14261470                    or return $app->publish_error(); 
  • branches/release-33/lib/MT/FileInfo.pm

    r1495 r1776  
    3838    datasource => 'fileinfo', 
    3939    primary_key => 'id', 
     40    cacheable => 0, 
    4041}); 
    4142