3 * @copyright Copyright (C) 2010-2021, 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\Console;
25 use Friendica\Database\Database;
26 use Friendica\Database\DBA;
28 use Friendica\Model\Contact;
29 use Friendica\Util\Strings;
33 * License: AGPLv3 or later, same as Friendica
35 class FixAPDeliveryWorkerTaskParameters extends \Asika\SimpleConsole\Console
37 protected $helpOptions = ['h', 'help', '?'];
60 protected function getHelp()
63 console fixapdeliveryworkertaskparameters - fix APDelivery worker task parameters corrupted during the 2020.12 RC period
65 bin/console fixapdeliveryworkertaskparameters [-h|--help|-?] [-v]
68 During the 2020.12 RC period some worker task parameters have been corrupted, resulting in the impossibility to execute them.
69 This command restores their expected parameters.
70 If you didn't run Friendica during the 2020.12 RC period, you do not need to use this command.
73 -h|--help|-? Show help information
74 -v Show more debug information.
79 public function __construct(App\Mode $appMode, Database $dba, \Friendica\Core\L10n $l10n, array $argv = null)
81 parent::__construct($argv);
83 $this->appMode = $appMode;
88 protected function doExecute()
90 if ($this->getOption('v')) {
91 $this->out('Class: ' . __CLASS__);
92 $this->out('Arguments: ' . var_export($this->args, true));
93 $this->out('Options: ' . var_export($this->options, true));
96 if (count($this->args) > 0) {
97 throw new \Asika\SimpleConsole\CommandArgsException('Too many arguments');
100 if ($this->appMode->isInstall()) {
101 throw new RuntimeException('Friendica isn\'t properly installed yet.');
105 $this->processed = 0;
109 $result = $this->dba->p('SELECT `id`, `parameter` FROM `workerqueue` WHERE `command` = "APDelivery" AND `parameter` LIKE "[\"%\",\"\",%" LIMIT ' . $this->examined . ', 100');
110 while ($row = $this->dba->fetch($result)) {
112 $this->processRow($row);
114 } while ($this->dba->isResult($result));
116 if ($this->getOption('v')) {
117 $this->out('Examined: ' . $this->examined);
118 $this->out('Processed: ' . $this->processed);
119 $this->out('Errored: ' . $this->errored);
125 private function processRow(array $workerqueueItem)
127 $parameters = json_decode($workerqueueItem['parameter'], true);
131 if ($this->getOption('v')) {
132 $this->out('Unabled to parse parameter JSON of the row with id ' . $workerqueueItem['id']);
133 $this->out('JSON: ' . var_export($workerqueueItem['parameter'], true));
137 if ($parameters[1] !== '' && !is_array($parameters[2])) {
138 // Nothing to do, we save a write
142 if ($parameters[1] === '') {
146 if (is_array($parameters[2])) {
147 $parameters[4] = $parameters[2];
148 $contact = Contact::getById(current($parameters[2]), ['url']);
149 $parameters[2] = $contact['url'];
152 $fields = ['parameter' => json_encode($parameters)];
153 if ($this->dba->update('workerqueue', $fields, ['id' => $workerqueueItem['id']])) {
157 if ($this->getOption('v')) {
158 $this->out('Unabled to update the row with id ' . $workerqueueItem['id']);
159 $this->out('Fields: ' . var_export($fields, true));