WordPoints_CubePoints_Importer   C
last analyzed

Complexity

Total Complexity 54

Size/Duplication

Total Lines 704
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 704
rs 5.2173
c 0
b 0
f 0
wmc 54
lcom 1
cbo 2

17 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 34 1
A is_available() 0 11 2
A is_cubepoints_installed() 0 4 1
A is_cubepoints_active() 0 4 1
B import_excluded_users() 0 43 4
C import_points_settings() 0 102 11
B import_daily_points_hook() 0 37 5
A add_points_hook() 0 21 2
A format_settings_for_post_type() 0 21 1
B import_user_points() 0 32 3
A get_next_user_points_batch() 0 23 2
A can_import_points_logs() 0 12 2
B import_points_logs() 0 31 3
C import_points_log() 0 62 8
A render_points_log_text() 0 6 1
A get_next_points_logs_batch() 0 23 2
B import_ranks() 0 50 5

How to fix   Complexity   

Complex Class

Complex classes like WordPoints_CubePoints_Importer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use WordPoints_CubePoints_Importer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Importer class for importing from CubePoints.
5
 *
6
 * @package WordPoints_Importer
7
 * @since 1.0.0
8
 */
9
10
/**
11
 * CubePoints importer.
12
 *
13
 * @since 1.0.0
14
 */
