3 * @brief Calls the post update functions
5 function post_update() {
7 if (!post_update_1192())
10 if (!post_update_1195())
15 * @brief set the gcontact-id in all item entries
17 * This job has to be started multiple times until all entries are set.
18 * It isn't started in the update function since it would consume too much time and can be done in the background.
20 * @return bool "true" when the job is done
22 function post_update_1192() {
24 // Was the script completed?
25 if (get_config("system", "post_update_version") >= 1192)
28 // Check if the first step is done (Setting "gcontact-id" in the item table)
29 $r = q("SELECT `author-link`, `author-name`, `author-avatar`, `uid`, `network` FROM `item` WHERE `gcontact-id` = 0 LIMIT 1000");
31 // Are there unfinished entries in the thread table?
32 $r = q("SELECT COUNT(*) AS `total` FROM `thread`
33 INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
34 WHERE `thread`.`gcontact-id` = 0 AND
35 (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
37 if ($r AND ($r[0]["total"] == 0)) {
38 set_config("system", "post_update_version", 1192);
42 // Update the thread table from the item table
43 q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
44 SET `thread`.`gcontact-id` = `item`.`gcontact-id`
45 WHERE `thread`.`gcontact-id` = 0 AND
46 (`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
52 foreach ($r AS $item) {
53 $index = $item["author-link"]."-".$item["uid"];
54 $item_arr[$index] = array("author-link" => $item["author-link"],
55 "uid" => $item["uid"],
56 "network" => $item["network"]);
59 // Set the "gcontact-id" in the item table and add a new gcontact entry if needed
60 foreach($item_arr AS $item) {
61 $gcontact_id = get_gcontact_id(array("url" => $item['author-link'], "network" => $item['network'],
62 "photo" => $item['author-avatar'], "name" => $item['author-name']));
63 q("UPDATE `item` SET `gcontact-id` = %d WHERE `uid` = %d AND `author-link` = '%s' AND `gcontact-id` = 0",
64 intval($gcontact_id), intval($item["uid"]), dbesc($item["author-link"]));
70 * @brief Updates the "shadow" field in the item table
72 * @return bool "true" when the job is done
74 function post_update_1195() {
76 // Was the script completed?
77 if (get_config("system", "post_update_version") >= 1195)
80 $end_id = get_config("system", "post_update_1195_end");
82 $r = q("SELECT `id` FROM `item` WHERE `uid` != 0 ORDER BY `id` DESC LIMIT 1");
84 set_config("system", "post_update_1195_end", $r[0]["id"]);
85 $end_id = get_config("system", "post_update_1195_end");
89 $start_id = get_config("system", "post_update_1195_start");
91 $query1 = "SELECT `item`.`id` FROM `item` ";
93 $query2 = "INNER JOIN `item` AS `shadow` ON `item`.`uri` = `shadow`.`uri` AND `shadow`.`uid` = 0 ";
95 $query3 = "WHERE `item`.`uid` != 0 AND `item`.`id` >= %d AND `item`.`id` <= %d
96 AND `item`.`visible` AND NOT `item`.`private`
97 AND NOT `item`.`deleted` AND NOT `item`.`moderated`
98 AND `item`.`network` IN ('%s', '%s', '%s', '')
99 AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
100 AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
101 AND `item`.`shadow` = 0";
103 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 1",
104 intval($start_id), intval($end_id),
105 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
107 set_config("system", "post_update_version", 1195);
110 set_config("system", "post_update_1195_start", $r[0]["id"]);
111 $start_id = get_config("system", "post_update_1195_start");
115 $r = q($query1.$query2.$query3." ORDER BY `item`.`id` LIMIT 10000,1",
116 intval($start_id), intval($end_id),
117 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
119 $pos_id = $r[0]["id"];
123 logger("Progress: Start: ".$start_id." position: ".$pos_id." end: ".$end_id, LOGGER_DEBUG);
125 $r = q("UPDATE `item` ".$query2." SET `item`.`shadow` = `shadow`.`id` ".$query3,
126 intval($start_id), intval($pos_id),
127 dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));