b59c4e2aef0f4dd7b8e5f90983f0db1a.requirements.script.validator 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /** @var modX $modx */
  3. $modx =& $transport->xpdo;
  4. if (!function_exists('checkVersion')) {
  5. /**
  6. * @param string $description
  7. * @param string $current
  8. * @param array $definition
  9. * @param modX $modx
  10. * @return bool
  11. */
  12. function checkVersion($description, $current, array $definition, $modx)
  13. {
  14. $pass = true;
  15. $passGlyph = '✔';
  16. $failGlyph = '×';
  17. $warnGlyph = '⚠';
  18. // Determine the minimum version (the one that we require today) and the recommended version (the version we'll
  19. // start requiring in 9 months from now).
  20. $realMinimum = false;
  21. $recommended = false;
  22. $recommendedDate = false;
  23. foreach ($definition as $date => $minVersion) {
  24. $date = strtotime($date);
  25. if ($date <= time()) {
  26. $realMinimum = $minVersion;
  27. }
  28. if ($date <= time() + (60 * 60 * 24 * 270)) {
  29. $recommended = $minVersion;
  30. $recommendedDate = $date;
  31. }
  32. }
  33. if ($realMinimum) {
  34. $level = xPDO::LOG_LEVEL_INFO;
  35. $glyph = $passGlyph;
  36. $checkMinimumVersion = $realMinimum;
  37. if (substr_count($realMinimum, '.') < 2) {
  38. $checkMinimumVersion .= '.0-dev';
  39. }
  40. if (version_compare($current, $checkMinimumVersion) <= 0) {
  41. $level = xPDO::LOG_LEVEL_ERROR;
  42. $pass = false;
  43. $glyph = $failGlyph;
  44. }
  45. $modx->log($level, "- {$description} {$realMinimum}+ (minimum): {$glyph} {$current}");
  46. }
  47. if ($pass && $recommended) {
  48. $level = xPDO::LOG_LEVEL_INFO;
  49. $glyph = $passGlyph;
  50. $checkRecommendedVersion = $recommended;
  51. if (substr_count($realMinimum, '.') < 2) {
  52. $checkRecommendedVersion .= '.0-dev';
  53. }
  54. if (version_compare($current, $checkRecommendedVersion) <= 0) {
  55. $level = xPDO::LOG_LEVEL_WARN;
  56. $glyph = $warnGlyph;
  57. }
  58. $recommendedDateFormatted = date('Y-m-d', $recommendedDate);
  59. $modx->log($level, "- {$description} {$recommended}+ (minimum per {$recommendedDateFormatted}): {$glyph} {$current}");
  60. }
  61. return $pass;
  62. }
  63. }
  64. $success = false;
  65. switch($options[xPDOTransport::PACKAGE_ACTION]) {
  66. case xPDOTransport::ACTION_INSTALL:
  67. case xPDOTransport::ACTION_UPGRADE:
  68. $success = true;
  69. $modx->log(xPDO::LOG_LEVEL_INFO, 'Checking if the minimum requirements are met...');
  70. $modxVersion = $modx->getVersionData();
  71. if (!checkVersion('MODX', $modxVersion['full_version'], [
  72. '2019-03-12 12:00:00' => '2.6',
  73. '2019-11-27 12:00:00' => '2.7',
  74. ], $modx)) {
  75. $success = false;
  76. }
  77. if (!checkVersion('PHP', PHP_VERSION, [
  78. '2019-07-01 12:00:00' => '7.1',
  79. '2020-03-01 12:00:00' => '7.2',
  80. '2020-11-30 12:00:00' => '7.3',
  81. ], $modx)) {
  82. $success = false;
  83. }
  84. if ($success) {
  85. $modx->log(xPDO::LOG_LEVEL_INFO, 'Requirements look good!');
  86. }
  87. else {
  88. $modx->log(xPDO::LOG_LEVEL_ERROR, 'Unfortunately, the minimum requirements aren\'t met. Installation cannot continue.');
  89. }
  90. break;
  91. case xPDOTransport::ACTION_UNINSTALL:
  92. $success = true;
  93. break;
  94. }
  95. return $success;