]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/PubSubPublish.php
Merge pull request #12680 from nupplaphil/feat/addon_logger
[friendica.git] / src / Worker / PubSubPublish.php
index a5381c18d16a6af23684cb01cfc73b451deaee5e..bb10361c5800b94b53cb0744edc4a1abd138f806 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2023, the Friendica project
  *
  * @license GNU AGPL version 3 or any later version
  *
@@ -29,7 +29,13 @@ use Friendica\Protocol\OStatus;
 
 class PubSubPublish
 {
-       public static function execute($pubsubpublish_id = 0)
+       /**
+        * Publishes subscriber id
+        *
+        * @param int $pubsubpublish_id Push subscriber id
+        * @return void
+        */
+       public static function execute(int $pubsubpublish_id = 0)
        {
                if ($pubsubpublish_id == 0) {
                        return;
@@ -38,7 +44,13 @@ class PubSubPublish
                self::publish($pubsubpublish_id);
        }
 
-       private static function publish($id)
+       /**
+        * Publishes push subscriber
+        *
+        * @param int $id Push subscriber id
+        * @return void
+        */
+       private static function publish(int $id)
        {
                $subscriber = DBA::selectFirst('push_subscriber', [], ['id' => $id]);
                if (!DBA::isResult($subscriber)) {
@@ -48,7 +60,7 @@ class PubSubPublish
                /// @todo Check server status with GServer::check()
                // Before this can be done we need a way to safely detect the server url.
 
-               Logger::log("Generate feed of user " . $subscriber['nickname']. " to " . $subscriber['callback_url']. " - last updated " . $subscriber['last_update'], Logger::DEBUG);
+               Logger::info('Generate feed of user ' . $subscriber['nickname'] . ' to ' . $subscriber['callback_url'] . ' - last updated ' . $subscriber['last_update']);
 
                $last_update = $subscriber['last_update'];
                $params = OStatus::feed($subscriber['nickname'], $last_update);
@@ -57,25 +69,26 @@ class PubSubPublish
                        return;
                }
 
-               $hmac_sig = hash_hmac("sha1", $params, $subscriber['secret']);
+               $hmac_sig = hash_hmac('sha1', $params, $subscriber['secret']);
 
-               $headers = ["Content-type: application/atom+xml",
-                               sprintf("Link: <%s>;rel=hub,<%s>;rel=self",
+               $headers = [
+                       'Content-type' => 'application/atom+xml',
+                       'Link' => sprintf('<%s>;rel=hub,<%s>;rel=self',
                                        DI::baseUrl() . '/pubsubhubbub/' . $subscriber['nickname'],
                                        $subscriber['topic']),
-                               "X-Hub-Signature: sha1=" . $hmac_sig];
+                       'X-Hub-Signature' => 'sha1=' . $hmac_sig];
 
-               Logger::log('POST ' . print_r($headers, true) . "\n" . $params, Logger::DATA);
+               Logger::debug('POST', ['headers' => $headers, 'params' => $params]);
 
-               $postResult = DI::httpRequest()->post($subscriber['callback_url'], $params, $headers);
+               $postResult = DI::httpClient()->post($subscriber['callback_url'], $params, $headers);
                $ret = $postResult->getReturnCode();
 
                if ($ret >= 200 && $ret <= 299) {
-                       Logger::log('Successfully pushed to ' . $subscriber['callback_url']);
+                       Logger::info('Successfully pushed to ' . $subscriber['callback_url']);
 
                        PushSubscriber::reset($subscriber['id'], $last_update);
                } else {
-                       Logger::log('Delivery error when pushing to ' . $subscriber['callback_url'] . ' HTTP: ' . $ret);
+                       Logger::notice('Delivery error when pushing to ' . $subscriber['callback_url'] . ' HTTP: ' . $ret);
 
                        PushSubscriber::delay($subscriber['id']);
                }