]> git.mxchange.org Git - friendica.git/blob - update.php
Fixes:
[friendica.git] / update.php
1 <?php
2
3 use Friendica\Core\Addon;
4 use Friendica\Core\Config;
5 use Friendica\Core\L10n;
6 use Friendica\Core\PConfig;
7 use Friendica\Core\Worker;
8 use Friendica\Database\DBA;
9 use Friendica\Database\DBM;
10 use Friendica\Model\Contact;
11 use Friendica\Model\Item;
12 use Friendica\Model\User;
13
14 require_once 'include/dba.php';
15
16 /**
17  *
18  * update.php - automatic system update
19  *
20  * This function is responsible for doing post update changes to the data
21  * (not the structure) in the database.
22  *
23  * Database structure changes are done in src/Database/DBStructure.php
24  *
25  * If there is a need for a post process to a structure change, update this file
26  * by adding a new function at the end with the number of the new DB_UPDATE_VERSION.
27  *
28  * The numbered script in this file has to be exactly like the DB_UPDATE_VERSION
29  *
30  * Example:
31  * You are currently on version 4711 and you are preparing changes that demand an update script.
32  *
33  * 1. Create a function "update_4712()" here in the update.php
34  * 2. Apply the needed structural changes in src/Database/DBStructure.php
35  * 3. Set DB_UPDATE_VERSION in boot.php to 4712.
36  *
37  * If you need to run a script before the database update, name the function "pre_update_4712()"
38  */
39
40 function update_1178() {
41         require_once 'mod/profiles.php';
42
43         $profiles = q("SELECT `uid`, `about`, `locality`, `pub_keywords`, `gender` FROM `profile` WHERE `is-default`");
44
45         foreach ($profiles AS $profile) {
46                 if ($profile["about"].$profile["locality"].$profile["pub_keywords"].$profile["gender"] == "")
47                         continue;
48
49                 $profile["pub_keywords"] = profile_clean_keywords($profile["pub_keywords"]);
50
51                 $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` AND `uid` = %d",
52                                 dbesc($profile["about"]),
53                                 dbesc($profile["locality"]),
54                                 dbesc($profile["pub_keywords"]),
55                                 dbesc($profile["gender"]),
56                                 intval($profile["uid"])
57                         );
58         }
59 }
60
61 function update_1179() {
62         if (Config::get('system','no_community_page'))
63                 Config::set('system','community_page_style', CP_NO_COMMUNITY_PAGE);
64
65         // Update the central item storage with uid=0
66         Worker::add(PRIORITY_LOW, "threadupdate");
67
68         return UPDATE_SUCCESS;
69 }
70
71 function update_1181() {
72
73         // Fill the new fields in the term table.
74         Worker::add(PRIORITY_LOW, "TagUpdate");
75
76         return UPDATE_SUCCESS;
77 }
78
79 function update_1189() {
80
81         if (strlen(Config::get('system','directory_submit_url')) &&
82                 !strlen(Config::get('system','directory'))) {
83                 Config::set('system','directory', dirname(Config::get('system','directory_submit_url')));
84                 Config::delete('system','directory_submit_url');
85         }
86
87         return UPDATE_SUCCESS;
88 }
89
90 function update_1191() {
91         Config::set('system', 'maintenance', 1);
92
93         if (Addon::isEnabled('forumlist')) {
94                 $addon = 'forumlist';
95                 $addons = Config::get('system', 'addon');
96                 $addons_arr = [];
97
98                 if ($addons) {
99                         $addons_arr = explode(",",str_replace(" ", "", $addons));
100
101                         $idx = array_search($addon, $addons_arr);
102                         if ($idx !== false){
103                                 unset($addons_arr[$idx]);
104                                 //delete forumlist manually from addon and hook table
105                                 // since Addon::uninstall() don't work here
106                                 q("DELETE FROM `addon` WHERE `name` = 'forumlist' ");
107                                 q("DELETE FROM `hook` WHERE `file` = 'addon/forumlist/forumlist.php' ");
108                                 Config::set('system','addon', implode(", ", $addons_arr));
109                         }
110                 }
111         }
112
113         // select old formlist addon entries
114         $r = q("SELECT `uid`, `cat`, `k`, `v` FROM `pconfig` WHERE `cat` = '%s' ",
115                 dbesc('forumlist')
116         );
117
118         // convert old forumlist addon entries in new config entries
119         if (DBM::is_result($r)) {
120                 foreach ($r as $rr) {
121                         $uid = $rr['uid'];
122                         $family = $rr['cat'];
123                         $key = $rr['k'];
124                         $value = $rr['v'];
125
126                         if ($key === 'randomise')
127                                 PConfig::delete($uid,$family,$key);
128
129                         if ($key === 'show_on_profile') {
130                                 if ($value)
131                                         PConfig::set($uid,feature,forumlist_profile,$value);
132
133                                 PConfig::delete($uid,$family,$key);
134                         }
135
136                         if ($key === 'show_on_network') {
137                                 if ($value)
138                                         PConfig::set($uid,feature,forumlist_widget,$value);
139
140                                 PConfig::delete($uid,$family,$key);
141                         }
142                 }
143         }
144
145         Config::set('system', 'maintenance', 0);
146
147         return UPDATE_SUCCESS;
148 }
149
150 function update_1203() {
151         $r = q("UPDATE `user` SET `account-type` = %d WHERE `page-flags` IN (%d, %d)",
152                 dbesc(ACCOUNT_TYPE_COMMUNITY), dbesc(PAGE_COMMUNITY), dbesc(PAGE_PRVGROUP));
153 }
154
155 function update_1244() {
156         // Sets legacy_password for all legacy hashes
157         DBA::update('user', ['legacy_password' => true], ['SUBSTR(password, 1, 4) != "$2y$"']);
158
159         // All legacy hashes are re-hashed using the new secure hashing function
160         $stmt = DBA::select('user', ['uid', 'password'], ['legacy_password' => true]);
161         while($user = DBA::fetch($stmt)) {
162                 DBA::update('user', ['password' => User::hashPassword($user['password'])], ['uid' => $user['uid']]);
163         }
164
165         // Logged in users are forcibly logged out
166         DBA::delete('session', ['1 = 1']);
167
168         return UPDATE_SUCCESS;
169 }
170
171 function update_1245() {
172         $rino = Config::get('system', 'rino_encrypt');
173
174         if (!$rino) {
175                 return UPDATE_SUCCESS;
176         }
177
178         Config::set('system', 'rino_encrypt', 1);
179
180         return UPDATE_SUCCESS;
181 }
182
183 function update_1247() {
184         // Removing hooks with the old name
185         DBA::e("DELETE FROM `hook`
186 WHERE `hook` LIKE 'plugin_%'");
187
188         // Make sure we install the new renamed ones
189         Addon::reload();
190 }
191
192 function update_1260() {
193         Config::set('system', 'maintenance', 1);
194         Config::set('system', 'maintenance_reason', L10n::t('%s: Updating author-id and owner-id in item and thread table. ', DBM::date().' '.date('e')));
195
196         $items = DBA::p("SELECT `id`, `owner-link`, `owner-name`, `owner-avatar`, `network` FROM `item`
197                 WHERE `owner-id` = 0 AND `owner-link` != ''");
198         while ($item = DBA::fetch($items)) {
199                 $contact = ['url' => $item['owner-link'], 'name' => $item['owner-name'],
200                         'photo' => $item['owner-avatar'], 'network' => $item['network']];
201                 $cid = Contact::getIdForURL($item['owner-link'], 0, false, $contact);
202                 if (empty($cid)) {
203                         continue;
204                 }
205                 Item::update(['owner-id' => $cid], ['id' => $item['id']]);
206         }
207         DBA::close($items);
208
209         DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
210                 SET `thread`.`owner-id` = `item`.`owner-id` WHERE `thread`.`owner-id` = 0");
211
212         $items = DBA::p("SELECT `id`, `author-link`, `author-name`, `author-avatar`, `network` FROM `item`
213                 WHERE `author-id` = 0 AND `author-link` != ''");
214         while ($item = DBA::fetch($items)) {
215                 $contact = ['url' => $item['author-link'], 'name' => $item['author-name'],
216                         'photo' => $item['author-avatar'], 'network' => $item['network']];
217                 $cid = Contact::getIdForURL($item['author-link'], 0, false, $contact);
218                 if (empty($cid)) {
219                         continue;
220                 }
221                 Item::update(['author-id' => $cid], ['id' => $item['id']]);
222         }
223         DBA::close($items);
224
225         DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id`
226                 SET `thread`.`author-id` = `item`.`author-id` WHERE `thread`.`author-id` = 0");
227
228         Config::set('system', 'maintenance', 0);
229         return UPDATE_SUCCESS;
230 }
231
232 function update_1261() {
233         // This fixes the results of an issue in the develop branch of 2018-05.
234         DBA::update('contact', ['blocked' => false, 'pending' => false], ['uid' => 0, 'blocked' => true, 'pending' => true]);
235         return UPDATE_SUCCESS;
236 }
237
238 function update_1278() {
239         Config::set('system', 'maintenance', 1);
240         Config::set('system', 'maintenance_reason', L10n::t('%s: Updating post-type.', DBM::date().' '.date('e')));
241
242         Item::update(['post-type' => Item::PT_PAGE], ['bookmark' => true]);
243         Item::update(['post-type' => Item::PT_PERSONAL_NOTE], ['type' => 'note']);
244
245         Config::set('system', 'maintenance', 0);
246
247         return UPDATE_SUCCESS;
248 }