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