Completed
Pull Request — develop (#747)
by
unknown
03:34
created
src/modules/core/wordlift_core_install.php 2 patches
Indentation   +242 added lines, -242 removed lines patch added patch discarded remove patch
@@ -12,93 +12,93 @@  discard block
 block discarded – undo
12 12
  */
13 13
 function wl_core_install_entity_type_data() {
14 14
 
15
-	Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
16
-
17
-	// Set the taxonomy data.
18
-	// Note: parent types must be defined before child types.
19
-	$terms = array(
20
-		'thing'         => array(
21
-			'label'       => 'Thing',
22
-			'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
23
-		),
24
-		'creative-work' => array(
25
-			'label'       => 'CreativeWork',
26
-			'description' => 'A creative work (or a Music Album).',
27
-		),
28
-		'event'         => array(
29
-			'label'       => 'Event',
30
-			'description' => 'An event.',
31
-		),
32
-		'organization'  => array(
33
-			'label'       => 'Organization',
34
-			'description' => 'An organization, including a government or a newspaper.',
35
-		),
36
-		'person'        => array(
37
-			'label'       => 'Person',
38
-			'description' => 'A person (or a music artist).',
39
-		),
40
-		'place'         => array(
41
-			'label'       => 'Place',
42
-			'description' => 'A place.',
43
-		),
44
-		'localbusiness' => array(
45
-			'label'       => 'LocalBusiness',
46
-			'description' => 'A local business.',
47
-		),
48
-	);
49
-
50
-	foreach ( $terms as $slug => $term ) {
51
-
52
-		// Create the term if it does not exist, then get its ID
53
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
54
-
55
-		if ( 0 == $term_id || is_null( $term_id ) ) {
56
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
57
-		} else {
58
-			$term_id = $term_id['term_id'];
59
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
60
-		}
61
-
62
-		// Check for errors.
63
-		if ( is_wp_error( $result ) ) {
64
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
65
-			continue;
66
-		}
67
-
68
-		// Check if 'parent' corresponds to an actual term and get its ID.
69
-		if ( ! isset( $term['parents'] ) ) {
70
-			$term['parents'] = array();
71
-		}
72
-
73
-		$parent_ids = array();
74
-		foreach ( $term['parents'] as $parent_slug ) {
75
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77
-		}
78
-
79
-		// Define a parent in the WP taxonomy style (not important for WL)
80
-		if ( empty( $parent_ids ) ) {
81
-			// No parent
82
-			$parent_id = 0;
83
-		} else {
84
-			// Get first parent
85
-			$parent_id = $parent_ids[0];
86
-		}
87
-
88
-		// Update term with description, slug and parent
89
-		$term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90
-			'name'        => $term['label'],
91
-			'slug'        => $slug,
92
-			'description' => $term['description'],
93
-			// We give to WP taxonomy just one parent. TODO: see if can give more than one
94
-			'parent'      => $parent_id,
95
-		) );
96
-
97
-		Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
98
-
99
-	}
100
-
101
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
15
+    Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
16
+
17
+    // Set the taxonomy data.
18
+    // Note: parent types must be defined before child types.
19
+    $terms = array(
20
+        'thing'         => array(
21
+            'label'       => 'Thing',
22
+            'description' => 'A generic thing (something that doesn\'t fit in the previous definitions.',
23
+        ),
24
+        'creative-work' => array(
25
+            'label'       => 'CreativeWork',
26
+            'description' => 'A creative work (or a Music Album).',
27
+        ),
28
+        'event'         => array(
29
+            'label'       => 'Event',
30
+            'description' => 'An event.',
31
+        ),
32
+        'organization'  => array(
33
+            'label'       => 'Organization',
34
+            'description' => 'An organization, including a government or a newspaper.',
35
+        ),
36
+        'person'        => array(
37
+            'label'       => 'Person',
38
+            'description' => 'A person (or a music artist).',
39
+        ),
40
+        'place'         => array(
41
+            'label'       => 'Place',
42
+            'description' => 'A place.',
43
+        ),
44
+        'localbusiness' => array(
45
+            'label'       => 'LocalBusiness',
46
+            'description' => 'A local business.',
47
+        ),
48
+    );
49
+
50
+    foreach ( $terms as $slug => $term ) {
51
+
52
+        // Create the term if it does not exist, then get its ID
53
+        $term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
54
+
55
+        if ( 0 == $term_id || is_null( $term_id ) ) {
56
+            $result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
57
+        } else {
58
+            $term_id = $term_id['term_id'];
59
+            $result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
60
+        }
61
+
62
+        // Check for errors.
63
+        if ( is_wp_error( $result ) ) {
64
+            wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
65
+            continue;
66
+        }
67
+
68
+        // Check if 'parent' corresponds to an actual term and get its ID.
69
+        if ( ! isset( $term['parents'] ) ) {
70
+            $term['parents'] = array();
71
+        }
72
+
73
+        $parent_ids = array();
74
+        foreach ( $term['parents'] as $parent_slug ) {
75
+            $parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
+            $parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77
+        }
78
+
79
+        // Define a parent in the WP taxonomy style (not important for WL)
80
+        if ( empty( $parent_ids ) ) {
81
+            // No parent
82
+            $parent_id = 0;
83
+        } else {
84
+            // Get first parent
85
+            $parent_id = $parent_ids[0];
86
+        }
87
+
88
+        // Update term with description, slug and parent
89
+        $term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90
+            'name'        => $term['label'],
91
+            'slug'        => $slug,
92
+            'description' => $term['description'],
93
+            // We give to WP taxonomy just one parent. TODO: see if can give more than one
94
+            'parent'      => $parent_id,
95
+        ) );
96
+
97
+        Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
98
+
99
+    }
100
+
101
+    Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
102 102
 
