Skip to content

Commit

Permalink
Merge branch 'master' of github.com:tbar0970/jethro-pmm
Browse files Browse the repository at this point in the history
  • Loading branch information
tbar0970 committed Nov 15, 2024
2 parents 0f9dd86 + 059eeca commit 41aeb08
Show file tree
Hide file tree
Showing 6 changed files with 601 additions and 4 deletions.
17 changes: 15 additions & 2 deletions include/sms_sender.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,8 @@ public static function sendMessage($message, $recips, $saveAsNote=FALSE)
$response = str_replace("\r", '', $response);
if ($okReg = self::_getSetting('RESPONSE_OK_REGEX')) {
foreach ($recips as $id => $recip) {
$reps['_RECIPIENT_INTERNATIONAL_'] = self::internationaliseNumber($recip['mobile_tel']);
$reps['_RECIPIENT_'] = $recip['mobile_tel'];
$reps['_RECIPIENT_INTERNATIONAL_'] = self::internationaliseNumber(self::normalizeNumber($recip['mobile_tel']));
$reps['_RECIPIENT_'] = self::normalizeNumber($recip['mobile_tel']);
$pattern = '/' . str_replace(array_keys($reps), array_values($reps), $okReg) . '/m';
if (preg_match($pattern, $response)) {
$successes[$id] = $recip;
Expand Down Expand Up @@ -315,6 +315,18 @@ private static function internationaliseNumber($number)
return $number;
}

/**
* Remove any whitespace or non-digits from telephone number.
* https://github.com/tbar0970/jethro-pmm/issues/1093
*/
private static function normalizeNumber($number)
{
if ($number !== null) {
return preg_replace('/\D/', '', $number);
}
return null;
}

private static function logSuccess($recip_count, $message)
{
if (self::$configPrefix !== self::DEFAULT_CONFIG_PREFIX) return; // Log doesn't apply when using dedicated 2FA settings.
Expand Down Expand Up @@ -403,4 +415,5 @@ private static function saveAsNote($recipients, $message)
}
}


}
59 changes: 59 additions & 0 deletions upgrades/2024-upgrade-to-2.36-report-if-agebrackets-are-broken.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*****************************************************************
* This script will report if any Persons have been incorrectly had their Age Bracket set to 'Adult',
* as a result of a Jethro 2.35.1 bug https://github.com/tbar0970/jethro-pmm/issues/1086
* If affected persons are found, the script points people to a new Jethro page which will fix the problem.
* This script makes no changes directly, as user input is required.
******************************************************************/

const SINGLE_PERSON = "single person affected";
const MULTIPLE_PERSONS = "multiple persons affected";
ini_set('display_errors', 1);
error_reporting(E_ALL);

define('JETHRO_ROOT', dirname(dirname(__FILE__)));
set_include_path(get_include_path().PATH_SEPARATOR.JETHRO_ROOT);
require_once JETHRO_ROOT.'/conf.php';
define('DB_MODE', 'private');
require_once JETHRO_ROOT.'/include/init.php';
require_once JETHRO_ROOT.'/upgrades/upgradefixes/2.5.1_fix_agebrackets/AgeBracketChangesFixer.php';
require_once JETHRO_ROOT.'/include/user_system.class.php';

$GLOBALS['user_system'] = new User_System();
$GLOBALS['user_system']->setCLIScript();

require_once JETHRO_ROOT.'/include/system_controller.class.php';
$GLOBALS['system'] = System_Controller::get();

$badchangegroups = AgeBracketChangesFixer::getBadChangeGroups();

// We're interested if any of our BadChangeGroups affect >1 user. If so that's a very likely indication of problems.
// Partition our BadChangeGroups into $groupedchanges[1] (single-person affected) and $groupedchanges['n'] (multiple persons affected).
$groupedchanges = array_reduce($badchangegroups, function ($carry, $cg) {
if ($cg->isBulkEdit()) {
$carry[MULTIPLE_PERSONS][] = $cg;
} else {
$carry[SINGLE_PERSON][] = $cg;
}
return $carry;
}, []);

if (!empty($groupedchanges)) {
if (array_key_exists(MULTIPLE_PERSONS, $groupedchanges)) {
// Bulk edit definitely caused problems. Report affected persons by name.
$allaffected = array_map(fn($gc) => $gc->getAffectedPersons(), $groupedchanges[MULTIPLE_PERSONS]);
$allaffected = array_unique(array_merge(...$allaffected));
print("Warning: ".count($allaffected)." people have been incorrectly turned into Adults by bug https://github.com/tbar0970/jethro-pmm/issues/1086:".PHP_EOL);
} elseif (array_key_exists(SINGLE_PERSON, $groupedchanges)) {
$allaffected = array_map(fn($gc) => $gc->getAffectedPersons(), $groupedchanges[SINGLE_PERSON]);
$allaffected = array_unique(array_merge(...$allaffected));
print("Warning: ".count($allaffected)." people MAY have been incorrectly turned into Adults by bug https://github.com/tbar0970/jethro-pmm/issues/1086:".PHP_EOL);
}
foreach ($allaffected as $affected) {
print($affected.PHP_EOL);
}
print("Please go to Admin -> Fix Broken Age Brackets to fix this".PHP_EOL);
}
//AgeBracketChangesFixer::printBadChanges($badchanges);
//AgeBracketChangesFixer::fix($badChanges);
exit(0);
Loading

0 comments on commit 41aeb08

Please sign in to comment.