Changeset 414

Show
Ignore:
Timestamp:
09/13/07 11:44:40 (1 year ago)
Author:
ogawa
Message:

add make_unique_entry_title().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • DuplicateEntries/trunk/DuplicateEntries/DuplicateEntries.pl

    r410 r414  
    8787            }, 
    8888        }); 
     89        $entry_cloned->title(make_unique_entry_title($entry)); 
    8990        $entry_cloned->status(MT::Entry::HOLD()); 
    9091        $entry_cloned->tags($entry->tags); 
     
    125126        my $tmpl_cloned = $tmpl->clone({ 
    126127            except => { 
    127                 id       => 1, 
     128                id => 1, 
    128129            }, 
    129130        }); 
    130131        $tmpl_cloned->name(make_unique_tmpl_name($tmpl)); 
     132 
    131133        $tmpl_cloned->save 
    132134            or return $app->error($plugin->translate('Saving template failed: [_1]', $tmpl_cloned->errstr)); 
     
    136138} 
    137139 
     140sub make_unique_entry_title { 
     141    my $entry = shift; 
     142    my $class = ref $entry || MT->model($entry->class_type); 
     143 
     144    my $blog_id = $entry->blog_id; 
     145    my $title = $entry->title; 
     146    my $unique_title; 
     147    my $i = 1; 
     148    do { 
     149        $unique_title = $title . ' (' . $i++ . ')'; 
     150    } while ($class->count({ 
     151        title   => $unique_title, 
     152        blog_id => $blog_id 
     153    })); 
     154 
     155    $unique_title; 
     156} 
     157 
    138158sub make_unique_tmpl_name { 
    139159    my $tmpl = shift; 
     160    my $class = ref $tmpl || MT->model('template'); 
     161 
    140162    my $blog_id = $tmpl->blog_id; 
    141163    my $tmpl_name = $tmpl->name; 
     
    144166    do { 
    145167        $unique_tmpl_name = $tmpl_name . ' (' . $i++ . ')'; 
    146     } while (MT->model('template')->count({ 
     168    } while ($class->count({ 
    147169        name    => $unique_tmpl_name, 
    148170        blog_id => $blog_id