103 103
 }
104 104
 
@@ -107,16 +107,16 @@  discard block
 block discarded – undo
107 107
  */
108 108
 function wl_core_install_create_relation_instance_table() {
109 109
 
110
-	global $wpdb;
111
-	// global $wl_db_version;
112
-	$installed_version = get_option( 'wl_db_version' );
110
+    global $wpdb;
111
+    // global $wl_db_version;
112
+    $installed_version = get_option( 'wl_db_version' );
113 113
 
114
-	if ( WL_DB_VERSION != $installed_version ) {
115
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
116
-		$charset_collate = $wpdb->get_charset_collate();
114
+    if ( WL_DB_VERSION != $installed_version ) {
115
+        $table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
116
+        $charset_collate = $wpdb->get_charset_collate();
117 117
 
118
-		// Sql statement for the relation instances custom table
119
-		$sql = <<<EOF
118
+        // Sql statement for the relation instances custom table
119
+        $sql = <<<EOF
120 120
 			CREATE TABLE $table_name (
121 121
   				id int(11) NOT NULL AUTO_INCREMENT,
122 122
   				subject_id int(11) NOT NULL,
@@ -128,14 +128,14 @@  discard block
 block discarded – undo
128 128
 			) $charset_collate;
129 129
 EOF;
130 130
 
131
-		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
-		$results = dbDelta( $sql );
131
+        // @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
+        $results = dbDelta( $sql );
134 134
 
135
-		wl_write_log( $results );
135
+        wl_write_log( $results );
136 136
 
137
-		update_option( 'wl_db_version', WL_DB_VERSION );
138
-	}
137
+        update_option( 'wl_db_version', WL_DB_VERSION );
138
+    }
139 139
 }
140 140
 
141 141
 /**
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function wl_core_upgrade_db_to_1_0() {
148 148
 
149
-	if ( ! get_option( 'wl_db_version' ) ) {
150
-		wl_core_install_create_relation_instance_table();
151
-	}
149
+    if ( ! get_option( 'wl_db_version' ) ) {
150
+        wl_core_install_create_relation_instance_table();
151
+    }
152 152
 
153 153
 }
154 154
 
@@ -161,31 +161,31 @@  discard block
 block discarded – undo
161 161
  */
162 162
 function wl_core_upgrade_db_1_0_to_3_10() {
163 163
 
164
-	// If the DB version is less than 3.10, than flatten the txonomy.
165
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
164
+    // If the DB version is less than 3.10, than flatten the txonomy.
165
+    if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
166 166
 
167
-		$term_slugs = array(
168
-			'thing',
169
-			'creative-work',
170
-			'event',
171
-			'organization',
172
-			'person',
173
-			'place',
174
-			'localbusiness',
175
-		);
167
+        $term_slugs = array(
168
+            'thing',
169
+            'creative-work',
170
+            'event',
171
+            'organization',
172
+            'person',
173
+            'place',
174
+            'localbusiness',
175
+        );
176 176
 
177
-		foreach ( $term_slugs as $slug ) {
177
+        foreach ( $term_slugs as $slug ) {
178 178
 
179
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
179
+            $term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
180 180
 
181
-			// Set the term's parent to 0.
182
-			if ( $term ) {
183
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184
-					'parent' => 0,
185
-				) );
186
-			}
187
-		}
188
-	}
181
+            // Set the term's parent to 0.
182
+            if ( $term ) {
183
+                wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184
+                    'parent' => 0,
185
+                ) );
186
+            }
187
+        }
188
+    }
189 189
 
190 190
 }
191 191
 
@@ -198,14 +198,14 @@  discard block
 block discarded – undo
198 198
  * @since 3.12.0
199 199
  */
200 200
 function wl_core_upgrade_db_3_10_3_12() {
201
-	/*
201
+    /*
202 202
 	 * As this upgrade functionality runs on the init hook, and the AMP plugin
203 203
 	 * initialization does the same, avoid possible race conditions by
204 204
 	 * deferring the actual flush to a later hook.
205 205
 	 */
206
-	add_action( 'wp_loaded', function () {
207
-		flush_rewrite_rules();
208
-	} );
206
+    add_action( 'wp_loaded', function () {
207
+        flush_rewrite_rules();
208
+    } );
209 209
 }
210 210
 
