Skip to content

Commit e70b4c1

Browse files
committed
Remove settings and data structure when uninstalling
1 parent b6f008c commit e70b4c1

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

CRM/Civioffice/Form/Task/CreateDocumentsTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public function postProcess()
176176

177177
// Store default value for activity type in current contact's settings.
178178
try {
179+
// TODO: Use a more distinct settings name such as "'"civioffice.create_activity_type.class.<class_name>".
179180
Civi::contactSettings()->set('civioffice_create_' . static::class . '_activity_type', $values['activity_type_id'] ?? '');
180181
} catch (CRM_Core_Exception $ex) {
181182
Civi::log()->warning("CiviOffice: Couldn't save defaults: " . $ex->getMessage());

CRM/Civioffice/Upgrader.php

+43-8
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,50 @@ public function install()
3232
}
3333
}
3434

35-
/**
36-
* Example: Run an external SQL script when the module is uninstalled.
37-
*/
38-
public function uninstall()
39-
{
40-
// TODO: Remove civioffice_live_snippets option group.
41-
// TODO: Remove settings created by this extension.
42-
// TODO: Clean-up file cache (rendered files), using a cleanup interface.
35+
public function uninstall() {
36+
// Remove settings created by this extension.
37+
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Local::LOCAL_TEMP_PATH_SETTINGS_KEY);
38+
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Local::LOCAL_STATIC_PATH_SETTINGS_KEY);
39+
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Upload::UPLOAD_PRIVATE_ENABLED_SETTINGS_KEY);
40+
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Upload::UPLOAD_PUBLIC_ENABLED_SETTINGS_KEY);
41+
42+
// Revert contact settings for each live snippet.
43+
$liveSnippetNames = \Civi\Api4\OptionValue::get(FALSE)
44+
->addSelect('name')
45+
->addWhere('option_group_id.name', '=', 'civioffice_live_snippets')
46+
->execute()
47+
->column('name');
48+
49+
// Revert/delete contact settings.
50+
$contactSettingsLike = implode(
51+
' OR ',
52+
[
53+
CRM_Civioffice_Form_DocumentFromSingleContact::UNOCONV_CREATE_SINGLE_ACTIVIY_ATTACHMENT,
54+
CRM_Civioffice_Form_DocumentFromSingleContact::UNOCONV_CREATE_SINGLE_ACTIVIY_TYPE,
55+
'civioffice_create_%_activity_type',
56+
'civioffice.create_%.activity_type_id',
57+
]
58+
+ array_map(fn($liveSnippetName) => "civioffice.live_snippets.{$liveSnippetName}", $liveSnippetNames)
59+
);
60+
// Civi::contactSettings()->revert() does not support reverting for all contacts.
61+
CRM_Core_DAO::executeQuery(
62+
<<<SQL
63+
DELETE FROM `civicrm_setting` WHERE `name` LIKE '{$contactSettingsLike}';
64+
SQL
65+
);
66+
67+
// Remove "civioffice_live_snippets" option group.
68+
\Civi\Api4\OptionGroup::delete(FALSE)
69+
->addWhere('name', '=', 'civioffice_live_snippets')
70+
->execute();
71+
72+
// Revert renderer settings.
73+
foreach ((array) Civi::settings()->get('civioffice_renderers') as $renderer_uri => $renderer_name) {
74+
Civi::settings()->revert('civioffice_renderer_' . $renderer_uri);
4375
}
76+
Civi::settings()->revert('civioffice_renderers');
77+
// TODO: Clean-up file cache (temporary rendered files), using a cleanup interface.
78+
}
4479

4580
/**
4681
* Support Live Snippets.

0 commit comments

Comments
 (0)