]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Directory.php
Merge branch 'friendica:develop' into mastodon-edit-title-spoiler-update
[friendica.git] / src / Worker / Directory.php
index 63f2e3b6743f93f0d0fa4a7a26e64066fe8da7eb..b66b662d4c8c4432d937d534d42c9098caf343ff 100644 (file)
@@ -1,22 +1,42 @@
 <?php
 /**
- * @file src/Worker/Directory.php
- * @brief Sends updated profile data to the directory
+ * @copyright Copyright (C) 2010-2023, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
  */
 
 namespace Friendica\Worker;
 
-use Friendica\Core\Addon;
-use Friendica\Core\Config;
+use Friendica\Core\Hook;
+use Friendica\Core\Logger;
+use Friendica\Core\Search;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
-use Friendica\Util\Network;
+use Friendica\DI;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 
+/**
+ * Sends updated profile data to the directory
+ */
 class Directory
 {
-       public static function execute($url = '')
+       public static function execute(string $url = '')
        {
-               $dir = Config::get('system', 'directory');
+               $dir = Search::getGlobalDirectory();
 
                if (!strlen($dir)) {
                        return;
@@ -31,27 +51,21 @@ class Directory
 
                $arr = ['url' => $url];
 
-               Addon::callHooks('globaldir_update', $arr);
+               Hook::callAll('globaldir_update', $arr);
 
-               logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG);
+               Logger::info('Updating directory: ' . $arr['url']);
                if (strlen($arr['url'])) {
-                       Network::fetchUrl($dir . '?url=' . bin2hex($arr['url']));
+                       DI::httpClient()->fetch($dir . '?url=' . bin2hex($arr['url']), HttpClientAccept::HTML);
                }
 
                return;
        }
 
        private static function updateAll() {
-               $r = q("SELECT `url` FROM `contact`
-                       INNER JOIN `profile` ON `profile`.`uid` = `contact`.`uid`
-                       INNER JOIN `user` ON `user`.`uid` = `contact`.`uid`
-                               WHERE `contact`.`self` AND `profile`.`net-publish` AND `profile`.`is-default` AND
-                                       NOT `user`.`account_expired` AND `user`.`verified`");
-
-               if (DBA::isResult($r)) {
-                       foreach ($r AS $user) {
-                               Worker::add(PRIORITY_LOW, 'Directory', $user['url']);
-                       }
+               $users = DBA::select('owner-view', ['url'], ['net-publish' => true, 'account_expired' => false, 'verified' => true]);
+               while ($user = DBA::fetch($users)) {
+                       Worker::add(Worker::PRIORITY_LOW, 'Directory', $user['url']);
                }
+               DBA::close($users);
        }
 }