211 211
 /**
@@ -216,44 +216,44 @@  discard block
 block discarded – undo
216 216
  * @since 3.14.0
217 217
  */
218 218
 function wl_core_upgrade_db_3_12_3_14() {
219
-	$result = wp_insert_term(
220
-		'Recipe',
221
-		Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
222
-		array(
223
-			'slug'        => 'recipe',
224
-			'description' => 'A Recipe.',
225
-		)
226
-	);
227
-
228
-	// Assign capabilities to manipulate entities to admins.
229
-	$admins = get_role( 'administrator' );
230
-
231
-	$admins->add_cap( 'edit_wordlift_entity' );
232
-	$admins->add_cap( 'read_wordlift_entity' );
233
-	$admins->add_cap( 'edit_wordlift_entities' );
234
-	$admins->add_cap( 'edit_others_wordlift_entities' );
235
-	$admins->add_cap( 'publish_wordlift_entities' );
236
-	$admins->add_cap( 'read_private_wordlift_entities' );
237
-	$admins->add_cap( 'delete_wordlift_entity' );
238
-	$admins->add_cap( 'delete_wordlift_entities' );
239
-	$admins->add_cap( 'delete_others_wordlift_entities' );
240
-	$admins->add_cap( 'delete_published_wordlift_entities' );
241
-	$admins->add_cap( 'delete_private_wordlift_entities' );
242
-
243
-	// Assign capabilities to manipulate entities to editors.
244
-	$editors = get_role( 'editor' );
245
-
246
-	$editors->add_cap( 'edit_wordlift_entity' );
247
-	$editors->add_cap( 'read_wordlift_entity' );
248
-	$editors->add_cap( 'edit_wordlift_entities' );
249
-	$editors->add_cap( 'edit_others_wordlift_entities' );
250
-	$editors->add_cap( 'publish_wordlift_entities' );
251
-	$editors->add_cap( 'read_private_wordlift_entities' );
252
-	$editors->add_cap( 'delete_wordlift_entity' );
253
-	$editors->add_cap( 'delete_wordlift_entities' );
254
-	$editors->add_cap( 'delete_others_wordlift_entities' );
255
-	$editors->add_cap( 'delete_published_wordlift_entities' );
256
-	$editors->add_cap( 'delete_private_wordlift_entities' );
219
+    $result = wp_insert_term(
220
+        'Recipe',
221
+        Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
222
+        array(
223
+            'slug'        => 'recipe',
224
+            'description' => 'A Recipe.',
225
+        )
226
+    );
227
+
228
+    // Assign capabilities to manipulate entities to admins.
229
+    $admins = get_role( 'administrator' );
230
+
231
+    $admins->add_cap( 'edit_wordlift_entity' );
232
+    $admins->add_cap( 'read_wordlift_entity' );
233
+    $admins->add_cap( 'edit_wordlift_entities' );
234
+    $admins->add_cap( 'edit_others_wordlift_entities' );
235
+    $admins->add_cap( 'publish_wordlift_entities' );
236
+    $admins->add_cap( 'read_private_wordlift_entities' );
237
+    $admins->add_cap( 'delete_wordlift_entity' );
238
+    $admins->add_cap( 'delete_wordlift_entities' );
239
+    $admins->add_cap( 'delete_others_wordlift_entities' );
240
+    $admins->add_cap( 'delete_published_wordlift_entities' );
241
+    $admins->add_cap( 'delete_private_wordlift_entities' );
242
+
243
+    // Assign capabilities to manipulate entities to editors.
244
+    $editors = get_role( 'editor' );
245
+
246
+    $editors->add_cap( 'edit_wordlift_entity' );
247
+    $editors->add_cap( 'read_wordlift_entity' );
248
+    $editors->add_cap( 'edit_wordlift_entities' );
249
+    $editors->add_cap( 'edit_others_wordlift_entities' );
250
+    $editors->add_cap( 'publish_wordlift_entities' );
251
+    $editors->add_cap( 'read_private_wordlift_entities' );
252
+    $editors->add_cap( 'delete_wordlift_entity' );
253
+    $editors->add_cap( 'delete_wordlift_entities' );
254
+    $editors->add_cap( 'delete_others_wordlift_entities' );
255
+    $editors->add_cap( 'delete_published_wordlift_entities' );
256
+    $editors->add_cap( 'delete_private_wordlift_entities' );
257 257
 }
258 258
 
259 259
 /**
@@ -265,100 +265,100 @@  discard block
 block discarded – undo
265 265
  */
