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