|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
require_once dirname( __FILE__ ) . '/sync/class.jetpack-sync-functions.php'; |
|
4
|
|
|
|
|
5
|
|
|
class Jetpack_Import_Stats { |
|
6
|
|
|
/** |
|
7
|
|
|
* A mapping of known importers to friendly names. |
|
8
|
|
|
* Keys are the class name of the known importer. |
|
9
|
|
|
* Values are the friendly name. |
|
10
|
|
|
* @var array |
|
11
|
|
|
*/ |
|
12
|
|
|
private static $known_importers = array( |
|
13
|
|
|
'Blogger_Importer' => 'blogger', |
|
14
|
|
|
'LJ_API_Import' => 'livejournal', |
|
15
|
|
|
'MT_Import' => 'mt', |
|
16
|
|
|
'RSS_Import' => 'rss', |
|
17
|
|
|
'WC_Tax_Rate_Importer' => 'woo-tax-rate', |
|
18
|
|
|
'WP_Import' => 'wordpress', |
|
19
|
|
|
); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* A mapping of action types to event name. |
|
23
|
|
|
* Keys are the name of the action. |
|
24
|
|
|
* Values are the event name recorded for that action. |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
private static $action_event_name_map = array( |
|
28
|
|
|
'import_start' => 'jetpack_import_start', |
|
29
|
|
|
'import_done' => 'jetpack_import_done', |
|
30
|
|
|
'import_end' => 'jetpack_import_done', |
|
31
|
|
|
); |
|
32
|
|
|
|
|
33
|
|
|
public static function init() { |
|
34
|
|
|
// Only handle import actions for sites that have agreed to TOS |
|
35
|
|
|
if ( Jetpack::jetpack_tos_agreed() ) { |
|
36
|
|
|
add_action( 'import_start', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
|
37
|
|
|
add_action( 'import_done', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
|
38
|
|
|
add_action( 'import_end', array( 'Jetpack_Import_Stats', 'log_import_progress' ) ); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function log_import_progress( $importer ) { |
|
43
|
|
|
// prefer self-reported importer-names |
|
44
|
|
|
if ( ! $importer ) { |
|
45
|
|
|
// fall back to inferring by calling class name |
|
46
|
|
|
$importer = Jetpack_Sync_Functions::get_calling_importer_class(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
// Give known importers a "friendly" name |
|
50
|
|
|
if ( isset( self::$known_importers[ $importer ] ) ) { |
|
51
|
|
|
$importer = self::$known_importers[ $importer ]; |
|
52
|
|
|
} |
|
53
|
|
|
$action = current_filter(); |
|
54
|
|
|
// map action to event name |
|
55
|
|
|
$event_name = self::$action_event_name_map[ $action ]; |
|
56
|
|
|
|
|
57
|
|
|
$current_user = wp_get_current_user(); |
|
58
|
|
|
|
|
59
|
|
|
// Record event to Tracks |
|
60
|
|
|
jetpack_tracks_record_event( $current_user, $event_name, array( |
|
61
|
|
|
'importer' => $importer, |
|
62
|
|
|
) ); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
add_action( 'init', array( 'Jetpack_Import_Stats', 'init' ) ); |
|
67
|
|
|
|