266 266
 function wl_core_upgrade_db_3_14_3_15() {
267 267
 
268
-	if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
269
-		$article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
270
-
271
-		if ( ! $article ) {
272
-			wp_insert_term(
273
-				'Article',
274
-				Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
275
-				array(
276
-					'slug'        => 'article',
277
-					'description' => 'An Article.',
278
-				)
279
-			);
280
-		}
281
-
282
-		// The following is disabled because on large installations it may slow the
283
-		// web site.
284
-		//
285
-		// See https://github.com/insideout10/wordlift-plugin/issues/663.
286
-		//
287
-		//		// An sql that will assign the article term to all posts and pages
288
-		//		$wpdb->query( $wpdb->prepare(
289
-		//			"
290
-		//			INSERT INTO $wpdb->term_relationships( object_id, term_taxonomy_id )
291
-		//			SELECT id, %d
292
-		//			FROM $wpdb->posts
293
-		//			WHERE post_type IN ( 'post', 'page' )
294
-		//				AND id NOT IN
295
-		//			(
296
-		//				SELECT DISTINCT tr.object_id
297
-		//				FROM $wpdb->term_relationships tr
298
-		//				INNER JOIN $wpdb->term_taxonomy tt
299
-		//					ON tr.term_taxonomy_id = tt.term_taxonomy_id
300
-		//						AND tt.taxonomy = 'wl_entity_type'
301
-		//			)
302
-		//			",
303
-		//			$article_id
304
-		//		) );
305
-	}
268
+    if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
269
+        $article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
270
+
271
+        if ( ! $article ) {
272
+            wp_insert_term(
273
+                'Article',
274
+                Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
275
+                array(
276
+                    'slug'        => 'article',
277
+                    'description' => 'An Article.',
278
+                )
279
+            );
280
+        }
281
+
282
+        // The following is disabled because on large installations it may slow the
283
+        // web site.
284
+        //
285
+        // See https://github.com/insideout10/wordlift-plugin/issues/663.
286
+        //
287
+        //		// An sql that will assign the article term to all posts and pages
288
+        //		$wpdb->query( $wpdb->prepare(
289
+        //			"
290
+        //			INSERT INTO $wpdb->term_relationships( object_id, term_taxonomy_id )
291
+        //			SELECT id, %d
292
+        //			FROM $wpdb->posts
293
+        //			WHERE post_type IN ( 'post', 'page' )
294
+        //				AND id NOT IN
295
+        //			(
296
+        //				SELECT DISTINCT tr.object_id
297
+        //				FROM $wpdb->term_relationships tr
298
+        //				INNER JOIN $wpdb->term_taxonomy tt
299
+        //					ON tr.term_taxonomy_id = tt.term_taxonomy_id
300
+        //						AND tt.taxonomy = 'wl_entity_type'
301
+        //			)
302
+        //			",
303
+        //			$article_id
304
+        //		) );
305
+    }
306 306
 
307 307
 }
308 308
 
309 309
 // Check db status on automated plugins updates
310 310
 function wl_core_update_db_check() {
311 311
 
312
-	$log = Wordlift_Log_Service::get_logger( 'wl_core_update_db_check' );
312
+    $log = Wordlift_Log_Service::get_logger( 'wl_core_update_db_check' );
313 313
 
314
-	// Ensure the custom type and the taxonomy are registered.
315
-	Wordlift_Entity_Post_Type_Service::get_instance()->register();
314
+    // Ensure the custom type and the taxonomy are registered.
315
+    Wordlift_Entity_Post_Type_Service::get_instance()->register();
316 316
 
317
-	// Commenting this out because this function is already called by init
318
-	// with priority 0 at wordlift_entity_type.php.
319
-	wl_entity_type_taxonomy_register();
317
+    // Commenting this out because this function is already called by init
318
+    // with priority 0 at wordlift_entity_type.php.
319
+    wl_entity_type_taxonomy_register();
320 320
 
321
-	// Ensure the custom taxonomy for dbpedia topics is registered
322
-	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
321
+    // Ensure the custom taxonomy for dbpedia topics is registered
322
+    Wordlift_Topic_Taxonomy_Service::get_instance()->init();
323 323
 
324
-	if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
325
-		wl_core_install_entity_type_data();
326
-		wl_core_upgrade_db_to_1_0();
327
-		wl_core_upgrade_db_1_0_to_3_10();
328
-		wl_core_upgrade_db_3_10_3_12();
329
-		wl_core_upgrade_db_3_12_3_14();
330
-		wl_core_upgrade_db_3_14_3_15();
331
-		update_option( 'wl_db_version', WL_DB_VERSION );
332
-	}
324
+    if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
325
+        wl_core_install_entity_type_data();
326
+        wl_core_upgrade_db_to_1_0();
327
+        wl_core_upgrade_db_1_0_to_3_10();
328
+        wl_core_upgrade_db_3_10_3_12();
329
+        wl_core_upgrade_db_3_12_3_14();
330
+        wl_core_upgrade_db_3_14_3_15();
331
+        update_option( 'wl_db_version', WL_DB_VERSION );
332
+    }
333 333
 
