PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 3.3.9
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v3.3.9
3.3.9 3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 All 67 releases
logtivity / Loggers / WP_All_Import / Logtivity_WP_All_Import.php

Logtivity_WP_All_Import.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity 3.3.9, at Loggers/WP_All_Import/Logtivity_WP_All_Import.php

119 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Logtivity
5 * @contact logtivity.io, [email protected]
6 * @copyright 2024-2026 Logtivity. All rights reserved
7 * @license https://www.gnu.org/licenses/gpl.html GNU/GPL
8 *
9 * This file is part of Logtivity.
10 *
11 * Logtivity is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Logtivity is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 class Logtivity_WP_All_Import
26 {
27 protected $allowedAllImportLogs = [
28 'All Import Running',
29 'All Import Completed',
30 ];
31
32 public function __construct()
33 {
34 if ($this->isImporting()) {
35 $this->logImportButDisableIndividualChanges();
36 }
37
38 add_action('pmxi_before_xml_import', [$this, 'importRunning'], 10, 1);
39 add_action('pmxi_after_xml_import', [$this, 'importCompleted'], 10, 2);
40 }
41
42 public function importRunning($import_id)
43 {
44 Logtivity::log()
45 ->setAction('All Import Running')
46 ->setContext($import_id)
47 ->addMeta('Import ID', $import_id)
48 ->send();
49 }
50
51 public function importCompleted($import_id, $import)
52 {
53 Logtivity::log()
54 ->setAction('All Import Completed')
55 ->setContext($import_id)
56 ->addMeta('Import ID', $import_id)
57 ->send();
58 }
59
60 public function isImporting()
61 {
62 // Manually running an import
63 $manual_run = isset( $_GET['page'] ) && ( $_GET['page'] == 'pmxi-admin-import' || $_GET['page'] == 'pmxi-admin-manage' );
64
65 // Cron jobs running an import
66 $cron_run = isset( $_GET['import_id'] ) && isset( $_GET['action'] ) && $_GET['action'] == 'processing';
67
68 // Automatic Scheduling service running an import
69 $automatic_scheduling_run = ( isset( $_GET['action'] ) && $_GET['action'] == 'wpai_public_api' ) && ( isset( $_GET['q'] ) && $_GET['q'] == 'scheduling/process' );
70
71 // Manually uploading an import file
72 $manual_upload = ( isset($_GET['page']) && $_GET['page'] == 'pmxi-admin-settings' ) && ( isset( $_GET['action'] ) && $_GET['action'] == 'upload' );
73
74 // Extra check: see if import ID is numeric
75 $import_id = is_numeric( $this->wp_all_import_get_import_id() );
76
77 // Check if they're importing
78 if ( $manual_run || $cron_run || $automatic_scheduling_run || $manual_upload || $import_id ) {
79 return true;
80 }
81 }
82
83 public function logImportButDisableIndividualChanges()
84 {
85 add_action('wp_logtivity_instance', function($Logtivity_Logger) {
86 if (!in_array($Logtivity_Logger->action, $this->allowedAllImportLogs)) {
87 $Logtivity_Logger->stop();
88 }
89 });
90 }
91
92 public function wp_all_import_get_import_id() {
93 global $argv;
94 $import_id = 'new';
95
96 if ( ! empty( $argv ) ) {
97 $import_id_arr = array_filter( $argv, function( $a ) {
98 return ( is_numeric( $a ) ) ? true : false;
99 });
100
101 if ( ! empty( $import_id_arr ) ) {
102 $import_id = reset( $import_id_arr );
103 }
104 }
105
106 if ( $import_id == 'new' ) {
107 if ( isset( $_GET['import_id'] ) ) {
108 $import_id = intval($_GET['import_id']);
109 // } elseif ( isset( $_GET['id'] ) ) {
110 // $import_id = intval($_GET['id']);
111 }
112 }
113
114 return $import_id;
115 }
116 }
117
118 $Logtivity_WP_All_Import = new Logtivity_WP_All_Import;
119