]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/UpdateContact.php
Drop UpdateContact worker task if contact is blocked
[friendica.git] / src / Worker / UpdateContact.php
index 790badc9d2d3e2510f49416c4e568c22ed4a075f..c2e443282056381cae6594c1c88d7a618e1d7e1f 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
  *
 namespace Friendica\Worker;
 
 use Friendica\Core\Logger;
+use Friendica\Core\Worker;
 use Friendica\Model\Contact;
+use Friendica\Network\HTTPException\InternalServerErrorException;
+use Friendica\Util\Network;
 
 class UpdateContact
 {
        /**
         * Update contact data via probe
-        * @param int    $contact_id Contact ID
+        *
+        * @param int $contact_id Contact ID
+        * @return void
+        * @throws InternalServerErrorException
+        * @throws \ImagickException
         */
-       public static function execute($contact_id)
+       public static function execute(int $contact_id)
        {
+               // Silently dropping the task if the contact is blocked
+               if (Contact::isBlocked($contact_id)) {
+                       return;
+               }
+
                $success = Contact::updateFromProbe($contact_id);
 
                Logger::info('Updated from probe', ['id' => $contact_id, 'success' => $success]);
        }
+
+       /**
+        * @param array|int $run_parameters Priority constant or array of options described in Worker::add
+        * @param int       $contact_id
+        * @return int
+        * @throws InternalServerErrorException
+        */
+       public static function add($run_parameters, int $contact_id): int
+       {
+               if (!$contact_id) {
+                       throw new \InvalidArgumentException('Invalid value provided for contact_id');
+               }
+
+               // Dropping the task if the contact is blocked
+               if (Contact::isBlocked($contact_id)) {
+                       return 0;
+               }
+
+               return Worker::add($run_parameters, 'UpdateContact', $contact_id);
+       }
 }