|
| 1 | +<?php |
| 2 | +/* |
| 3 | + +--------------------------------------------------------------------+ |
| 4 | + | Copyright CiviCRM LLC. All rights reserved. | |
| 5 | + | | |
| 6 | + | This work is published under the GNU AGPLv3 license with some | |
| 7 | + | permitted exceptions and without any warranty. For full license | |
| 8 | + | and copyright information, see https://civicrm.org/licensing | |
| 9 | + +--------------------------------------------------------------------+ |
| 10 | + */ |
| 11 | + |
| 12 | +use CRM_Omnipaymultiprocessor_ExtensionUtil as E; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class CRM_Omnipaymultiprocessor_Check |
| 16 | + */ |
| 17 | +class CRM_Omnipaymultiprocessor_Check { |
| 18 | + |
| 19 | + /** |
| 20 | + * @var string |
| 21 | + */ |
| 22 | + const MIN_VERSION_MJWSHARED = '0.9.3'; |
| 23 | + |
| 24 | + public static function checkRequirements(&$messages) { |
| 25 | + self::checkExtensionMjwshared($messages); |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * @param array $messages |
| 30 | + * |
| 31 | + * @throws \CiviCRM_API3_Exception |
| 32 | + */ |
| 33 | + private static function checkExtensionMjwshared(&$messages) { |
| 34 | + // mjwshared: required. Requires min version |
| 35 | + $extensionName = 'mjwshared'; |
| 36 | + $extensions = civicrm_api3('Extension', 'get', [ |
| 37 | + 'full_name' => $extensionName, |
| 38 | + ]); |
| 39 | + |
| 40 | + if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] !== 'installed')) { |
| 41 | + $message = new CRM_Utils_Check_Message( |
| 42 | + __FUNCTION__ . E::SHORT_NAME . '_requirements', |
| 43 | + E::ts('The <em>%1</em> extension requires the <em>Payment Shared</em> extension which is not installed. See <a href="%2" target="_blank">details</a> for more information.', |
| 44 | + [ |
| 45 | + 1 => ucfirst(E::SHORT_NAME), |
| 46 | + 2 => 'https://civicrm.org/extensions/mjwshared', |
| 47 | + ] |
| 48 | + ), |
| 49 | + E::ts('%1: Missing Requirements', [1 => ucfirst(E::SHORT_NAME)]), |
| 50 | + \Psr\Log\LogLevel::ERROR, |
| 51 | + 'fa-money' |
| 52 | + ); |
| 53 | + $message->addAction( |
| 54 | + E::ts('Install now'), |
| 55 | + NULL, |
| 56 | + 'href', |
| 57 | + ['path' => 'civicrm/admin/extensions', 'query' => ['action' => 'update', 'id' => $extensionName, 'key' => $extensionName]] |
| 58 | + ); |
| 59 | + $messages[] = $message; |
| 60 | + return; |
| 61 | + } |
| 62 | + if ($extensions['values'][$extensions['id']]['status'] === 'installed') { |
| 63 | + self::requireExtensionMinVersion($messages, $extensionName, self::MIN_VERSION_MJWSHARED, $extensions['values'][$extensions['id']]['version']); |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @param array $messages |
| 69 | + * @param string $extensionName |
| 70 | + * @param string $minVersion |
| 71 | + * @param string $actualVersion |
| 72 | + */ |
| 73 | + private static function requireExtensionMinVersion(&$messages, $extensionName, $minVersion, $actualVersion) { |
| 74 | + if (version_compare($actualVersion, $minVersion) === -1) { |
| 75 | + $message = new CRM_Utils_Check_Message( |
| 76 | + __FUNCTION__ . $extensionName . E::SHORT_NAME . '_requirements', |
| 77 | + E::ts('The %1 extension requires the %2 extension version %3 or greater but your system has version %4.', |
| 78 | + [ |
| 79 | + 1 => ucfirst(E::SHORT_NAME), |
| 80 | + 2 => $extensionName, |
| 81 | + 3 => $minVersion, |
| 82 | + 4 => $actualVersion |
| 83 | + ]), |
| 84 | + E::ts('%1: Missing Requirements', [1 => ucfirst(E::SHORT_NAME)]), |
| 85 | + \Psr\Log\LogLevel::ERROR, |
| 86 | + 'fa-money' |
| 87 | + ); |
| 88 | + $message->addAction( |
| 89 | + E::ts('Upgrade now'), |
| 90 | + NULL, |
| 91 | + 'href', |
| 92 | + ['path' => 'civicrm/admin/extensions', 'query' => ['action' => 'update', 'id' => $extensionName, 'key' => $extensionName]] |
| 93 | + ); |
| 94 | + $messages[] = $message; |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | +} |
0 commit comments