MTãªãã¸ã§ã¯ãã®è¤è£½ãä½ããã¼ã«ã¹ã¯ãªãããä½ã£ã
Movable Type使ã£ã¦ãæã«ããã¾ã«ããã¼ã¸ã³ã°ã®ãã¹ããè² è·ãã¹ãçããããæã«ãè¨äºã大éã«ã³ãã¼ãããæããã£ã¦ãããã¾ã§ä¸è¨ã®ãããªã¹ã¯ãªãããå©ããããã¦ã³ãã¼ãä½ã£ã¦ã¾ããã
ãããMTãªãã¸ã§ã¯ãå ¨è¬ã«åºãã¦ãè¯ãããªã¨æã£ãã®ã§ãObjectCloneã¨ãããã©ã°ã¤ã³ãä½ãã¾ããã
ObjectClone ãã©ã°ã¤ã³
usage ã®ã¾ã¾ã§ãããä¸è¨ã®ããã«ä½¿ãã¾ãã
USAGE: perl tools/object-clone --model=NAME --orig_id=NUM [OPTION] Requires: -m, --model=NAME Model name (object datasource) of object to make clone. -o, --orig_id=NUM Original object id clone object. Options: -a, --amount=NUM Amount of clones to make. Default 1. -d, --debug Output debug info to STDERR. -h, --help Show help. -r, --redefine=PAIR Redefine column value with column key and column value pair. -u, --usage Show usage. Examples: # Make clones of 100 objects of MT::Entry from original entry that entry_id is 1. $ tools/object-clone --model=entry --orig_id=1 --amount=100 # Make a clone of MT::Blog, and redefine name, site_path and site_url. $ tools/object-clone -m blog -o 2 -r 'name=Clone Blog' -r 'site_path=/path/to/site-path' -r 'site_url=/::/clone-blog/'
åºæ¬ã¯ãã¢ãã«åã¨ã³ãã¼å
ã®ãªãã¸ã§ã¯ãã®IDããããããã--model
ãªãã·ã§ã³ã¨--orig_id
ãªãã·ã§ã³ã§æå®ãã¦ã¯ãã¼ã³ãä½ãã¾ãã
ã¯ãã¼ã³ãè¤æ°ä½ãå ´åã¯ãä½ãæ°ã--amount
ãªãã·ã§ã³ã§æå®ãã¾ãã
ä»ã«ã¯ãåã«ä¸¸ã
ã³ãã¼ããã ãã§ã¯ãªãã¦ãä¸é¨ãå¤ãå¤æ´ããå ´åã¯ã--redefine
ãªãã·ã§ã³ã§ããã£ã¼ã«ãåã¨ãã®å¤ã=
ã§åºåã£ã¦æå®ãã¾ãã
å ·ä½çã«ã¯ãAã¨ããããã°ã®è¨äºããBã¨ããããã°ã«ã³ãã¼ããããããªæãªã©ã«ãä¸è¨ã®ããã«æå®ãã¾ãã
$ perl tools/object-clone --model entry --orig_id 1 --amount 10 --redefine blog_id=3
ã³ãã³ãã©ã¤ã³ãªãã·ã§ã³ã®åèªãé©åãã©ããã¯å¾®å¦ãªæãããã¾ãããã¨ããããå¿ è¦æä½éãªãªãã·ã§ã³ã ãç¨æãã¾ããã
å¤ã®å¤æ´ãå¿ è¦ãªã±ã¼ã¹
DBä¸ã®å¶ç´ã¯ãªãã«ãé¢ããããå®éã«ã¯MT::Entryã®ãã¼ã¹ãã¼ã ã ã¨ããCustomFields::Fieldã®ã¿ã°åã¯ãå¤ãéè¤ããªãããã«CMSä¸ã§å¶éãããã£ã¦ããããããã¯ã°ã©ã¦ã³ãã§ã®å¤ã®çæã®å®è£ ããã£ãããã¾ãã
ãã®è¾ºã®å¯¾å¿ã¯ãªãã¸ã§ã¯ãæ¯ã«å¿ è¦ãªæããªã®ã§ãObjectClone::Patcherã¨ãã®ãµãã¯ã©ã¹ã«åãåºãã¦ãã¾ãã
åä½ã§ä½¿ããã¨ã¯ã»ã¼ãªãã¨æãã¾ãããä¸è¨ã®ãããªæãã§ä½¿ãã¾ãã
use strict; use warnings; use lib qw(lib extlib plugins/ObjectClone/lib); use MT; use ObjectClone::Patcher; use ObjectClone::Patcher::MT::Entry; my $mt = MT->instance; my $orig_obj = MT::Entry->load(1) or die MT::Entry->errstr; my $new_obj = $orig_obj->clone; my $patcher = ObjectClone::Patcher->model('entry')->new($new_obj, $orig_obj); $patcher->remove_patch(basename => \&ObjectClone::Patcher::MT::Entry::basename) ->add_patch(basename => sub { 'new-basename' }) ->add_patch(convert_breaks => sub { 'markdown' }) ->apply_patch; $new_obj->save or die $new_obj->errstr;
ããã©ã«ãã§ä¸è¨ã®Patcherã¯ã©ã¹ãç¨æãã¦ãã¾ãã
- ObjectClone::Patcher::MT::Entry
- ObjectClone::Patcher::MT::Category
- ObjectClone::Patcher::MT::Author
- ObjectClone::Patcher::CustomFields::Field
ã¨ã¯è¨ã£ã¦ãå®éã«å®è£ ãããã®ã¯ããã¼ã¹ãã¼ã ãã¦ãã¼ã¯ã«ããå¦çãããã§ãã
ç¬èªãªãã¸ã§ã¯ããtools/clone-objectã§çæãããã¨ããªã©ã¯ãä¸è¨ã®Patcherã¯ã©ã¹ã追å ããã°å¯¾å¿ãã§ãã¾ãã( ObjectClone::Patcher::{ãªãã¸ã§ã¯ãå} )
å¾ã¯ãapply_patchã¡ã½ããã§ãããããé©ç¨ããåã«ãbefore_apply_patchã¨ããã³ã¼ã«ããã¯ãå¼ã°ããã®ã§ãããã©ã«ãã®ãããå¦çãç¡å¹ã«ããããããã«å ãã¦ä½ãã®å¦çãå®è¡ãããããæã¯ãã³ã¼ã«ããã¯ãã©ã°ã¤ã³ã§æ¡å¼µã§ãã¾ãã
ã³ã¼ã«ããã¯ãã©ã°ã¤ã³ã®ãµã³ãã«
ä¸è¨ã®ããã«ã³ã¼ã«ããã¯ã使ã£ããã©ã°ã¤ã³ãæ¸ãã¾ãã
id: ObjectCloneCallback key: object-clone-callback name: ObjectCloneCallback callbacks: ObjectClone::Patcher::MT::Entry::before_apply_patch: | sub { my ($cb, $patcher) = @_; $patcher->add_patch('basename', sub { my ($new_obj, $orig_obj) = @_; 'new-basename'; }); }
ã¾ã¨ã
主ã«éçºãã¼ã«ã¨ãã¦ä½ã£ãã®ã§ãéçºæã«ã¯å½¹ã«ç«ã¤æ°ããã¦ãã¾ãã
ã·ã§ã«ã¹ã¯ãªããã¨çµã¿åããããããã®ãè¯ãããããã¾ããã
ã»ãªã®ã