forked from friendica/friendica-addons
Mailstream: use new logging convention
This commit is contained in:
parent
c6bd06d3d7
commit
a46c4ef9f3
1 changed files with 27 additions and 28 deletions
|
@ -8,7 +8,6 @@
|
|||
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Core\Hook;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Core\Worker;
|
||||
|
@ -32,7 +31,7 @@ function mailstream_install()
|
|||
Hook::register('post_remote_end', 'addon/mailstream/mailstream.php', 'mailstream_post_hook');
|
||||
Hook::register('mailstream_send_hook', 'addon/mailstream/mailstream.php', 'mailstream_send_hook');
|
||||
|
||||
Logger::info("installed mailstream");
|
||||
DI::logger()->info("installed mailstream");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,7 +85,7 @@ function mailstream_generate_id(string $uri): string
|
|||
$host = DI::baseUrl()->getHost();
|
||||
$resource = hash('md5', $uri);
|
||||
$message_id = "<" . $resource . "@" . $host . ">";
|
||||
Logger::debug('generated message ID', ['id' => $message_id, 'uri' => $uri]);
|
||||
DI::logger()->debug('generated message ID', ['id' => $message_id, 'uri' => $uri]);
|
||||
return $message_id;
|
||||
}
|
||||
|
||||
|
@ -95,28 +94,28 @@ function mailstream_send_hook(array $data)
|
|||
$criteria = array('uid' => $data['uid'], 'contact-id' => $data['contact-id'], 'uri' => $data['uri']);
|
||||
$item = Post::selectFirst([], $criteria);
|
||||
if (empty($item)) {
|
||||
Logger::error('could not find item');
|
||||
DI::logger()->error('could not find item');
|
||||
return;
|
||||
}
|
||||
|
||||
if ($item['deleted']) {
|
||||
Logger::debug('mailstream_send_hook skipping deleted item', ['guid' => $item['guid']]);
|
||||
DI::logger()->debug('mailstream_send_hook skipping deleted item', ['guid' => $item['guid']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$user = User::getById($item['uid']);
|
||||
if (empty($user)) {
|
||||
Logger::error('mailstream_send_hook could not find user', ['uid' => $item['uid']]);
|
||||
DI::logger()->error('mailstream_send_hook could not find user', ['uid' => $item['uid']]);
|
||||
return;
|
||||
}
|
||||
|
||||
$author = DBA::selectFirst('contact', ['nick', 'blocked', 'uri-id'], ['id' => $data['author-id'], 'self' => false]);
|
||||
if (!DBA::isResult($author)) {
|
||||
Logger::error('mailstream_send_hook could not find author', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
DI::logger()->error('mailstream_send_hook could not find author', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
return;
|
||||
}
|
||||
if ($author['blocked']) {
|
||||
Logger::info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
DI::logger()->info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'author-id' => $data['author-id']]);
|
||||
return;
|
||||
}
|
||||
$collapsed = false;
|
||||
|
@ -126,11 +125,11 @@ function mailstream_send_hook(array $data)
|
|||
}
|
||||
if (DBA::isResult($user_contact)) {
|
||||
if ($user_contact['blocked']) {
|
||||
Logger::info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
DI::logger()->info('mailstream_send_hook author is blocked', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
return;
|
||||
}
|
||||
if ($user_contact['ignored']) {
|
||||
Logger::info('mailstream_send_hook author is ignored', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
DI::logger()->info('mailstream_send_hook author is ignored', ['guid' => $item['guid'], 'cid' => $user_contact['cid']]);
|
||||
return;
|
||||
}
|
||||
if ($user_contact['collapsed']) {
|
||||
|
@ -139,9 +138,9 @@ function mailstream_send_hook(array $data)
|
|||
}
|
||||
|
||||
if (!mailstream_send($data['message_id'], $item, $user, $collapsed)) {
|
||||
Logger::debug('mailstream_send_hook send failed, will retry', $data);
|
||||
DI::logger()->debug('mailstream_send_hook send failed, will retry', $data);
|
||||
if (!Worker::defer()) {
|
||||
Logger::error('failed and could not defer', $data);
|
||||
DI::logger()->error('failed and could not defer', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -157,32 +156,32 @@ function mailstream_send_hook(array $data)
|
|||
function mailstream_post_hook(array &$item)
|
||||
{
|
||||
if ($item['uid'] === 0) {
|
||||
Logger::debug('mailstream: root user, skipping item ' . $item['id']);
|
||||
DI::logger()->debug('mailstream: root user, skipping item ' . $item['id']);
|
||||
return;
|
||||
}
|
||||
if (!DI::pConfig()->get($item['uid'], 'mailstream', 'enabled')) {
|
||||
Logger::debug('mailstream: not enabled.', ['item' => $item['id'], ' uid ' => $item['uid']]);
|
||||
DI::logger()->debug('mailstream: not enabled.', ['item' => $item['id'], ' uid ' => $item['uid']]);
|
||||
return;
|
||||
}
|
||||
if (!$item['contact-id']) {
|
||||
Logger::debug('no contact-id', ['item' => $item['id']]);
|
||||
DI::logger()->debug('no contact-id', ['item' => $item['id']]);
|
||||
return;
|
||||
}
|
||||
if (!$item['uri']) {
|
||||
Logger::debug('no uri', ['item' => $item['id']]);
|
||||
DI::logger()->debug('no uri', ['item' => $item['id']]);
|
||||
return;
|
||||
}
|
||||
if ($item['verb'] == Activity::ANNOUNCE) {
|
||||
Logger::debug('ignoring announce', ['item' => $item['id']]);
|
||||
DI::logger()->debug('ignoring announce', ['item' => $item['id']]);
|
||||
return;
|
||||
}
|
||||
if (DI::pConfig()->get($item['uid'], 'mailstream', 'nolikes')) {
|
||||
if ($item['verb'] == Activity::LIKE) {
|
||||
Logger::debug('ignoring like', ['item' => $item['id']]);
|
||||
DI::logger()->debug('ignoring like', ['item' => $item['id']]);
|
||||
return;
|
||||
}
|
||||
if ($item['verb'] == Activity::DISLIKE) {
|
||||
Logger::debug('ignoring dislike', ['item' => $item['id']]);
|
||||
DI::logger()->debug('ignoring dislike', ['item' => $item['id']]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +233,7 @@ function mailstream_do_images(array &$item, array &$attachments)
|
|||
try {
|
||||
$curlResult = DI::httpClient()->get($url, HttpClientAccept::DEFAULT, [HttpClientOptions::COOKIEJAR => $cookiejar]);
|
||||
if (!$curlResult->isSuccess()) {
|
||||
Logger::debug('mailstream: fetch image url failed', [
|
||||
DI::logger()->debug('mailstream: fetch image url failed', [
|
||||
'url' => $url,
|
||||
'item_id' => $item['id'],
|
||||
'return_code' => $curlResult->getReturnCode()
|
||||
|
@ -242,7 +241,7 @@ function mailstream_do_images(array &$item, array &$attachments)
|
|||
continue;
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
Logger::error('exception fetching url', ['url' => $url, 'item_id' => $item['id']]);
|
||||
DI::logger()->error('exception fetching url', ['url' => $url, 'item_id' => $item['id']]);
|
||||
continue;
|
||||
}
|
||||
$attachments[$url] = [
|
||||
|
@ -343,7 +342,7 @@ function mailstream_subject(array $item): string
|
|||
}
|
||||
$contact = Contact::selectFirst([], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
|
||||
if (!DBA::isResult($contact)) {
|
||||
Logger::error('no contact', [
|
||||
DI::logger()->error('no contact', [
|
||||
'item' => $item['id'],
|
||||
'plink' => $item['plink'],
|
||||
'contact id' => $item['contact-id'],
|
||||
|
@ -386,16 +385,16 @@ function mailstream_subject(array $item): string
|
|||
function mailstream_send(string $message_id, array $item, array $user, bool $collapsed): bool
|
||||
{
|
||||
if (!is_array($item)) {
|
||||
Logger::error('item is empty', ['message_id' => $message_id]);
|
||||
DI::logger()->error('item is empty', ['message_id' => $message_id]);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$item['visible']) {
|
||||
Logger::debug('item not yet visible', ['item uri' => $item['uri']]);
|
||||
DI::logger()->debug('item not yet visible', ['item uri' => $item['uri']]);
|
||||
return false;
|
||||
}
|
||||
if (!$message_id) {
|
||||
Logger::error('no message ID supplied', ['item uri' => $item['uri'], 'user email' => $user['email']]);
|
||||
DI::logger()->error('no message ID supplied', ['item uri' => $item['uri'], 'user email' => $user['email']]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -459,15 +458,15 @@ function mailstream_send(string $message_id, array $item, array $user, bool $col
|
|||
if (!$mail->Send()) {
|
||||
throw new Exception($mail->ErrorInfo);
|
||||
}
|
||||
Logger::debug('sent message', [
|
||||
DI::logger()->debug('sent message', [
|
||||
'message ID' => $mail->MessageID,
|
||||
'subject' => $mail->Subject,
|
||||
'address' => $address
|
||||
]);
|
||||
} catch (phpmailerException $e) {
|
||||
Logger::debug('mailstream_send PHPMailer exception sending message', ['item uri' => $item['uri'], 'message_id' => $message_id, 'error' => $e->errorMessage()]);
|
||||
DI::logger()->debug('mailstream_send PHPMailer exception sending message', ['item uri' => $item['uri'], 'message_id' => $message_id, 'error' => $e->errorMessage()]);
|
||||
} catch (Exception $e) {
|
||||
Logger::debug('mailstream_send exception sending message', ['item uri' => $item['uri'], 'message_id' => $message_id, 'error' => $e->errorMessage()]);
|
||||
DI::logger()->debug('mailstream_send exception sending message', ['item uri' => $item['uri'], 'message_id' => $message_id, 'error' => $e->errorMessage()]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
Loading…
Add table
Reference in a new issue