Skip to content

Commit 9ffa4bc

Browse files
committed
Fix malformatted value for "civioffice_renderers" setting
1 parent 47f896e commit 9ffa4bc

File tree

1 file changed

+45
-19
lines changed

1 file changed

+45
-19
lines changed

CRM/Civioffice/Upgrader.php

+45-19
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,26 @@ public function upgrade_0007(): bool
102102
return true;
103103
}
104104

105-
public function upgrade_0008(): bool
106-
{
107-
// Check for instances of the "unoconv-local-phpword" renderer type.
108-
foreach (Civi::settings()->get('civioffice_renderers') ?? [] as $renderer_uri => $renderer_name) {
109-
$configuration = Civi::settings()->get('civioffice_renderer_' . $renderer_uri);
110-
if ($configuration['type'] == 'unoconv-local-phpword') {
111-
$this->ctx->log->info(
112-
'Migrate "unoconv-local-phpword" renderer instance ' . $renderer_name . ' to unified "unoconv-local" with PHPWord usage.'
113-
);
114-
// Convert to "unoconv-local" type with configuration option "phpword_tokens" set to TRUE.
115-
$configuration['type'] = 'unoconv-local';
116-
$configuration['phpword_tokens'] = true;
117-
Civi::settings()->set('civioffice_renderer_' . $renderer_uri, $configuration);
118-
}
119-
}
120-
return true;
105+
public function upgrade_0008(): bool {
106+
self::fixSettingsValueSerialization();
107+
// Check for instances of the "unoconv-local-phpword" renderer type.
108+
foreach (Civi::settings()->get('civioffice_renderers') ?? [] as $renderer_uri => $renderer_name) {
109+
$configuration = Civi::settings()->get('civioffice_renderer_' . $renderer_uri);
110+
if ($configuration['type'] == 'unoconv-local-phpword') {
111+
$this->ctx->log->info(
112+
'Migrate "unoconv-local-phpword" renderer instance ' . $renderer_name . ' to unified "unoconv-local" with PHPWord usage.'
113+
);
114+
// Convert to "unoconv-local" type with configuration option "phpword_tokens" set to TRUE.
115+
$configuration['type'] = 'unoconv-local';
116+
$configuration['phpword_tokens'] = TRUE;
117+
Civi::settings()->set('civioffice_renderer_' . $renderer_uri, $configuration);
118+
}
121119
}
120+
return TRUE;
121+
}
122122

123-
public function upgrade_0009(): bool
124-
{
123+
public function upgrade_0009(): bool {
124+
self::fixSettingsValueSerialization();
125125
// Drop "temp_folder_path" from unoconv renderer settings.
126126
foreach (Civi::settings()->get('civioffice_renderers') ?? [] as $renderer_uri => $renderer_name) {
127127
$configuration = Civi::settings()->get('civioffice_renderer_' . $renderer_uri);
@@ -132,6 +132,32 @@ public function upgrade_0009(): bool
132132
}
133133
}
134134

135-
return true;
135+
return TRUE;
136+
}
137+
138+
public function upgrade_0010(): bool {
139+
self::fixSettingsValueSerialization();
140+
return TRUE;
141+
}
142+
143+
/**
144+
* Convert JSON-formatted setting "civioffice_renderers" to PHP-serialized format.
145+
* The setting was wrongly defined as JSON-formatted in settings metadata while unerialization with a format other
146+
* than PHP-serialized only works with the API. Civi::settings() always expects and generates PHP-serialized values.
147+
*/
148+
private static function fixSettingsValueSerialization(): void {
149+
$dao = \CRM_Core_DAO::executeQuery(
150+
\CRM_Utils_SQL_Select::from('civicrm_setting')
151+
->select('value')
152+
->where('name="civioffice_renderers"')
153+
->toSQL()
154+
);
155+
while ($dao->fetch()) {
156+
$legacyValue = \CRM_Core_DAO::unSerializeField($dao->value, \CRM_Core_DAO::SERIALIZE_JSON);
157+
if (is_array($legacyValue)) {
158+
Civi::settings()->set('civioffice_renderers', $legacyValue);
159+
}
160+
}
136161
}
162+
137163
}

0 commit comments

Comments
 (0)