3 * @copyright Copyright (C) 2020, Friendica
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\Worker;
24 use Friendica\Core\Logger;
25 use Friendica\Database\DBA;
30 * Replace all occurences of the given contact id and replace it
32 * @param integer $search_cid
33 * @param integer $replace_cid
36 public static function execute(int $search_cid, int $replace_cid, int $uid)
38 if (empty($search_cid) || empty($replace_cid) || ($search_cid == $replace_cid)) {
43 Logger::info('Handling duplicate', ['search' => $replace_cid, 'replace' => $search_cid]);
46 DBA::update('item', ['contact-id' => $search_cid], ['contact-id' => $replace_cid]);
47 DBA::update('thread', ['contact-id' => $search_cid], ['contact-id' => $replace_cid]);
48 DBA::update('mail', ['contact-id' => $search_cid], ['contact-id' => $replace_cid]);
49 DBA::update('photo', ['contact-id' => $search_cid], ['contact-id' => $replace_cid]);
50 DBA::update('event', ['cid' => $search_cid], ['cid' => $replace_cid]);
52 // These fields only contain public contact entries (uid = 0)
54 DBA::update('post-tag', ['cid' => $search_cid], ['cid' => $replace_cid]);
55 DBA::update('item', ['author-id' => $search_cid], ['author-id' => $replace_cid]);
56 DBA::update('item', ['owner-id' => $search_cid], ['owner-id' => $replace_cid]);
57 DBA::update('thread', ['author-id' => $search_cid], ['author-id' => $replace_cid]);
58 DBA::update('thread', ['owner-id' => $search_cid], ['owner-id' => $replace_cid]);
60 /// @todo Check if some other data needs to be adjusted as well, possibly the "rel" status?
63 // Remove the duplicate
64 DBA::delete('contact', ['id' => $replace_cid]);