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