PluginProbe
Zotpress / trunk
Zotpress vtrunk
7.4.4 trunk 1.0 1.1 1.2 1.3 1.4 1.5 1.6 2.0 2.1 2.2 2.3 2.4 2.5 2.5.1 2.5.2 2.6 2.6.1 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1 All 138 releases
zotpress / lib / admin / admin.install.php

admin.install.php in Zotpress trunk, at lib/admin/admin.install.php

260 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 // INSTALL -----------------------------------------------------------------------------------------
6
7 function Zotpress_install( $taskType="install" )
8 {
9 global $wpdb;
10 global $current_user;
11
12 $Zotpress_main_db_version = "5.2";
13 $Zotpress_oauth_db_version = "5.0.5";
14 $Zotpress_zoteroItemImages_db_version = "5.2.6";
15 $Zotpress_cache_version = "7.1.4";
16
17 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
18
19
20 // +----------------------------------+
21 // | Remove old databases and options |
22 // +----------------------------------+
23
24 // CHANGED (7.3): We don't want to delete everything when updating,
25 // so a task type (install or update) check was added.
26
27 if ( $taskType == "install" )
28 {
29 // kfeuerherm: added next two lines 15 November 2019
30 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress;");
31 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_oauth;");
32
33 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroItems;");
34 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroCollections;");
35 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroTags;");
36 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroRelItemColl;");
37 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroRelItemTags;");
38
39 // kfeuerherm: added next two lines 15 November 2019
40 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_cache;");
41 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroItemImages;");
42
43 // kfeuerherm: added next nine lines 15 November 2019
44 delete_option( 'Zotpress_cache_version' );
45 delete_option( 'Zotpress_DefaultCPT' );
46 delete_option( 'Zotpress_DefaultCacheTimer' );
47 delete_option( 'Zotpress_DefaultAccount' );
48 delete_option( 'Zotpress_DefaultEditor' );
49 delete_option( 'Zotpress_DefaultStyle' );
50 delete_option( 'Zotpress_StyleList' );
51 delete_option( 'Zotpress_update_version' );
52 delete_option( 'Zotpress_main_db_version' );
53 delete_option( 'Zotpress_oauth_db_version' );
54
55 delete_option( 'Zotpress_zoteroItems_db_version' );
56 delete_option( 'Zotpress_zoteroCollections_db_version' );
57 delete_option( 'Zotpress_zoteroTags_db_version' );
58 delete_option( 'Zotpress_zoteroRelItemColl_db_version' );
59 delete_option( 'Zotpress_zoteroRelItemTags_db_version' );
60
61 // kfeuerherm: added next three lines 15 November 2019
62 delete_option( 'Zotpress_zoteroItemImages_db_version' );
63 delete_option( 'Zotpress_update_notice_dismissed' );
64 delete_option( 'Zotpress_zoteroItemImages_db_version' );
65
66 // kfeuerherm: next two are in the reset code; not sure needed yet
67 delete_user_meta( $current_user->ID, 'zotpress_5_2_ignore_notice' );
68 delete_user_meta( $current_user->ID, 'zotpress_survey_notice_ignore' );
69
70 } // taskType check
71
72
73 // +-----------------------+
74 // | Zotero accounts table |
75 // +-----------------------+
76
77 // For each table, the basic check is:
78 // - If the table version option doesn't exist, OR
79 // - If the table version is not the same as the update version (vars defined above)
80 // Then add/update the table and add/update the option
81
82 if ( ! get_option("Zotpress_main_db_version")
83 || get_option("Zotpress_main_db_version") != $Zotpress_main_db_version
84 )
85 {
86 $table_name = $wpdb->prefix . "zotpress";
87
88 $structure = "CREATE TABLE $table_name (
89 id INT(9) NOT NULL AUTO_INCREMENT,
90 account_type VARCHAR(10) NOT NULL,
91 api_user_id VARCHAR(10) NOT NULL,
92 public_key VARCHAR(28) default NULL,
93 nickname VARCHAR(200) default NULL,
94 version VARCHAR(10) default '5.1',
95 UNIQUE KEY id (id)
96 );";
97
98 dbDelta($structure);
99
100 update_option("Zotpress_main_db_version", $Zotpress_main_db_version);
101 }
102
103
104 // +-------------+
105 // | OAuth table |
106 // +-------------+
107
108 if ( ! get_option("Zotpress_oauth_db_version")
109 || get_option("Zotpress_oauth_db_version") != $Zotpress_oauth_db_version
110 )
111 {
112 $table_name = $wpdb->prefix . "zotpress_oauth";
113
114 $structure = "CREATE TABLE $table_name (
115 id INT(9) NOT NULL AUTO_INCREMENT,
116 cache LONGTEXT NOT NULL,
117 UNIQUE KEY id (id)
118 );";
119
120 dbDelta($structure);
121
122 update_option("Zotpress_oauth_db_version", $Zotpress_oauth_db_version);
123
124 // Initial populate
125 if ($wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."zotpress_oauth;") == 0)
126 $wpdb->query("INSERT INTO ".$wpdb->prefix."zotpress_oauth (cache) VALUES ('empty')");
127 }
128
129
130 // +--------------+
131 // | Images table |
132 // +--------------+
133
134 if ( ! get_option("Zotpress_zoteroItemImages_db_version")
135 || get_option("Zotpress_zoteroItemImages_db_version") != $Zotpress_zoteroItemImages_db_version
136 )
137 {
138 $table_name = $wpdb->prefix . "zotpress_zoteroItemImages";
139
140 $structure = "CREATE TABLE $table_name (
141 id INT(9) AUTO_INCREMENT,
142 api_user_id VARCHAR(50),
143 item_key VARCHAR(50),
144 image TEXT,
145 UNIQUE KEY id (id),
146 PRIMARY KEY (api_user_id, item_key)
147 );";
148
149 dbDelta( $structure );
150
151 update_option( "Zotpress_zoteroItemImages_db_version", $Zotpress_zoteroItemImages_db_version );
152 }
153
154
155 // +-------------+
156 // | Cache table |
157 // +-------------+
158
159 if ( ! get_option("Zotpress_cache_version")
160 || get_option("Zotpress_cache_version") != $Zotpress_cache_version
161 )
162 {
163 $structure = "CREATE TABLE ".$wpdb->prefix."zotpress_cache (
164 id INT(9) NOT NULL AUTO_INCREMENT,
165 request_id VARCHAR(200) NOT NULL,
166 api_user_id VARCHAR(50),
167 json BLOB,
168 tags BLOB,
169 headers MEDIUMTEXT,
170 libver INT(9),
171 retrieved VARCHAR(100),
172 UNIQUE KEY id (id),
173 PRIMARY KEY (request_id)
174 );";
175
176 dbDelta($structure);
177
178 update_option("Zotpress_cache_version", $Zotpress_cache_version);
179 }
180
181 }
182 register_activation_hook( ZOTPRESS_PLUGIN_FILE, 'Zotpress_install' );
183
184 // INSTALL -----------------------------------------------------------------------------------------
185
186
187 // UNINSTALL --------------------------------------------------------------------------------------
188
189 function Zotpress_uninstall()
190 {
191 global $wpdb;
192 global $current_user;
193
194 // Drop all tables -- originally not including accounts/main, but not sure why
195 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress;");
196 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_oauth;");
197 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroItems;");
198 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroItemImages;");
199 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroCollections;");
200 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroTags;");
201 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroRelItemColl;");
202 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_zoteroRelItemTags;");
203 $wpdb->query("DROP TABLE IF EXISTS ".$wpdb->prefix."zotpress_cache;");
204
205 // Delete options
206 delete_option( 'Zotpress_DefaultCPT' );
207 delete_option( 'Zotpress_DefaultCacheTimer' );
208 delete_option( 'Zotpress_DefaultAccount' );
209 delete_option( 'Zotpress_DefaultStyle' );
210 delete_option( 'Zotpress_StyleList' );
211 delete_option( 'Zotpress_update_version' );
212 delete_option( 'Zotpress_main_db_version' );
213 delete_option( 'Zotpress_oauth_db_version' );
214 delete_option( 'Zotpress_zoteroItems_db_version' );
215 delete_option( 'Zotpress_zoteroCollections_db_version' );
216 delete_option( 'Zotpress_zoteroTags_db_version' );
217 delete_option( 'Zotpress_zoteroRelItemColl_db_version' );
218 delete_option( 'Zotpress_zoteroRelItemTags_db_version' );
219 delete_option( 'Zotpress_zoteroItemImages_db_version' );
220 delete_option( 'Zotpress_cache_version' );
221 delete_option( 'Zotpress_update_notice_dismissed' );
222
223 // Delete user meta
224 delete_user_meta( $current_user->ID, 'zotpress_5_2_ignore_notice' );
225 delete_user_meta( $current_user->ID, 'zotpress_survey_notice_ignore' );
226 }
227
228 register_uninstall_hook( ZOTPRESS_PLUGIN_FILE, 'Zotpress_uninstall' );
229
230 // UNINSTALL ---------------------------------------------------------------------------------------
231
232
233 // UPDATE ------------------------------------------------------------------------------------------
234
235
236 /**
237 *
238 * If update check option doesn't exist, OR
239 * If it exists but it's not the same version as the database update version
240 *
241 * Then, run the install, which installs or updates the databases
242 *
243 **/
244 if ( ! get_option( "Zotpress_update_version" )
245 || get_option("Zotpress_update_version") != $GLOBALS['Zotpress_update_db_by_version'] )
246 {
247 Zotpress_install("update");
248
249 // Add or update version number
250 if ( !get_option( "Zotpress_update_version" ) )
251 add_option( "Zotpress_update_version", $GLOBALS['Zotpress_update_db_by_version'], "", "no" );
252 else
253 update_option( "Zotpress_update_version", $GLOBALS['Zotpress_update_db_by_version'] );
254 }
255
256 // UPDATE ------------------------------------------------------------------------------------------
257
258
259 ?>
260