3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\OStatus;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Protocol;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Database\Database;
30 use Friendica\Model\Contact;
31 use Friendica\Module\Response;
32 use Friendica\Navigation\SystemMessages;
33 use Friendica\Util\Profiler;
34 use Psr\Log\LoggerInterface;
36 class Repair extends \Friendica\BaseModule
38 /** @var IHandleUserSessions */
40 /** @var SystemMessages */
41 private $systemMessages;
47 public function __construct(App\Page $page, Database $database, SystemMessages $systemMessages, IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
49 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
51 $this->session = $session;
52 $this->systemMessages = $systemMessages;
53 $this->database = $database;
57 protected function content(array $request = []): string
59 if (!$this->session->getLocalUserId()) {
60 $this->systemMessages->addNotice($this->t('Permission denied.'));
61 $this->baseUrl->redirect('login');
64 $uid = $this->session->getLocalUserId();
66 $counter = intval($request['counter'] ?? 0);
68 $condition = ['uid' => $uid, 'network' => Protocol::OSTATUS, 'rel' => [Contact::FRIEND, Contact::SHARING]];
69 $total = $this->database->count('contact', $condition);
71 $contacts = Contact::selectToArray(['url'], $condition, ['order' => ['url'], 'limit' => [$counter++, 1]]);
73 Contact::createFromProbeForUser($this->session->getLocalUserId(), $contacts[0]['url']);
75 $this->page['htmlhead'] .= '<meta http-equiv="refresh" content="5; url=ostatus/repair?counter=' . $counter . '">';
79 $tpl = Renderer::getMarkupTemplate('ostatus/repair.tpl');
81 return Renderer::replaceMacros($tpl, [
83 'title' => $this->t('Resubscribing to OStatus contacts'),
84 'keep' => $this->t('Keep this window open until done.'),
85 'done' => $this->t('✔ Done'),
86 'nocontacts' => $this->t('No OStatus contacts to resubscribe to.'),
89 '$counter' => $counter,
90 '$contact' => $contacts[0] ?? null,