15
class WordPoints_CubePoints_Importer extends WordPoints_Importer {
16
17
	/**
18
	 * Reversible log types indexed by the reversing log type.
19
	 *
20
	 * This information is used to set the `auto_reversed` and `original_log_id`
21
	 * points log metadata for the imported logs.
22
	 *
23
	 * @since 1.2.0
24
	 *
25
	 * @see WordPoints_CubePoints_Importer::import_points_log()
26
	 *
27
	 * @var array
28
	 */
29
	protected $reversible_log_types = array(
30
		'comment_remove'      => 'comment',
31
		'post_comment_remove' => 'post_comment',
32
	);
33
34
	/**
35
	 * Primary entity slugs for each imported log type.
36
	 *
37
	 * These are points log meta keys under which to save the entity ID in the
38
	 * CubePoints `data` log field.
39
	 *
40
	 * @since 1.2.0
41
	 *
42
	 * @see WordPoints_CubePoints_Importer::import_points_log()
43
	 *
44
	 * @var array
45
	 */
46
	protected $log_type_entities = array(
47
		'comment'             => 'comment',
48
		'comment_remove'      => 'comment',
49
		'post'                => 'post',
50
		'post_comment'        => 'comment',
51
		'post_comment_remove' => 'comment',
52
		'register'            => 'user',
53
	);
54
55
	/**
56
	 * IDs of reversible logs, indexed by CubePoints log type and object ID.
57
	 *
58
	 * @since 1.2.0
59
	 *
60
	 * @see WordPoints_CubePoints_Importer::import_points_log()
61
	 *
62
	 * @var int[][]
63
	 */
64
	protected $reversible_log_ids;
65
66
	/**
67
	 * @since 1.0.0
68
	 */
69
	public function __construct( $name ) {
70
71
		parent::__construct( $name );
72
73
		$this->components = array(
74
			'points' => array(
75
				'excluded_users' => array(
76
					'label' => __( 'Excluded users', 'wordpoints-importer' ),
77
					'function' => array( $this, 'import_excluded_users' ),
78
				),
79
				'settings'    => array(
80
					'label' => __( 'Points Reactions', 'wordpoints-importer' ),
81
					'description' => __( 'If checked, the settings for the number of points to award for posts, comments, etc. are imported.', 'wordpoints-importer' ),
82
					'function' => array( $this, 'import_points_settings' ),
83
				),
84
				'user_points' => array(
85
					'label' => __( 'User points', 'wordpoints-importer' ),
86
					'function' => array( $this, 'import_user_points' ),
87
				),
88
				'logs' => array(
89
					'label' => __( 'Points logs', 'wordpoints-importer' ),
90
					'function' => array( $this, 'import_points_logs' ),
91
					'can_import' => array( $this, 'can_import_points_logs' ),
92
				),
93
			),
94
			'ranks' => array(
95
				'ranks' => array(
96
					'label' => __( 'Rank settings', 'wordpoints-importer' ),
97
					'description' => __( 'If checked, the list of ranks is imported, and users will have the correct ranks assigned to them.', 'wordpoints-importer' ),
98
					'function' => array( $this, 'import_ranks' ),
99
				),
100
			),
101
		);
102
	}
103
104
	/**
105
	 * @since 1.0.0
106
	 */
107
	public function is_available() {
108
109
		if ( ! $this->is_cubepoints_installed() ) {
110
			return new WP_Error(
111
				'cubepoints_not_installed'
112
				, __( 'CubePoints is not installed', 'wordpoints-importer' )
113
			);
114
		}
115
116
		return true;
117
	}
118
119
	/**
120
	 * Check if CubePoints is installed.
121
	 *
122
	 * @since 1.0.0
123
	 */
124
	public function is_cubepoints_installed() {
125
126
		return (bool) get_option( 'cp_db_version' );
127
	}
128
129
	/**
130
	 * Check if CubePoints is active.
131
	 *
132
	 * @since 1.0.0
133
	 */
134
	public function is_cubepoints_active() {
135
136
		return function_exists( 'cp_ready' );
137
	}
138
139
	/**
140
	 * Import the excluded users.
141
	 *
142
	 * @since 1.0.0
143
	 */
144
	protected function import_excluded_users() {
145
146
		$this->feedback->info( __( 'Importing excluded users&hellip;', 'wordpoints-importer' ) );
147
148
		$excluded_users = get_option( 'cp_topfilter' );
149
150
		if ( ! is_array( $excluded_users ) ) {
151
			$this->feedback->warning( __( 'No excluded users found.', 'wordpoints-importer' ) );
152
			return;
153
		}
154
155
		$user_ids = array();
156
157
		foreach ( $excluded_users as $user_login ) {
158
159
			$user = get_user_by( 'login', $user_login );
160
161
			if ( $user instanceof WP_User ) {
162
				$user_ids[] = $user->ID;
163
			}
164
		}
165
166
		$excluded_user_ids = wordpoints_get_maybe_network_array_option(
167
			'wordpoints_excluded_users'
168
		);
169
170
		$excluded_user_ids = array_unique(
171
			array_merge( $excluded_user_ids, $user_ids )
172
		);
173
174
		wordpoints_update_maybe_network_option(
175
			'wordpoints_excluded_users'
176
			, $excluded_user_ids
177
		);
178
179
		$this->feedback->success(
180
			sprintf(
181
				// translators: Number of users.
182
				__( 'Imported %s excluded users.', 'wordpoints-importer' )
183
				, count( $user_ids )
184
			)
185
		);
186
	}
187
188
	/**
189
	 * Import the points settings to the points hooks.
190
	 *
191
	 * @since 1.1.0
192
	 *
193
	 * @param array $settings The settings for the points component import.
194
	 */
195
	protected function import_points_settings( $settings ) {
196
197
		$this->feedback->info( __( 'Importing points reactions&hellip;', 'wordpoints-importer' ) );
198
199
		$options = array(
200
			'cp_comment_points'     => array(
201
				'event' => 'comment_leave\post',
202
				'target' => array( 'comment\post', 'author', 'user' ),
203
				/* translators: The post type name */
204
				'log_text' => __( 'Comment on a %s.', 'wordpoints-importer' ),
205
				/* translators: The post type name */
206
				'description' => __( 'Commenting on a %s.', 'wordpoints-importer' ),
207
				'legacy_log_type' => 'cubepoints-comment',
208
				'legacy_meta_key' => 'comment',
209
			),
210
			'cp_post_points'        => array(
211
				'event' => 'post_publish\post',
212
				'target' => array( 'post\post', 'author', 'user' ),
213
				/* translators: The post type name */
214
				'log_text' => __( 'Published a Post.', 'wordpoints-importer' ),
215
				/* translators: The post type name */
216
				'description' => __( 'Publishing a Post.', 'wordpoints-importer' ),
217
				'legacy_log_type' => 'cubepoints-post',
218
				'legacy_meta_key' => 'post',
219
				// CubePoints doesn't remove points when a post is deleted.
220
				'blocker' => array( 'toggle_off' => true ),
221
				'points_legacy_repeat_blocker' => array( 'toggle_on' => true ),
222
			),
223
			'cp_reg_points'         => array(
224
				'event' => 'user_register',
225
				'log_text' => __( 'Registration.', 'wordpoints-importer' ),
226
				'description' => __( 'Registration.', 'wordpoints-importer' ),
227
				'legacy_log_type' => 'cubepoints-register',
228
			),
229
			'cp_post_author_points' => array(
230
				'event' => 'comment_leave\post',
231
				'target' => array( 'comment\post', 'post\post', 'post\post', 'author', 'user' ),
232
				/* translators: The post type name */
233
				'log_text' => __( 'Received a comment on a %s.', 'wordpoints-importer' ),
234
				/* translators: The post type name */
235
				'description' => __( 'Receiving a comment on a %s.', 'wordpoints-importer' ),
236
				'legacy_log_type' => 'cubepoints-post_author',
237
				'legacy_meta_key' => 'comment',
238
			),
239
		);
240
241
		// Don't import this module setting if the module isn't active.
242
		if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'post_author_points' ) ) {
243
			unset( $options['cp_post_author_points'] );
244
		}
