@@ -102,26 +102,26 @@ public function upgrade_0007(): bool
102
102
return true ;
103
103
}
104
104
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
+ }
121
119
}
120
+ return TRUE ;
121
+ }
122
122
123
- public function upgrade_0009 (): bool
124
- {
123
+ public function upgrade_0009 (): bool {
124
+ self :: fixSettingsValueSerialization ();
125
125
// Drop "temp_folder_path" from unoconv renderer settings.
126
126
foreach (Civi::settings ()->get ('civioffice_renderers ' ) ?? [] as $ renderer_uri => $ renderer_name ) {
127
127
$ configuration = Civi::settings ()->get ('civioffice_renderer_ ' . $ renderer_uri );
@@ -132,6 +132,32 @@ public function upgrade_0009(): bool
132
132
}
133
133
}
134
134
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
+ }
136
161
}
162
+
137
163
}
0 commit comments