@@ -169,7 +169,36 @@ sub save {
169
169
if ( defined $asset -> file_ext ) {
170
170
$asset -> file_ext( lc ( $asset -> file_ext ) );
171
171
}
172
+ if (MT-> config-> EnableAssetAutoDirify) {
173
+ use MT::Util qw( dirify decode_url) ;
174
+ my $delimiter = MT-> config-> AssetAutoDirifyDelimiter;
175
+ my $fmgr = $asset -> blog-> file_mgr;
176
+ my $old_path = $asset -> file_path;
177
+
178
+ # #file_ext is stored as jpg, not .jpg, hence the -1
179
+ my $basename = substr ($asset -> file_name, 0, index ($asset -> file_name, $asset -> file_ext)-1);
180
+ my $basename_dirified = dirify($basename , $delimiter );
181
+ my $path = $asset -> file_path;
182
+ my $blog_site_url = $asset -> blog-> site_url();
183
+
184
+ $path =~ s / $basename/ $basename_dirified / ;
185
+ # #Assets with spaces and such in them are URL encoded initially.
186
+ # #If they are not decoded, then the Perl regexs below will fail.
187
+ my $url = decode_url $asset -> url;
188
+ $url =~ s / $basename/ $basename_dirified / ;
189
+ $url =~ s / $blog_site_url/ \% r\/ / ;
190
+
191
+ # #URL should now look like %r/myfolder/myfile.jpeg, not http://www.mydomain.com/myfolder/myfile.jpeg
192
+ # #This value will let the asset be stored as having a relative path to the blog, making it easier
193
+ # #to manually move assets in cases like a shared host moving a user between servers.
194
+ $asset -> file_path($path );
195
+ $asset -> url($url );
196
+ $asset -> file_name($basename );
197
+ # #No need to call $asset->save because it is called below.
198
+
199
+ $fmgr -> rename ($old_path , $path ); # #Move the file to the new dirified file name
172
200
201
+ }
173
202
unless ( $asset -> SUPER::save(@_ ) ) {
174
203
175
204
# TODO - note to committers: should this be here? Seems odd.
0 commit comments