Skip to content
Snippets Groups Projects
Commit 1fbda76b authored by eileen's avatar eileen
Browse files

Hacks to avoid failure on upgrade due to new field not yet being in the DB

On attempting to upgrade I found I couldn't get to the upgrade screen add the new serialize field as
I got fatal errors in these 2 places (maybe more to come).

The new field is civicrm_custom_field.serialize
parent 27a47776
Branches
Tags
No related merge requests found
......@@ -278,6 +278,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
*
* @return array
* an array of active custom fields.
* @throws \CRM_Core_Exception
*/
public static function &getFields(
$customDataType = 'Individual',
......@@ -392,6 +393,10 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
if ($onlyParent) {
$extends .= " AND $cgTable.extends_entity_column_value IS NULL AND $cgTable.extends_entity_column_id IS NULL ";
}
// Temporary hack - in 5.27 a new field is added to civicrm_custom_field. There is a high
// risk this function is called before the upgrade page can be reached and if
// so it will potentially result in fatal error.
$serializeField = CRM_Core_BAO_Domain::isDBUpdateRequired() ? '' : "$cfTable.serialize,";
$query = "SELECT $cfTable.id, $cfTable.label,
$cgTable.title,
......@@ -410,7 +415,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
$cfTable.date_format,
$cfTable.time_format,
$cgTable.is_multiple,
$cfTable.serialize,
$serializeField
$cgTable.table_name,
og.name as option_group_name
FROM $cfTable
......
......@@ -82,6 +82,19 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain {
);
}
/**
* Is a database update required to apply latest schema changes.
*
* @return bool
*
* @throws \CRM_Core_Exception
*/
public static function isDBUpdateRequired() {
$dbVersion = CRM_Core_BAO_Domain::version();
$codeVersion = CRM_Utils_System::version();
return version_compare($dbVersion, $codeVersion) < 0;
}
/**
* Get the location values of a domain.
*
......
......@@ -739,10 +739,8 @@ class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
);
}
else {
$codeVersion = CRM_Utils_System::version();
// if db.ver < code.ver, time to upgrade
if (version_compare($dbVersion, $codeVersion) < 0) {
if (CRM_Core_BAO_Domain::isDBUpdateRequired()) {
$messages[] = new CRM_Utils_Check_Message(
__FUNCTION__,
ts('New codebase version detected. You must visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', [1 => $upgradeUrl]),
......
......@@ -94,6 +94,10 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component {
* @return array
*/
public function checkSmartGroupCustomFieldCriteria() {
if (CRM_Core_BAO_Domain::isDBUpdateRequired()) {
// Do not run this check when the db has not been updated as it might fail on non-updated schema issues.
return [];
}
$messages = $problematicSG = [];
$customFieldIds = array_keys(CRM_Core_BAO_CustomField::getFields('ANY', FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE));
try {
......
......@@ -122,7 +122,7 @@ function civicrm_api3_custom_field_delete($params) {
* @return array
*/
function civicrm_api3_custom_field_get($params) {
if (($params['legacy_html_type'] ?? TRUE) && !empty($params['return'])) {
if (!CRM_Core_BAO_Domain::isDBUpdateRequired() && ($params['legacy_html_type'] ?? TRUE) && !empty($params['return'])) {
if (is_array($params['return'])) {
$params['return'][] = 'serialize';
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment