diff --git a/lib/Lacuna/DB/Result/Empire.pm b/lib/Lacuna/DB/Result/Empire.pm index 1ba7b752..4554dc70 100644 --- a/lib/Lacuna/DB/Result/Empire.pm +++ b/lib/Lacuna/DB/Result/Empire.pm @@ -131,6 +131,36 @@ sub essentia { return $self->essentia_free + $self->essentia_game + $self->essentia_paid; } +around name => sub { + my ($orig, $self) = (shift, shift); + + if (@_) { + my $new_name = $_[0]; + + Lacuna->db->resultset('Lacuna::DB::Result::Log::EmpireNameChange')->new({ + empire_id => $self->id, + empire_name => $new_name, + old_empire_name => $self->$orig, + })->insert; + } + + $self->$orig(@_); +}; + +around update => sub { + my ($orig, $self) = (shift, shift); + + if ( @_ && exists $_[0]->{name} ) { + Lacuna->db->resultset('Lacuna::DB::Result::Log::EmpireNameChange')->new({ + empire_id => $self->id, + empire_name => $_[0]->{name}, + old_empire_name => $self->name, + })->insert; + } + + $self->$orig(@_); +}; + sub update_species { my ($self, $me) = @_; $self->species_name($me->{name}); diff --git a/lib/Lacuna/DB/Result/Log/EmpireNameChange.pm b/lib/Lacuna/DB/Result/Log/EmpireNameChange.pm new file mode 100644 index 00000000..4db39684 --- /dev/null +++ b/lib/Lacuna/DB/Result/Log/EmpireNameChange.pm @@ -0,0 +1,16 @@ +package Lacuna::DB::Result::Log::EmpireNameChange; + +use Moose; +use utf8; +no warnings qw(uninitialized); +extends 'Lacuna::DB::Result::Log::WithEmpire'; +use Lacuna::Util; + +__PACKAGE__->table('empire_name_change_log'); +__PACKAGE__->add_columns( + old_empire_name => { data_type => 'varchar', size => 30, is_nullable => 0 }, +); + +no Moose; +__PACKAGE__->meta->make_immutable(inline_constructor => 0); + diff --git a/lib/Lacuna/Web/Admin.pm b/lib/Lacuna/Web/Admin.pm index 095158a2..fe50596d 100644 --- a/lib/Lacuna/Web/Admin.pm +++ b/lib/Lacuna/Web/Admin.pm @@ -148,6 +148,22 @@ sub www_view_login_log { return $self->wrap($out); } +sub www_view_empire_name_change_log { + my ($self, $request) = @_; + my $empire_id = $request->param('empire_id'); + my $date_query = $request->param('old') ? {'=' => undef} : { '!=' => undef }; + my $history = Lacuna->db->resultset('Lacuna::DB::Result::Log::EmpireNameChange')->search({empire_id => $empire_id},{order_by => { -desc => 'date_stamp' }}); + my $out = '

Empire Name-Change Log

'; + $out .= sprintf('Back To Empire', $empire_id); + $out .= ''; + while (my $log = $history->next) { + $out .= sprintf('', + $log->date_stamp, $log->empire_name, $log->old_empire_name); + } + $out .= '
DateNew NameOld Name
%s%s%s
'; + return $self->wrap($out); +} + sub www_search_empires { my ($self, $request) = @_; my $page_number = $request->param('page_number') || 1; @@ -744,7 +760,8 @@ sub www_view_empire { $out .= ''; $out .= sprintf('', $empire->id); $out .= sprintf('', $empire->rpc_count); - $out .= sprintf('', $empire->name); + $out .= sprintf('',$empire->id); $out .= sprintf('', $empire->email); $out .= sprintf('', $empire->date_created); $out .= sprintf('', $empire->stage); diff --git a/var/upgrades/3.0879.sql b/var/upgrades/3.0879.sql index 99ee1f40..80c84bc9 100644 --- a/var/upgrades/3.0879.sql +++ b/var/upgrades/3.0879.sql @@ -5,3 +5,14 @@ alter table empire add column essentia_paid float(11,1) not null default 0 after update empire set essentia_game=essentia; alter table login_log add column is_sitter int(1) not null default 0; + +create table empire_name_change_log ( + id int(11) not null auto_increment, + date_stamp datetime not null, + empire_id int(11) not null, + empire_name varchar(30) not null, + old_empire_name varchar(30) not null, + primary key (id), + key erl_idx_empire_id (empire_id), + key erl_idx_date_stamp (date_stamp) +);
Id%s
RPC Requests%s
Name%s
Name%s', $empire->name); + $out .= sprintf('View History
Email%s
Created%s
Stage%s