Skip to content

Commit

Permalink
remove never-used option value
Browse files Browse the repository at this point in the history
  • Loading branch information
demeritcowboy committed Dec 20, 2020
1 parent 8178e72 commit bdc29c0
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 18 deletions.
6 changes: 1 addition & 5 deletions CRM/Mailing/MailStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ public static function getStore($name = NULL) {
private static function getProtocolDefaults($protocol) {
switch ($protocol) {
case 'IMAP':
case 'IMAP_XOAUTH2':
return [
// For backward compat with pre-release XOAuth2 configurations
'auth' => $protocol === 'IMAP_XOAUTH2' ? 'XOAuth2' : 'Password',
// In a simpler world:
// 'auth' => 'Password',
'auth' => 'Password',
'factory' => function($mailSettings) {
$useXOAuth2 = ($mailSettings['auth'] === 'XOAuth2');
return new CRM_Mailing_MailStore_Imap($mailSettings['server'], $mailSettings['username'], $mailSettings['password'], (bool) $mailSettings['is_ssl'], $mailSettings['source'], $useXOAuth2);
Expand Down
68 changes: 57 additions & 11 deletions CRM/Upgrade/Incremental/php/FiveThirtyFour.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ class CRM_Upgrade_Incremental_php_FiveThirtyFour extends CRM_Upgrade_Incremental
* @param null $currentVer
*/
public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
// Example: Generate a pre-upgrade message.
// if ($rev == '5.12.34') {
// $preUpgradeMessage .= '<p>' . ts('A new permission, "%1", has been added. This permission is now used to control access to the Manage Tags screen.', array(1 => ts('manage tags'))) . '</p>';
// }
if ($rev === '5.34.alpha1') {
$xoauth2Value = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_MailSettings', 'protocol', 'IMAP_XOAUTH2');
if (!empty($xoauth2Value)) {
if ($this->isXOAUTH2InUse($xoauth2Value)) {
// Leaving out ts() since it's unlikely this message will ever
// be displayed to anyone.
$preUpgradeMessage .= '<p>This site appears to be using the IMAP_XOAUTH2 mail protocol which was part of pre-5.32 work towards OAUTH2 but was never functional and never released as an active option value. Please post at https://lab.civicrm.org/dev/core/-/issues/2264 describing how you are using this value.</p>';
}
}
}
}

/**
Expand All @@ -40,10 +46,16 @@ public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NU
* an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
*/
public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
// Example: Generate a post-upgrade message.
// if ($rev == '5.12.34') {
// $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
// }
if ($rev === '5.34.alpha1') {
$xoauth2Value = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_MailSettings', 'protocol', 'IMAP_XOAUTH2');
if (!empty($xoauth2Value)) {
if ($this->isXOAUTH2InUse($xoauth2Value)) {
// Leaving out ts() since it's unlikely this message will ever
// be displayed to anyone.
$postUpgradeMessage .= '<div class="crm-error"><ul><li>This site appears to be using the IMAP_XOAUTH2 mail protocol which was part of pre-5.32 work towards OAUTH2 but was never functional and never released as an active option value. Please post at https://lab.civicrm.org/dev/core/-/issues/2264 describing how you are using this value.</li></ul></div>';
}
}
}
}

/*
Expand All @@ -70,10 +82,44 @@ public function upgrade_5_34_alpha1(string $rev): void {

$this->addTask('core-issue#365 - Add effective_end_date to civicrm_action_schedule', 'addColumn',
'civicrm_action_schedule', 'effective_end_date', "timestamp NULL COMMENT 'Latest date to consider end events from.'");

$this->addTask('Remove never used IMAP_XOAUTH2 option value', 'removeUnusedXOAUTH2');
}

/**
* This option value was never used, but check anyway if someone happens
* to be using it and then ask them to report what they're doing with it.
* There's no way to send a message to the user during the task, so we have
* to check it here and also as a pre/post upgrade message.
* Similar to removeGooglePlusOption from 5.23 except there we know some
* people would have used it.
*/
public static function removeUnusedXOAUTH2(CRM_Queue_TaskContext $ctx) {
$xoauth2Value = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_MailSettings', 'protocol', 'IMAP_XOAUTH2');
if (!empty($xoauth2Value)) {
if (!self::isXOAUTH2InUse($xoauth2Value)) {
CRM_Core_DAO::executeQuery("DELETE ov FROM civicrm_option_value ov
INNER JOIN civicrm_option_group og
ON (og.name = 'mail_protocol' AND ov.option_group_id = og.id)
WHERE ov.value = %1",
[1 => [$xoauth2Value, 'Positive']]);
}
}
return TRUE;
}

// public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) {
// return TRUE;
// }
/**
* Determine if option value is enabled or used in mail settings.
* @return bool
*/
private static function isXOAUTH2InUse($xoauth2Value) {
$enabled = (bool) CRM_Core_DAO::SingleValueQuery("SELECT ov.is_active FROM civicrm_option_value ov
INNER JOIN civicrm_option_group og
ON (og.name = 'mail_protocol' AND ov.option_group_id = og.id)
WHERE ov.value = %1",
[1 => [$xoauth2Value, 'Positive']]);
$usedInMailSettings = (bool) CRM_Core_DAO::SingleValueQuery("SELECT id FROM civicrm_mail_settings WHERE protocol = %1", [1 => [$xoauth2Value, 'Positive']]);
return $enabled || $usedInMailSettings;
}

}
2 changes: 1 addition & 1 deletion sql/civicrm_generated.mysql

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion xml/templates/civicrm_data.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ VALUES
(@option_group_id_mp, 'Maildir', 2, 'Maildir', NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'POP3', 3, 'POP3', NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'Localdir', 4, 'Localdir', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL , NULL),
(@option_group_id_mp, 'IMAP XOAUTH2', 5, 'IMAP_XOAUTH2', NULL, 0, NULL, 5, NULL, 0, 0, 0, NULL, NULL , NULL),

-- priority
(@option_group_id_priority, '{ts escape="sql"}Urgent{/ts}', 1, 'Urgent', NULL, 0, NULL, 1, NULL, 0, 0, 1, NULL, NULL, NULL),
Expand Down

0 comments on commit bdc29c0

Please sign in to comment.