3 * @file include/post_update.php
7 * @brief Calls the post update functions
9 function post_update() {
11 if (!post_update_1192())
14 if (!post_update_1194())
19 * @brief set the gcontact-id in all item entries
21 * This job has to be started multiple times until all entries are set.
22 * It isn't started in the update function since it would consume too much time and can be done in the background.
24 * @return bool "true" when the job is done
26 function post_update_1192() {
28 // Was the script completed?
29 if (get_config("system", "post_update_version") >= 1192)
32 // Check if the first step is done (Setting "gcontact-id" in the item table)
33 $r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
35 // Are there unfinished entries in the thread table?
36 $r = q("SELECT COUNT(*) AS `total` FROM `thread`
37 INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
38 WHERE `thread`.`gcontact-id` = 0 AND
39 (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
41 if ($r AND ($r[0]["total"] == 0)) {
42 set_config("system", "post_update_version", 1192);
46 // Update the thread table from the item table
47 q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
48 SET `thread`.`gcontact-id` = `item`.`gcontact-id`
49 WHERE `thread`.`gcontact-id` = 0 AND
50 (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
56 foreach ($r AS $item) {
57 $index = $item["author-link"]."-".$item["uid"];
58 $item_arr[$index] = array("author-link" => $item["author-link"],
59 "uid" => $item["uid"],
60 "network" => $item["network"]);
63 // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
64 foreach($item_arr AS $item) {
65 $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
66 "photo" => $item['author-avatar'], "name" => $item['author-name']));
67 q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
68 intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
74 * @brief Updates the "global" field in the item table
76 * @return bool "true" when the job is done
78 function post_update_1194() {
80 // Was the script completed?
81 if (get_config("system", "post_update_version") >= 1194)
84 logger("Start", LOGGER_DEBUG);
86 $end_id = get_config("system", "post_update_1194_end");
88 $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
90 set_config("system", "post_update_1194_end", $r[0]["id"]);
91 $end_id = get_config("system", "post_update_1194_end");
95 logger("End ID: ".$end_id, LOGGER_DEBUG);
97 $start_id = get_config("system", "post_update_1194_start");
99 $query1 = "SELECT `item`.`id` FROM `item` ";
101 $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
103 $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
104 AND `item`.`visible` AND NOT `item`.`private`
105 AND NOT `item`.`deleted` AND NOT `item`.`moderated`
106 AND `item`.`network` IN ('%s', '%s', '%s', '')
107 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
108 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
109 AND NOT `item`.`global`";
111 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
112 intval($start_id), intval($end_id),
113 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
115 set_config("system", "post_update_version", 1194);
116 logger("Update is done", LOGGER_DEBUG);
119 set_config("system", "post_update_1194_start", $r[0]["id"]);
120 $start_id = get_config("system", "post_update_1194_start");
123 logger("Start ID: ".$start_id, LOGGER_DEBUG);
125 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1000,1",
126 intval($start_id), intval($end_id),
127 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
129 $pos_id = $r[0]["id"];
133 logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
135 $r = q("UPDATE `item` ".$query2." SET `item`.`global` = 1 ".$query3,
136 intval($start_id), intval($pos_id),
137 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
139 logger("Done", LOGGER_DEBUG);