Skip to content

Commit

Permalink
Fix fallour of STRICT_TRANS_TABLE
Browse files Browse the repository at this point in the history
With the move to Jammy, MariaDB now has STRICT_TRANS_TABLES on by
default. This means we can no longer do things like save empty strings
into integer columns and have them magically transformed into the
correct type (which I assume is what was happening before). This patch
adds a bunch of code around places where such slopiness was detected
during testing. The patch is half of the fix, the other half is
issue LibriVox#147.
  • Loading branch information
notartom committed Nov 29, 2022
1 parent b76cf46 commit 386c297
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
25 changes: 20 additions & 5 deletions application/libraries/Catalog_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ public function alter_data($data)
}


public function _prep_date($date_string)
{
// 0000-00-00 appears to break DateTime::createFromFormat (it returns
// -0001-110-30), special case it.
if ($date_string == '0000-00-00') {
return $date_string;
}
$d = DateTime::createFromFormat('Y-m-d', $date_string);
if ($d) {
return $d->format('Y-m-d');
}
return '0000-00-00';
}


public function _prep_project_data($data)
{
//project table
Expand All @@ -73,9 +88,9 @@ public function _prep_project_data($data)
$project_info['zip_size'] = $data['zip_size'];


$project_info['date_begin'] = (empty($data['begindate']))? '0000-00-00' : DateTime::createFromFormat('Y-m-d', $data['begindate'])->format('Y-m-d');
$project_info['date_catalog'] = $data['catalogdate'];
$project_info['date_target'] = (empty($data['targetdate']))? '0000-00-00' : DateTime::createFromFormat('Y-m-d', $data['targetdate'])->format('Y-m-d');
$project_info['date_begin'] = $this->_prep_date($data['begindate']);
$project_info['date_catalog'] = $this->_prep_date($data['catalogdate']);
$project_info['date_target'] = $this->_prep_date($data['targetdate']);

$project_info['copyright_year'] = $data['copyrightyear'];
$project_info['copyright_check']= (empty($data['copyrightcheck']))? 0: 1;;
Expand All @@ -89,7 +104,7 @@ public function _prep_project_data($data)

//volunteers
$project_info['person_bc_id'] = $data['person_bc_id'];
$project_info['person_altbc_id'] = $data['person_altbc_id'];
$project_info['person_altbc_id'] = empty($data['person_altbc_id']) ? 0 : $data['person_altbc_id'];
$project_info['person_mc_id'] = $data['person_mc_id'];
$project_info['person_pl_id'] = $data['person_pl_id'];

Expand Down Expand Up @@ -379,4 +394,4 @@ public function get_prototype()
return $data;
}

}
}
8 changes: 5 additions & 3 deletions application/libraries/Form_generator_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ function alter_data($fields)
}

$fields['list_keywords'] = $this->_process_keywords( $fields['list_keywords']);
$fields['edition_year'] = $fields['edition_year'] ? $fields['edition_year'] : NULL;
$fields['pub_year'] = $fields['pub_year'] ? $fields['pub_year'] : NULL;



Expand Down Expand Up @@ -109,8 +111,8 @@ function _process_authors($type, &$fields)
$author['auth_id'] = $author_array['auth_id'][$i];
$author['auth_first_name'] = $author_array['auth_first_name'][$i];
$author['auth_last_name'] = $author_array['auth_last_name'][$i];
$author['auth_yob'] = $author_array['auth_yob'][$i];
$author['auth_yod'] = $author_array['auth_yod'][$i];
$author['auth_yob'] = $author_array['auth_yob'][$i] ? $author_array['author_yob'][$i] : NULL;
$author['auth_yod'] = $author_array['auth_yod'][$i] ? $author_array['author_yod'][$i] : NULL;
$author['link_to_auth'] = $author_array['link_to_auth'][$i];

if (!empty($author['auth_first_name']) || !empty($author['auth_last_name']))
Expand Down Expand Up @@ -172,4 +174,4 @@ function _add_new_author($author)
return $this->ci->form_generators_authors_model->insert($author);
}

}
}

0 comments on commit 386c297

Please sign in to comment.