245
246
		$imported = 0;
247
248
		foreach ( $options as $option => $hook_settings ) {
249
250
			$points = get_option( $option );
251
252
			if ( wordpoints_posint( $points ) ) {
253
254
				$hook_settings['points'] = $points;
255
				$hook_settings['points_type'] = $settings['points_type'];
256
257
				if (
258
					// The CubePoints post points were only awarded for Posts.
259
					'post_publish\post' !== $hook_settings['event']
260
					&& strpos( $hook_settings['event'], '\post' )
261
				) {
262
263
					$post_type_slugs = get_post_types( array( 'public' => true ) );
264
265
					foreach ( $post_type_slugs as $post_type_slug ) {
266
267
						$added = $this->add_points_hook(
268
							$this->format_settings_for_post_type(
269
								$post_type_slug
270
								, $hook_settings
271
							)
272
						);
273
274
						if ( $added ) {
275
							$imported++;
276
						}
277
					}
278
279
				} else {
280
					if ( $this->add_points_hook( $hook_settings ) ) {
281
						$imported++;
282
					}
283
				}
284
			}
285
286
		} // End foreach ( $options ).
287
288
		if ( $this->import_daily_points_hook( $settings ) ) {
289
			$imported++;
290
		}
291
292
		$this->feedback->success(
293
			// translators: Number of reactions.
294
			sprintf( __( 'Imported %s points reactions.', 'wordpoints-importer' ), $imported )
295
		);
296
	}
297
298
	/**
299
	 * Import the settings for the Daily Points module to a points hook.
300
	 *
301
	 * @since 1.1.0
302
	 *
303
	 * @param array $settings The settings for the points component import.
304
	 *
305
	 * @return bool True if the settings were imported, false otherwise.
306
	 */
307
	protected function import_daily_points_hook( $settings ) {
308
309
		// Don't import this module setting if the module isn't active.
310
		if ( function_exists( 'cp_module_activated' ) && ! cp_module_activated( 'dailypoints' ) ) {
311
			return false;
312
		}
313
314
		$points = get_option( 'cp_module_dailypoints_points' );
315
		$period = get_option( 'cp_module_dailypoints_time' );
316
317
		if ( ! wordpoints_int( $points ) || ! wordpoints_posint( $period ) ) {
318
			return false;
319
		}
320
321
		return $this->add_points_hook(
322
			array(
323
				'event' => 'user_visit',
324
				'target' => array( 'current:user' ),
325
				'reactor' => 'points_legacy',
326
				'points' => $points,
327
				'points_type' => $settings['points_type'],
328
				'points_legacy_periods' => array(
329
					'fire' => array(
330
						array(
331
							'length' => $period,
332
							'args' => array( array( 'current:user' ) ),
333
							'relative' => true,
334
						),
335
					),
336
				),
337
				'log_text' => __( 'Visiting the site.', 'wordpoints-importer' ),
338
				'description' => __( 'Visiting the site.', 'wordpoints-importer' ),
339
				'points_legacy_reversals' => array(),
340
				'legacy_log_type' => 'cubepoints-dailypoints',
341
			)
342
		);
343
	}
