aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Update/_1238.php
blob: 1c79cc36ee560296cb20e39d600019f8efae7d12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php

namespace Zotlabs\Update;

class _1238 {

	function run() {
	
		q("START TRANSACTION");

		$r = q("DELETE FROM app WHERE app_name = '%s'",
			dbesc('Premium Channel')
		);

		// remove broken xchan entries
		$r0 = dbq("DELETE FROM xchan WHERE xchan_hash = ''");

		// remove broken hubloc entries
		$r1 = dbq("DELETE FROM hubloc WHERE hubloc_hash = ''");

		// fix legacy zot hubloc_id_url
		$r2 = dbq("UPDATE hubloc
			SET hubloc_id_url = CONCAT(hubloc_url, '/channel/', SUBSTRING(hubloc_addr FROM 1 FOR POSITION('@' IN hubloc_addr) -1))
			WHERE hubloc_network = 'zot'
			AND hubloc_id_url = ''"
		);

		// fix singleton networks hubloc_id_url
		if(ACTIVE_DBTYPE == DBTYPE_MYSQL) {
			// fix entries for activitypub which miss the xchan_url due to an earlier bug
			$r3 = dbq("UPDATE xchan
				SET xchan_url = xchan_hash
				WHERE xchan_network = 'activitypub'
				AND xchan_url = ''"
			);

			$r4 = dbq("UPDATE hubloc
				LEFT JOIN xchan ON hubloc.hubloc_hash = xchan.xchan_hash
				SET hubloc.hubloc_id_url = xchan.xchan_url
				WHERE hubloc.hubloc_network IN ('activitypub', 'diaspora', 'friendica-over-diaspora', 'gnusoc')
				AND hubloc.hubloc_id_url = ''
				AND xchan.xchan_url IS NOT NULL"
			);
		}
		if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
			// fix entries for activitypub which miss the xchan_url due to an earlier bug
			$r3 = dbq("UPDATE xchan
				SET xchan_url = xchan_hash
				WHERE xchan_network = 'activitypub'
				AND xchan_url = ''"
			);

			$r4 = dbq("UPDATE hubloc
				SET hubloc_id_url = xchan_url
				FROM xchan
				WHERE hubloc_hash = xchan_hash
				AND hubloc_network IN ('activitypub', 'diaspora', 'friendica-over-diaspora', 'gnusoc')
				AND hubloc_id_url = ''
				AND xchan_url IS NOT NULL"
			);
		}

		if($r0 && $r1 && $r2 && $r3 && $r4) {
			// remove hubloc entries where hubloc_id_url could not be fixed
			$r5 = dbq("DELETE FROM hubloc WHERE hubloc_id_url = ''");
		}

		if($r0 && $r1 && $r2 && $r3 && $r4 && $r5) {
			q("COMMIT");
			return UPDATE_SUCCESS;
		}

		q("ROLLBACK");
		return UPDATE_FAILED;

	}

}