https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31143
--- Comment #58 from [email protected] --- (In reply to Jonathan Druart from comment #57) > Hello Wainui, > The title of this bug report states that the patches are supposed to > "identify all cases in the database". But with those 2 patches we are only > dealing with two tables: items and patrons. > > I am suggesting the following snippet of code that will allow you to catch > invalid dates in the whole database: > > use Koha::Database; > my $schema = Koha::Database->new->schema; > # Loop over all the DBIx::Class classes > for my $class ( sort values %{$schema->{class_mappings}} ) { > # Retrieve the resultset so we can access the columns info > my $rs = $schema->resultset($class); > my $columns = $rs->result_source->columns_info; > > # Loop over the columns > while ( my ( $column, $info ) = each %$columns ) { > # Next if data type is not date/datetime/timestamp > my $data_type = $info->{data_type}; > next unless grep { $data_type =~ m{^$_$} } qw( timestamp datetime > date ); > > # Count the invalid dates > my $invalid_dates = $rs->search({ $column => '0000-00-00' })->count; > > next unless $invalid_dates; > > # "items.withdrawn_on contains 42 invalid dates" > say sprintf "Column %s.%s contains %s invalid dates", > $rs->result_source->name, $column, $invalid_dates; > } > } > > Let me know if you have any questions about it. I can help you to adjust it > to your needs. Thanks Jonathan! I will have a go at implementing this -- You are receiving this mail because: You are watching all bug changes. _______________________________________________ Koha-bugs mailing list [email protected] https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/