344
345
	/**
346
	 * Programmatically create a new instance of a points hook.
347
	 *
348
	 * @since 1.0.0
349
	 * @since 1.2.0 Now just accepts a single argument, $settings.
350
	 *
351
	 * @param array $settings The settings for this hook.
352
	 *
353
	 * @return bool True if added successfully, or false on failure.
354
	 */
355
	private function add_points_hook( $settings = array() ) {
356
357
		$reaction_store = wordpoints_hooks()->get_reaction_store( 'points' );
358
359
		$settings = array_merge(
360
			array(
361
				'target' => array( 'user' ),
362
				'reactor' => 'points_legacy',
363
				'points_legacy_reversals' => array( 'toggle_off' => 'toggle_on' ),
364
			)
365
			, $settings
366
		);
367
368
		$reaction = $reaction_store->create_reaction( $settings );
369
370
		if ( ! $reaction instanceof WordPoints_Hook_ReactionI ) {
371
			return false;
372
		}
373
374
		return true;
375
	}
376
377
	/**
378
	 * Format the settings for a reaction for a particular post type.
379
	 *
380
	 * @since 1.2.0
381
	 *
382
	 * @param string $post_type The slug of the post type to format the settings for.
383
	 * @param array  $settings  The reaction settings.
384
	 *
385
	 * @return array The settings modified for this particular post type.
386
	 */
387
	protected function format_settings_for_post_type( $post_type, $settings ) {
388
389
		$settings['event'] = str_replace(
390
			'\post'
391
			, '\\' . $post_type
392
			, $settings['event']
393
		);
394
395
		$settings['target'] = str_replace(
396
			'\post'
397
			, '\\' . $post_type
398
			, $settings['target']
399
		);
400
401
		$labels = get_post_type_labels( get_post_type_object( $post_type ) );
402
403
		$settings['log_text'] = sprintf( $settings['log_text'], $labels->singular_name );
404
		$settings['description'] = sprintf( $settings['description'], $labels->singular_name );
405
406
		return $settings;
407
	}
408
409
	/**
410
	 * Import the user points.
411
	 *
412
	 * @since 1.0.0
413
	 *
414
	 * @param array $settings The settings for the points component import.
415
	 */
416
	protected function import_user_points( $settings ) {
417
418
		$this->feedback->info( __( 'Importing users&apos; points&hellip;', 'wordpoints-importer' ) );
419
420
		// We don't log the import transactions.
421
		add_filter( 'wordpoints_points_log', '__return_false' );
422
423
		$start = 0;
424
		$rows  = $this->get_next_user_points_batch( $start );
425
426
		// We do the import in batches.
427
		while ( $rows ) {
428
429
			foreach ( $rows as $row ) {
430
431
				wordpoints_alter_points(
432
					$row->user_id
433
					, $row->points
434
					, $settings['points_type']
435
					, 'cubepoints_import' // This is only for the hooks, it isn't being logged.
436
				);
437
			}
438
439
			$start += count( $rows );
440
			$rows   = $this->get_next_user_points_batch( $start );
441
		}
442
443
		remove_filter( 'wordpoints_points_log', '__return_false' );
444
445
		// translators: Number of users.
446
		$this->feedback->success( sprintf( __( 'Imported points for %s users&hellip;', 'wordpoints-importer' ), $start ) );
447
	}
448
449
	/**
450
	 * Get a batch of user points to import.
451
	 *
452
	 * @since 1.0.0
453
	 *
454
	 * @param int $start The offset number to begin counting at.
455
	 *
456
	 * @return object[]|false The rows, or false.
457
	 */
458
	protected function get_next_user_points_batch( $start ) {
459
460
		global $wpdb;
461
462
		$rows = $wpdb->get_results(
463
			$wpdb->prepare(
464
				"
465
					SELECT `user_id`, `meta_value` as points
466
					FROM {$wpdb->usermeta}
467
					WHERE `meta_key` = 'cpoints'
468
					ORDER BY `umeta_id`
469
					LIMIT %d,500
470
				"
471
				, $start
472
			)
473
		); // WPCS: cache OK.
474
475
		if ( ! is_array( $rows ) ) {
476
			return false;
477
		}
478
479
		return $rows;
480
	}
