Changeset 394
- Timestamp:
- 08/26/07 17:26:26 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
FiscalYearlyArchives/trunk/FiscalYearlyArchives/fiscal_yearly_archives.pl
r393 r394 29 29 ['fiscal_start_month', { Default => 4, Scope => 'system' }], 30 30 ]), 31 32 31 }); 33 32 MT->add_plugin($plugin); … … 77 76 } 78 77 79 # This is a dirty hack to omit multiple get_config_value() calls for 80 # optimization. Basically, I don't like the way which a plugin loads 81 # and stores its configuration by using MT::PluginSettings. Because I 82 # believe it should be able to get_and_set to the 'registry' in a more 83 # flexible and transparent manner. 84 our $START_MONTH; 85 sub init_request { 86 my $plugin = shift; 87 $plugin->SUPER::init_request(@_); 88 $START_MONTH = $plugin->get_config_value('fiscal_start_month') || 4; 78 # a dirty hack to avoid multiple get_config_value() calls for 79 # optimization 80 { 81 my $start_month; 82 83 # fetch 'fiscal_start_month' at the first time the method is 84 # called, and cache it to $start_month 85 sub fiscal_start_month { 86 return $start_month if $start_month; 87 $start_month = $plugin->get_config_value('fiscal_start_month') || 4; 88 } 89 90 # invalidate $start_month cache everytime init_request() called 91 sub init_request { 92 my $plugin = shift; 93 $plugin->SUPER::init_request(@_); 94 $start_month = undef; 95 } 89 96 } 90 97 … … 92 99 my ($ts) = @_; 93 100 my ($y, $m) = unpack('A4A2', $ts); 94 $y-- if $m < $START_MONTH; 101 my $start_month = fiscal_start_month(); 102 $y-- if $m < $start_month; 95 103 $y; 96 104 } … … 108 116 sub start_end_fiscal_year { 109 117 my ($ts) = @_; 110 my $start_year = ts2fiscal($ts);111 my $start = sprintf("%04d%02d%02d000000", $start_year, $ START_MONTH, 1);118 my ($start_year, $start_month) = (ts2fiscal($ts), fiscal_start_month()); 119 my $start = sprintf("%04d%02d%02d000000", $start_year, $start_month, 1); 112 120 return $start unless wantarray; 113 121 114 122 my ($end_year, $end_month, $end_day); 115 if ($ START_MONTH== 1) {123 if ($start_month == 1) { 116 124 ($end_year, $end_month, $end_day) = ($start_year, 12, 31); 117 125 } else { 118 ($end_year, $end_month) = ($start_year + 1, $ START_MONTH- 1);126 ($end_year, $end_month) = ($start_year + 1, $start_month - 1); 119 127 $end_day = MT::Util::days_in($end_month, $end_year); 120 128 } … … 203 211 sub archive_group_entries { 204 212 my ($ctx, %param) = @_; 205 my $ts = sprintf("%04d%02d%02d000000", $param{fiscal_year}, $START_MONTH, 1)213 my $ts = sprintf("%04d%02d%02d000000", $param{fiscal_year}, fiscal_start_month(), 1) 206 214 if %param; 207 215 my ($start, $end); … … 236 244 my $auth = $params->{Author}; 237 245 238 my ($start, $end); 239 if ($ts) { 240 ($start, $end) = start_end_fiscal_year($ts); 241 } 246 my ($start, $end) = start_end_fiscal_year($ts) 247 if $ts; 242 248 my $count = MT->model('entry')->count({ 243 249 blog_id => $blog->id,
