Suppress all emails when Update::run is ran with $sendEmail = false

- Address Renderer crash in the App-less context of Console
This commit is contained in:
Hypolite Petovan 2020-07-13 17:22:21 -04:00
parent 869f3cfec4
commit 059087f998

View file

@ -127,7 +127,7 @@ class Update
// run the pre_update_nnnn functions in update.php // run the pre_update_nnnn functions in update.php
for ($x = $stored + 1; $x <= $current; $x++) { for ($x = $stored + 1; $x <= $current; $x++) {
$r = self::runUpdateFunction($x, 'pre_update'); $r = self::runUpdateFunction($x, 'pre_update', $sendMail);
if (!$r) { if (!$r) {
DI::config()->set('system', 'update', Update::FAILED); DI::config()->set('system', 'update', Update::FAILED);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
@ -156,7 +156,7 @@ class Update
// run the update_nnnn functions in update.php // run the update_nnnn functions in update.php
for ($x = $stored + 1; $x <= $current; $x++) { for ($x = $stored + 1; $x <= $current; $x++) {
$r = self::runUpdateFunction($x, 'update'); $r = self::runUpdateFunction($x, 'update', $sendMail);
if (!$r) { if (!$r) {
DI::config()->set('system', 'update', Update::FAILED); DI::config()->set('system', 'update', Update::FAILED);
DI::lock()->release('dbupdate'); DI::lock()->release('dbupdate');
@ -183,11 +183,12 @@ class Update
* *
* @param int $x the DB version number of the function * @param int $x the DB version number of the function
* @param string $prefix the prefix of the function (update, pre_update) * @param string $prefix the prefix of the function (update, pre_update)
* * @param bool $sendMail whether to send emails on success/failure
* @return bool true, if the update function worked * @return bool true, if the update function worked
* @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/ */
public static function runUpdateFunction($x, $prefix) public static function runUpdateFunction($x, $prefix, bool $sendMail = true)
{ {
$funcname = $prefix . '_' . $x; $funcname = $prefix . '_' . $x;
@ -207,11 +208,13 @@ class Update
$retval = $funcname(); $retval = $funcname();
if ($retval) { if ($retval) {
if ($sendMail) {
//send the administrator an e-mail //send the administrator an e-mail
self::updateFailed( self::updateFailed(
$x, $x,
DI::l10n()->t('Update %s failed. See error logs.', $x) DI::l10n()->t('Update %s failed. See error logs.', $x)
); );
}
Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]); Logger::error('Update function ERROR.', ['function' => $funcname, 'retval' => $retval]);
DI::lock()->release('dbupdate_function'); DI::lock()->release('dbupdate_function');
return false; return false;