481
482
	/**
483
	 * Check if the points logs can be imported.
484
	 *
485
	 * @since 1.0.0
486
	 *
487
	 * @return true|WP_Error True on success or a WP_Error on failure.
488
	 */
489
	public function can_import_points_logs() {
490
491
		if ( ! $this->is_cubepoints_active() ) {
492
493
			return new WP_Error(
494
				'wordpoints_import_points_logs_cubepoints_inactive'
495
				, __( 'CubePoints must be active.', 'wordpoints-importer' )
496
			);
497
		}
498
499
		return true;
500
	}
501
502
	/**
503
	 * Import the points logs.
504
	 *
505
	 * @since 1.0.0
506
	 *
507
	 * @param array $settings The import settings for the points component.
508
	 */
509
	protected function import_points_logs( $settings ) {
510
511
		$this->feedback->info( __( 'Importing points logs&hellip;', 'wordpoints-importer' ) );
512
513
		$start = 0;
514
		$logs  = $this->get_next_points_logs_batch( $start );
515
516
		while ( $logs ) {
517
518
			foreach ( $logs as $log ) {
519
520
				$this->import_points_log(
521
					$log->uid
522
					, $log->points
523
					, $settings['points_type']
524
					, "cubepoints-{$log->type}"
525
					, array(
526
						'cubepoints_type' => $log->type,
527
						'cubepoints_data' => $log->data,
528
					)
529
					, date( 'Y-m-d H:i:s', $log->timestamp )
530
				);
531
			}
532
533
			$start += count( $logs );
534
			$logs   = $this->get_next_points_logs_batch( $start );
535
		}
536
537
		// translators: Number of points logs.
538
		$this->feedback->success( sprintf( __( 'Imported %s points log entries.', 'wordpoints-importer' ), $start ) );
539
	}
540
541
	/**
542
	 * Import a points log.
543
	 *
544
	 * @since 1.0.0
545
	 *
546
	 * @param int    $user_id     The ID of the user the log is for.
547
	 * @param int    $points      The number of points awarded.
548
	 * @param string $points_type The points type.
549
	 * @param string $log_type    The log type.
550
	 * @param array  $meta        The metadata for this log.
551
	 * @param int    $date        The date the transaction took place.
552
	 */
553
	protected function import_points_log( $user_id, $points, $points_type, $log_type, $meta, $date ) {
554
555
		global $wpdb;
556
557
		$result = $wpdb->insert(
558
			$wpdb->wordpoints_points_logs,
559
			array(
560
				'user_id'     => $user_id,
561
				'points'      => $points,
562
				'points_type' => $points_type,
563
				'log_type'    => $log_type,
564
				'text'        => $this->render_points_log_text( '', $user_id, $points, $points_type, $log_type, $meta ),
565
				'date'        => $date,
566
				'site_id'     => $wpdb->siteid,
567
				'blog_id'     => $wpdb->blogid,
568
			),
569
			array( '%d', '%d', '%s', '%s', '%s', '%s', '%d', '%d' )
570
		);
571
572
		if ( false !== $result ) {
573
574
			$log_id = (int) $wpdb->insert_id;
575
576
			// Set auto_reversed and original_log_id metadata for reversed logs.
577
			foreach ( $this->reversible_log_types as $reverse_type => $type ) {
578
579
				if ( $meta['cubepoints_type'] === $type ) {
580
581
					// Save this log ID for later, in case this log was reversed.
582
					// cubepoints_data will contain the entity ID.
583
					$this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] = $log_id;
584
585
				} elseif (
586
					$meta['cubepoints_type'] === $reverse_type
587
					&& isset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] )
588
				) {
589
590
					// This log was reverses another one. Set the original log ID.
591
					$meta['original_log_id'] = $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ];
592
593
					// And mark the original as auto_reversed.
594
					wordpoints_add_points_log_meta( $meta['original_log_id'], 'auto_reversed', $log_id );
595
596
					// No need to keep this info anymore.
597
					unset( $this->reversible_log_ids[ $type ][ $meta['cubepoints_data'] ] );
