[SCRIPTS] Fix resend_confirm_address.php
Fix a regression from 6ec72b2978
,
check if an address is set when using --email.
This commit is contained in:
parent
ef056779fc
commit
f24d122ef5
|
@ -19,7 +19,7 @@ define('INSTALLDIR', dirname(__DIR__));
|
||||||
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
define('PUBLICDIR', INSTALLDIR . DIRECTORY_SEPARATOR . 'public');
|
||||||
|
|
||||||
$shortoptions = 'e::ay';
|
$shortoptions = 'e::ay';
|
||||||
$longoptions = array('email=', 'all', 'yes');
|
$longoptions = ['email=', 'all', 'yes'];
|
||||||
|
|
||||||
$self = basename($_SERVER['PHP_SELF']);
|
$self = basename($_SERVER['PHP_SELF']);
|
||||||
|
|
||||||
|
@ -48,10 +48,19 @@ $ca = null;
|
||||||
|
|
||||||
if (have_option('e', 'email')) {
|
if (have_option('e', 'email')) {
|
||||||
$email = get_option_value('e', 'email');
|
$email = get_option_value('e', 'email');
|
||||||
|
if (is_null($email)) {
|
||||||
|
echo "You must provide an email.\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
$ca = Confirm_address::getByAddress($email, 'email');
|
$ca = Confirm_address::getByAddress($email, 'email');
|
||||||
} catch (NoResultException $e) {
|
} catch (NoResultException $e) {
|
||||||
print sprintf("Can't find %s address %s in %s table.\n", $e->obj->address_type, $e->obj->address, $e->obj->tableName());
|
echo sprintf(
|
||||||
|
"Can't find %s address %s in %s table.\n",
|
||||||
|
$e->obj->address_type,
|
||||||
|
$e->obj->address,
|
||||||
|
$e->obj->tableName()
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} elseif (have_option('a', 'all')) {
|
} elseif (have_option('a', 'all')) {
|
||||||
|
@ -59,24 +68,24 @@ if (have_option('e', 'email')) {
|
||||||
$ca = new Confirm_address();
|
$ca = new Confirm_address();
|
||||||
$ca->address_type = 'email';
|
$ca->address_type = 'email';
|
||||||
if (!$ca->find()) {
|
if (!$ca->find()) {
|
||||||
print "confirm_address table contains no lingering email addresses\n";
|
echo "confirm_address table contains no lingering email addresses\n";
|
||||||
exit(0);
|
exit();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
print "You must provide an email (or --all).\n";
|
echo "You must provide an email (or --all).\n";
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!have_option('y', 'yes')) {
|
if (!have_option('y', 'yes')) {
|
||||||
print "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
|
echo "About to resend confirm_address email to {$ca->N} recipients. Are you sure? [y/N] ";
|
||||||
$response = fgets(STDIN);
|
$response = fgets(STDIN);
|
||||||
if (strtolower(trim($response)) != 'y') {
|
if (strcasecmp(trim($response), 'y') != 0) {
|
||||||
print "Aborting.\n";
|
echo "Aborting.\n";
|
||||||
exit(0);
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mailConfirmAddress(Confirm_address $ca)
|
function mail_confirm_address(Confirm_address $ca): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$user = User::getByID($ca->user_id);
|
$user = User::getByID($ca->user_id);
|
||||||
|
@ -89,24 +98,25 @@ function mailConfirmAddress(Confirm_address $ca)
|
||||||
throw new AlreadyFulfilledException('User already has identical confirmed email address.');
|
throw new AlreadyFulfilledException('User already has identical confirmed email address.');
|
||||||
}
|
}
|
||||||
} catch (AlreadyFulfilledException $e) {
|
} catch (AlreadyFulfilledException $e) {
|
||||||
print "\n User already had verified email: "._ve($ca->address);
|
echo "\n User already had verified email: " . _ve($ca->address);
|
||||||
$ca->delete();
|
$ca->delete();
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
print "\n Failed to get user with ID "._ve($user_id).', deleting confirm_address entry: '._ve($e->getMessage());
|
echo "\n Failed to get user with ID " . _ve($user_id)
|
||||||
|
. ', deleting confirm_address entry: ' . _ve($e->getMessage());
|
||||||
$ca->delete();
|
$ca->delete();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mail_confirm_address($user, $ca->code, $user->getNickname(), $ca->address);
|
$ca->sendConfirmation();
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once INSTALLDIR . '/lib/util/mail.php';
|
require_once INSTALLDIR . '/lib/util/mail.php';
|
||||||
|
|
||||||
if (!$all) {
|
if (!$all) {
|
||||||
mailConfirmAddress($ca);
|
mail_confirm_address($ca);
|
||||||
} else {
|
} else {
|
||||||
while ($ca->fetch()) {
|
while ($ca->fetch()) {
|
||||||
mailConfirmAddress($ca);
|
mail_confirm_address($ca);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print "\nDONE.\n";
|
echo "\nDONE.\n";
|
||||||
|
|
Loading…
Reference in New Issue
Block a user