334
-	// Update to WL install level 1.
335
-	if ( 1 > intval( get_option( 'wl_install_version' ) ) ) {
334
+    // Update to WL install level 1.
335
+    if ( 1 > intval( get_option( 'wl_install_version' ) ) ) {
336 336
 
337
-		$log->trace( 'Installing version 1...' );
337
+        $log->trace( 'Installing version 1...' );
338 338
 
339
-		// Get the configuration service and load the key.
340
-		$configuration_service = Wordlift_Configuration_Service::get_instance();
341
-		$key                   = $configuration_service->get_key();
339
+        // Get the configuration service and load the key.
340
+        $configuration_service = Wordlift_Configuration_Service::get_instance();
341
+        $key                   = $configuration_service->get_key();
342 342
 
343
-		// If the key is not empty then set the dataset URI while sending
344
-		// the site URL.
345
-		if ( ! empty( $key ) ) {
346
-			$log->info( 'Updating the remote dataset URI...' );
343
+        // If the key is not empty then set the dataset URI while sending
344
+        // the site URL.
345
+        if ( ! empty( $key ) ) {
346
+            $log->info( 'Updating the remote dataset URI...' );
347 347
 
348
-			$configuration_service->get_remote_dataset_uri( $key );
349
-		}
348
+            $configuration_service->get_remote_dataset_uri( $key );
349
+        }
350 350
 
351
-		// Check if the dataset key has been stored.
352
-		$dataset_uri = $configuration_service->get_dataset_uri();
351
+        // Check if the dataset key has been stored.
352
+        $dataset_uri = $configuration_service->get_dataset_uri();
353 353
 
354
-		// If the dataset URI is empty, do not set the install version.
355
-		if ( ! empty( $dataset_uri ) ) {
356
-			update_option( 'wl_install_version', 1 );
354
+        // If the dataset URI is empty, do not set the install version.
355
+        if ( ! empty( $dataset_uri ) ) {
356
+            update_option( 'wl_install_version', 1 );
357 357
 
358
-			$log->info( 'Version 1 installed.' );
359
-		}
358
+            $log->info( 'Version 1 installed.' );
359
+        }
360 360
 
361
-	}
361
+    }
362 362
 
363 363
 }
364 364
 
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  */
13 13
 function wl_core_install_entity_type_data() {
14 14
 
15
-	Wordlift_Log_Service::get_instance()->debug( 'Installing Entity Type data...' );
15
+	Wordlift_Log_Service::get_instance()->debug('Installing Entity Type data...');
16 16
 
17 17
 	// Set the taxonomy data.
18 18
 	// Note: parent types must be defined before child types.
@@ -47,37 +47,37 @@  discard block
 block discarded – undo
47 47
 		),
48 48
 	);
49 49
 