598
				}
599
			}
600
601
			// Set the entity IDs to their own meta keys, for the sake of reversals.
602
			if ( isset( $this->log_type_entities[ $meta['cubepoints_type'] ] ) ) {
603
				$meta[ $this->log_type_entities[ $meta['cubepoints_type'] ] ] = $meta['cubepoints_data'];
604
			}
605
606
			foreach ( $meta as $meta_key => $meta_value ) {
607
608
				wordpoints_add_points_log_meta( $log_id, $meta_key, $meta_value );
609
			}
610
611
			do_action( 'wordpoints_points_log', $user_id, $points, $points_type, $log_type, $meta, $log_id );
612
613
		} // End if ( inserted successfully ).
614
	}
615
616
	/**
617
	 * Generate the log text when importing a points log.
618
	 *
619
	 * @since 1.0.0
620
	 */
621
	public function render_points_log_text( $text, $user_id, $points, $points_type, $log_type, $meta ) {
0 ignored issues
show
Unused Code introduced by
The parameter $text is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $points_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $log_type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
622
623
		ob_start();
624
		do_action( 'cp_logs_description', $meta['cubepoints_type'], $user_id, $points, $meta['cubepoints_data'] );
625
		return ob_get_clean();
626
	}
627
628
	/**
629
	 * Get the next 500 points logs from CubePoints.
630
	 *
631
	 * @since 1.0.0
632
	 *
633
	 * @param int $start The offset number to begin counting the 500 at.
634
	 *
635
	 * @return object[]|false The rows from the database.
636
	 */
637
	protected function get_next_points_logs_batch( $start ) {
638
639
		global $wpdb;
640
641
		$logs = $wpdb->get_results( // WPCS: unprepared SQL OK.
642
			$wpdb->prepare( // WPCS: unprepared SQL OK.
643
				'
644
					SELECT *
645
					FROM `' . CP_DB . '`
646
					ORDER BY `id`
647
					LIMIT %d,500
648
				'
649
				, $start
650
			)
651
		); // WPCS: cache OK.
652
653
		if ( ! is_array( $logs ) ) {
654
			$this->feedback->error( __( 'Unable to retrieve the logs from CubePoints&hellip;', 'wordpoints-importer' ) );
655
			return false;
656
		}
657
658
		return $logs;
659
	}
660
661
	/**
662
	 * Import ranks.
663
	 *
664
	 * @since 1.1.0
665
	 *
666
	 * @param array $settings The import settings for the ranks component.
667
	 */
668
	public function import_ranks( $settings ) {
669
670
		$this->feedback->info( __( 'Importing ranks&hellip;', 'wordpoints-importer' ) );
671
672
		$ranks_data = get_option( 'cp_module_ranks_data' );
673
674
		if ( empty( $ranks_data ) || ! is_array( $ranks_data ) ) {
675
			$this->feedback->error( __( 'No ranks found.', 'wordpoints-importer' ) );
676
			return;
677
		}
678
679
		$i = 0;
680
681
		// The base rank already exists, so we just update it.
682
		if ( isset( $ranks_data[0] ) ) {
683
684
			wordpoints_update_rank(
685
				WordPoints_Rank_Groups::get_group( $settings['rank_group'] )->get_rank( 0 )
686
				, $ranks_data[0]
687
				, 'base'
688
				, $settings['rank_group']
689
				, 0
690
			);
691
692
			$i++;
693
694
			unset( $ranks_data[0] );
695
		}
696
697
		$points_type = substr( $settings['rank_group'], strlen( 'points_type-' ) );
698
		$rank_type = 'points-' . $points_type;
699
700
		ksort( $ranks_data );
701
702
		foreach ( $ranks_data as $points => $rank_name ) {
703
704
			wordpoints_add_rank(
705
				$rank_name
706
				, $rank_type
707
				, $settings['rank_group']
708
				, $i
709
				, array( 'points' => $points, 'points_type' => $points_type )
710
			);
711
712
			$i++;
713
		}
714
715
		// translators: Number of ranks.
716
		$this->feedback->success( sprintf( __( 'Imported %s ranks.', 'wordpoints-importer' ), $i ) );
717
	}
718
}
719
720
// EOF
721