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