Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove settings when uninstalling #28

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CRM/Civioffice/Form/Task/CreateDocumentsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public function postProcess()

// Store default value for activity type in current contact's settings.
try {
// TODO: Use a more distinct settings name such as "'"civioffice.create_activity_type.class.<class_name>".
Civi::contactSettings()->set('civioffice_create_' . static::class . '_activity_type', $values['activity_type_id'] ?? '');
} catch (CRM_Core_Exception $ex) {
Civi::log()->warning("CiviOffice: Couldn't save defaults: " . $ex->getMessage());
Expand Down
51 changes: 43 additions & 8 deletions CRM/Civioffice/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,50 @@ public function install()
}
}

/**
* Example: Run an external SQL script when the module is uninstalled.
*/
public function uninstall()
{
// TODO: Remove civioffice_live_snippets option group.
// TODO: Remove settings created by this extension.
// TODO: Clean-up file cache (rendered files), using a cleanup interface.
public function uninstall() {
// Remove settings created by this extension.
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Local::LOCAL_TEMP_PATH_SETTINGS_KEY);
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Local::LOCAL_STATIC_PATH_SETTINGS_KEY);
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Upload::UPLOAD_PRIVATE_ENABLED_SETTINGS_KEY);
Civi::settings()->revert(CRM_Civioffice_DocumentStore_Upload::UPLOAD_PUBLIC_ENABLED_SETTINGS_KEY);

// Revert contact settings for each live snippet.
$liveSnippetNames = \Civi\Api4\OptionValue::get(FALSE)
->addSelect('name')
->addWhere('option_group_id.name', '=', 'civioffice_live_snippets')
->execute()
->column('name');

// Revert/delete contact settings.
$contactSettingsLike = implode(
' OR ',
[
CRM_Civioffice_Form_DocumentFromSingleContact::UNOCONV_CREATE_SINGLE_ACTIVIY_ATTACHMENT,
CRM_Civioffice_Form_DocumentFromSingleContact::UNOCONV_CREATE_SINGLE_ACTIVIY_TYPE,
'civioffice_create_%_activity_type',
'civioffice.create_%.activity_type_id',
]
+ array_map(fn($liveSnippetName) => "civioffice.live_snippets.{$liveSnippetName}", $liveSnippetNames)
);
// Civi::contactSettings()->revert() does not support reverting for all contacts.
CRM_Core_DAO::executeQuery(
<<<SQL
DELETE FROM `civicrm_setting` WHERE `name` LIKE '{$contactSettingsLike}';
SQL
);

// Remove "civioffice_live_snippets" option group.
\Civi\Api4\OptionGroup::delete(FALSE)
->addWhere('name', '=', 'civioffice_live_snippets')
->execute();

// Revert renderer settings.
foreach ((array) Civi::settings()->get('civioffice_renderers') as $renderer_uri => $renderer_name) {
Civi::settings()->revert('civioffice_renderer_' . $renderer_uri);
}
Civi::settings()->revert('civioffice_renderers');
// TODO: Clean-up file cache (temporary rendered files), using a cleanup interface.
}

/**
* Support Live Snippets.
Expand Down
Loading