50
-	foreach ( $terms as $slug => $term ) {
50
+	foreach ($terms as $slug => $term) {
51 51
 
52 52
 		// Create the term if it does not exist, then get its ID
53
-		$term_id = term_exists( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
53
+		$term_id = term_exists($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
54 54
 
55
-		if ( 0 == $term_id || is_null( $term_id ) ) {
56
-			$result = wp_insert_term( $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
55
+		if (0 == $term_id || is_null($term_id)) {
56
+			$result = wp_insert_term($slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
57 57
 		} else {
58 58
 			$term_id = $term_id['term_id'];
59
-			$result  = get_term( $term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A );
59
+			$result  = get_term($term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, ARRAY_A);
60 60
 		}
61 61
 
62 62
 		// Check for errors.
63
-		if ( is_wp_error( $result ) ) {
64
-			wl_write_log( 'wl_install_entity_type_data [ ' . $result->get_error_message() . ' ]' );
63
+		if (is_wp_error($result)) {
64
+			wl_write_log('wl_install_entity_type_data [ '.$result->get_error_message().' ]');
65 65
 			continue;
66 66
 		}
67 67
 
68 68
 		// Check if 'parent' corresponds to an actual term and get its ID.
69
-		if ( ! isset( $term['parents'] ) ) {
69
+		if ( ! isset($term['parents'])) {
70 70
 			$term['parents'] = array();
71 71
 		}
72 72
 
73 73
 		$parent_ids = array();
74
-		foreach ( $term['parents'] as $parent_slug ) {
75
-			$parent_id    = get_term_by( 'slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
76
-			$parent_ids[] = intval( $parent_id->term_id );  // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
74
+		foreach ($term['parents'] as $parent_slug) {
75
+			$parent_id    = get_term_by('slug', $parent_slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
76
+			$parent_ids[] = intval($parent_id->term_id); // Note: int casting is suggested by Codex: http://codex.wordpress.org/Function_Reference/get_term_by
77 77
 		}
78 78
 
79 79
 		// Define a parent in the WP taxonomy style (not important for WL)
80
-		if ( empty( $parent_ids ) ) {
80
+		if (empty($parent_ids)) {
81 81
 			// No parent
82 82
 			$parent_id = 0;
83 83
 		} else {
@@ -86,19 +86,19 @@  discard block
 block discarded – undo
86 86
 		}
87 87
 
88 88
 		// Update term with description, slug and parent
89
-		$term = wp_update_term( $result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
89
+		$term = wp_update_term($result['term_id'], Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
90 90
 			'name'        => $term['label'],
91 91
 			'slug'        => $slug,
92 92
 			'description' => $term['description'],
93 93
 			// We give to WP taxonomy just one parent. TODO: see if can give more than one
94 94
 			'parent'      => $parent_id,
95
-		) );
95
+		));
96 96
 
97
-		Wordlift_Log_Service::get_instance()->trace( "Entity Type $slug installed with ID {$term['term_id']}." );
97
+		Wordlift_Log_Service::get_instance()->trace("Entity Type $slug installed with ID {$term['term_id']}.");
98 98
 
99 99
 	}
100 100
 
101
-	Wordlift_Log_Service::get_instance()->debug( 'Entity Type data installed.' );
101
+	Wordlift_Log_Service::get_instance()->debug('Entity Type data installed.');
102 102
 
103 103
 }
104 104
 
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 
110 110
 	global $wpdb;
111 111
 	// global $wl_db_version;
112
-	$installed_version = get_option( 'wl_db_version' );
112
+	$installed_version = get_option('wl_db_version');
113 113
 
114
-	if ( WL_DB_VERSION != $installed_version ) {
115
-		$table_name      = $wpdb->prefix . WL_DB_RELATION_INSTANCES_TABLE_NAME;
114
+	if (WL_DB_VERSION != $installed_version) {
115
+		$table_name      = $wpdb->prefix.WL_DB_RELATION_INSTANCES_TABLE_NAME;
116 116
 		$charset_collate = $wpdb->get_charset_collate();
117 117
 
118 118
 		// Sql statement for the relation instances custom table
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
 EOF;
130 130
 
131 131
 		// @see: https://codex.wordpress.org/Creating_Tables_with_Plugins
132
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
133
-		$results = dbDelta( $sql );
132
+		require_once(ABSPATH.'wp-admin/includes/upgrade.php');
133
+		$results = dbDelta($sql);
134 134
 
135
-		wl_write_log( $results );
135
+		wl_write_log($results);
136 136
 
137
-		update_option( 'wl_db_version', WL_DB_VERSION );
137
+		update_option('wl_db_version', WL_DB_VERSION);
138 138
 	}
139 139
 }
140 140
 
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function wl_core_upgrade_db_to_1_0() {
148 148
 
149
-	if ( ! get_option( 'wl_db_version' ) ) {
149
+	if ( ! get_option('wl_db_version')) {
150 150
 		wl_core_install_create_relation_instance_table();
151 151
 	}
152 152
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 function wl_core_upgrade_db_1_0_to_3_10() {
163 163
 
164 164
 	// If the DB version is less than 3.10, than flatten the txonomy.
165
-	if ( version_compare( get_option( 'wl_db_version' ), '3.9', '<=' ) ) {
165
+	if (version_compare(get_option('wl_db_version'), '3.9', '<=')) {
166 166
 
167 167
 		$term_slugs = array(
168 168
 			'thing',
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
 			'localbusiness',
175 175
 		);
176 176
 
177
-		foreach ( $term_slugs as $slug ) {
177
+		foreach ($term_slugs as $slug) {
178 178
 
179
-			$term = get_term_by( 'slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
179
+			$term = get_term_by('slug', $slug, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
180 180
 
181 181
 			// Set the term's parent to 0.
182
-			if ( $term ) {
183
-				wp_update_term( $term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
182
+			if ($term) {
183
+				wp_update_term($term->term_id, Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME, array(
184 184
 					'parent' => 0,
185
-				) );
185
+				));
186 186
 			}
187 187
 		}
188 188
 	}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 	 * initialization does the same, avoid possible race conditions by
204 204
 	 * deferring the actual flush to a later hook.
205 205
 	 */
206
-	add_action( 'wp_loaded', function () {
206
+	add_action('wp_loaded', function() {
207 207
 		flush_rewrite_rules();
208 208
 	} );
209 209
 }
@@ -226,34 +226,34 @@  discard block
 block discarded – undo
226 226
 	);
227 227
 
228 228
 	// Assign capabilities to manipulate entities to admins.
229
-	$admins = get_role( 'administrator' );
230
-
231
-	$admins->add_cap( 'edit_wordlift_entity' );
232
-	$admins->add_cap( 'read_wordlift_entity' );
233
-	$admins->add_cap( 'edit_wordlift_entities' );
234
-	$admins->add_cap( 'edit_others_wordlift_entities' );
235
-	$admins->add_cap( 'publish_wordlift_entities' );
236
-	$admins->add_cap( 'read_private_wordlift_entities' );
237
-	$admins->add_cap( 'delete_wordlift_entity' );
238
-	$admins->add_cap( 'delete_wordlift_entities' );
239
-	$admins->add_cap( 'delete_others_wordlift_entities' );
240
-	$admins->add_cap( 'delete_published_wordlift_entities' );
241
-	$admins->add_cap( 'delete_private_wordlift_entities' );
229
+	$admins = get_role('administrator');
230
+
231
+	$admins->add_cap('edit_wordlift_entity');
232
+	$admins->add_cap('read_wordlift_entity');
233
+	$admins->add_cap('edit_wordlift_entities');
234
+	$admins->add_cap('edit_others_wordlift_entities');
235
+	$admins->add_cap('publish_wordlift_entities');
236
+	$admins->add_cap('read_private_wordlift_entities');
237
+	$admins->add_cap('delete_wordlift_entity');
238
+	$admins->add_cap('delete_wordlift_entities');
239
+	$admins->add_cap('delete_others_wordlift_entities');
240
+	$admins->add_cap('delete_published_wordlift_entities');
241
+	$admins->add_cap('delete_private_wordlift_entities');
242 242
 
243 243
 	// Assign capabilities to manipulate entities to editors.
244
-	$editors = get_role( 'editor' );
245
-
246
-	$editors->add_cap( 'edit_wordlift_entity' );
247
-	$editors->add_cap( 'read_wordlift_entity' );
248
-	$editors->add_cap( 'edit_wordlift_entities' );
249
-	$editors->add_cap( 'edit_others_wordlift_entities' );
250
-	$editors->add_cap( 'publish_wordlift_entities' );
251
-	$editors->add_cap( 'read_private_wordlift_entities' );
252
-	$editors->add_cap( 'delete_wordlift_entity' );
253
-	$editors->add_cap( 'delete_wordlift_entities' );
254
-	$editors->add_cap( 'delete_others_wordlift_entities' );
255
-	$editors->add_cap( 'delete_published_wordlift_entities' );
256
-	$editors->add_cap( 'delete_private_wordlift_entities' );
244
+	$editors = get_role('editor');
245
+
246
+	$editors->add_cap('edit_wordlift_entity');
247
+	$editors->add_cap('read_wordlift_entity');
248
+	$editors->add_cap('edit_wordlift_entities');
249
+	$editors->add_cap('edit_others_wordlift_entities');
250
+	$editors->add_cap('publish_wordlift_entities');
251
+	$editors->add_cap('read_private_wordlift_entities');
252
+	$editors->add_cap('delete_wordlift_entity');
253
+	$editors->add_cap('delete_wordlift_entities');
254
+	$editors->add_cap('delete_others_wordlift_entities');
255
+	$editors->add_cap('delete_published_wordlift_entities');
256
+	$editors->add_cap('delete_private_wordlift_entities');
257 257
 }
258 258
 
259 259
 /**
@@ -265,10 +265,10 @@  discard block
 block discarded – undo
265 265
  */
266 266
 function wl_core_upgrade_db_3_14_3_15() {
267 267
 
268
-	if ( version_compare( get_option( 'wl_db_version' ), '3.15', '<=' ) ) {
269
-		$article = get_term_by( 'slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME );
268
+	if (version_compare(get_option('wl_db_version'), '3.15', '<=')) {
269
+		$article = get_term_by('slug', 'article', Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME);
270 270
 
271
-		if ( ! $article ) {
271
+		if ( ! $article) {
272 272
 			wp_insert_term(
273 273
 				'Article',
274 274
 				Wordlift_Entity_Types_Taxonomy_Service::TAXONOMY_NAME,
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 // Check db status on automated plugins updates
310 310
 function wl_core_update_db_check() {
311 311
 
312
-	$log = Wordlift_Log_Service::get_logger( 'wl_core_update_db_check' );
312
+	$log = Wordlift_Log_Service::get_logger('wl_core_update_db_check');
313 313
 
314 314
 	// Ensure the custom type and the taxonomy are registered.
315 315
 	Wordlift_Entity_Post_Type_Service::get_instance()->register();
@@ -321,20 +321,20 @@  discard block
 block discarded – undo
321 321
 	// Ensure the custom taxonomy for dbpedia topics is registered
322 322
 	Wordlift_Topic_Taxonomy_Service::get_instance()->init();
323 323
 
324
-	if ( get_option( 'wl_db_version' ) !== WL_DB_VERSION ) {
324
+	if (get_option('wl_db_version') !== WL_DB_VERSION) {
325 325
 		wl_core_install_entity_type_data();
326 326
 		wl_core_upgrade_db_to_1_0();
327 327
 		wl_core_upgrade_db_1_0_to_3_10();
328 328
 		wl_core_upgrade_db_3_10_3_12();
329 329
 		wl_core_upgrade_db_3_12_3_14();
330 330
 		wl_core_upgrade_db_3_14_3_15();
331
-		update_option( 'wl_db_version', WL_DB_VERSION );
331
+		update_option('wl_db_version', WL_DB_VERSION);
332 332
 	}
333 333
 
334 334
 	// Update to WL install level 1.
335
-	if ( 1 > intval( get_option( 'wl_install_version' ) ) ) {
335
+	if (1 > intval(get_option('wl_install_version'))) {
336 336
 
337
-		$log->trace( 'Installing version 1...' );
337
+		$log->trace('Installing version 1...');
338 338
 
339 339
 		// Get the configuration service and load the key.
340 340
 		$configuration_service = Wordlift_Configuration_Service::get_instance();
@@ -342,24 +342,24 @@  discard block
 block discarded – undo
342 342
 
343 343
 		// If the key is not empty then set the dataset URI while sending
344 344
 		// the site URL.
345
-		if ( ! empty( $key ) ) {
346
-			$log->info( 'Updating the remote dataset URI...' );
345
+		if ( ! empty($key)) {
346
+			$log->info('Updating the remote dataset URI...');
347 347
 
348
-			$configuration_service->get_remote_dataset_uri( $key );
348
+			$configuration_service->get_remote_dataset_uri($key);
349 349
 		}
350 350
 
351 351
 		// Check if the dataset key has been stored.
352 352
 		$dataset_uri = $configuration_service->get_dataset_uri();
353 353
 
354 354
 		// If the dataset URI is empty, do not set the install version.
355
-		if ( ! empty( $dataset_uri ) ) {
356
-			update_option( 'wl_install_version', 1 );
355
+		if ( ! empty($dataset_uri)) {
356
+			update_option('wl_install_version', 1);
357 357
 
358
-			$log->info( 'Version 1 installed.' );
358
+			$log->info('Version 1 installed.');
359 359
 		}
360 360
 
361 361
 	}
362 362
 
363 363
 }
364 364
 
365
-add_action( 'init', 'wl_core_update_db_check', 11 ); // need taxonomies and post type to be defined first
365
+add_action('init', 'wl_core_update_db_check', 11); // need taxonomies and post type to be defined first
Please login to merge, or discard this patch.
src/modules/core/wordlift_core_constants.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,38 +1,38 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-define( 'WL_DEFAULT_THUMBNAIL_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/public/images/missing-image-150x150.png' );
4
-define( 'WL_DEFAULT_PATH', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/' );
3
+define('WL_DEFAULT_THUMBNAIL_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/public/images/missing-image-150x150.png');
4
+define('WL_DEFAULT_PATH', dirname(dirname(plugin_dir_url(__FILE__))).'/');
5 5
 
6 6
 // Database version
7
-define( 'WL_DB_VERSION', '3.16' );
7
+define('WL_DB_VERSION', '3.16');
8 8
 
9 9
 // Custom table name
10
-define( 'WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances' );
10
+define('WL_DB_RELATION_INSTANCES_TABLE_NAME', 'wl_relation_instances');
11 11
 
12
-define( 'WL_WHAT_RELATION', 'what' );
13
-define( 'WL_WHO_RELATION', 'who' );
14
-define( 'WL_WHERE_RELATION', 'where' );
15
-define( 'WL_WHEN_RELATION', 'when' );
12
+define('WL_WHAT_RELATION', 'what');
13
+define('WL_WHO_RELATION', 'who');
14
+define('WL_WHERE_RELATION', 'where');
15
+define('WL_WHEN_RELATION', 'when');
16 16
 
17 17
 // Mapping options / validations rules used by wl_core_get_posts to perform validation on args
18 18
 // The array is serialized because array constants are only from php 5.6 on.
19
-define( 'WL_CORE_GET_POSTS_VALIDATION_RULES', serialize( array(
20
-	'get'            => array( 'posts', 'post_ids' ),
21
-	'as'             => array( 'object', 'subject' ),
22
-	'post_type'      => array( 'post', 'entity' ),
23
-	'post_status'    => array( 'draft', 'trash', 'publish' ),
19
+define('WL_CORE_GET_POSTS_VALIDATION_RULES', serialize(array(
20
+	'get'            => array('posts', 'post_ids'),
21
+	'as'             => array('object', 'subject'),
22
+	'post_type'      => array('post', 'entity'),
23
+	'post_status'    => array('draft', 'trash', 'publish'),
24 24
 	'with_predicate' => array(
25 25
 		WL_WHAT_RELATION,
26 26
 		WL_WHEN_RELATION,
27 27
 		WL_WHERE_RELATION,
28 28
 		WL_WHO_RELATION,
29 29
 	),
30
-) ) );
30
+)));
31 31
 
32 32
 // Classification boxes configuration for angularjs edit-post widget
33 33
 // The array is serialized because array constants are only from php 5.6 on.
34 34
 
35
-define( 'WL_CORE_POST_CLASSIFICATION_BOXES', serialize( array(
35
+define('WL_CORE_POST_CLASSIFICATION_BOXES', serialize(array(
36 36
 	array(
37 37
 		'id'               => WL_WHAT_RELATION,
38 38
 		'label'            => 'What',
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 	array(
57 57
 		'id'               => WL_WHERE_RELATION,
58 58
 		'label'            => 'Where',
59
-		'registeredTypes'  => array( 'place' ),
59
+		'registeredTypes'  => array('place'),
60 60
 		'selectedEntities' => array(),
61 61
 	),
62 62
 	array(
63 63
 		'id'               => WL_WHEN_RELATION,
64 64
 		'label'            => 'When',
65
-		'registeredTypes'  => array( 'event' ),
65
+		'registeredTypes'  => array('event'),
66 66
 		'selectedEntities' => array(),
67 67
 	),
68
-) ) );
68
+)));
Please login to merge, or discard this patch.