PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.0.2
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.0.2
5.13.0 5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / classes / WpMatomo / Commands / MatomoCommands.php
matomo / classes / WpMatomo / Commands Last commit date
MatomoCommands.php 5 years ago
MatomoCommands.php
116 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 * @package matomo
8 */
9
10 namespace WpMatomo\Commands;
11
12 use WpMatomo\Installer;
13 use WpMatomo\Settings;
14 use WpMatomo\Uninstaller;
15 use WP_CLI;
16 use WP_CLI_Command;
17 use WpMatomo\Updater;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22 if ( ! defined( 'WP_CLI' ) ) {
23 exit;
24 }
25
26 class MatomoCommands extends WP_CLI_Command {
27 /**
28 * Uninstalls Matomo.
29 *
30 * ## OPTIONS
31 *
32 * [--force]
33 * : To delete all data stored in all tables
34 *
35 * ## EXAMPLES
36 *
37 * wp matomo uninstall --force
38 *
39 * @when after_wp_load
40 */
41 public function uninstall( $args, $assoc_args ) {
42 if ( ! empty( $assoc_args['force'] ) ) {
43 $delete_all_data = true;
44 WP_CLI::log( 'Deleting all data is forced.' );
45 } else {
46 $delete_all_data = false;
47 WP_CLI::log( 'Deleting all data is NOT forced. To remove all data set the --force option.' );
48 }
49
50 $uninstaller = new Uninstaller();
51 $uninstaller->uninstall( $delete_all_data );
52
53 WP_CLI::success( 'Uninstalled Matomo Analytics' );
54 }
55 /**
56 * Updates Matomo.
57 *
58 * ## OPTIONS
59 *
60 * [--force]
61 * : To force running the update
62 *
63 * ## EXAMPLES
64 *
65 * wp matomo update --force
66 *
67 * @when after_wp_load
68 */
69 public function update( $args, $assoc_args ) {
70 if ( function_exists('is_multisite') && is_multisite() && function_exists( 'get_sites' ) ) {
71 foreach ( get_sites() as $site ) {
72 /** @var \WP_Site $site */
73 switch_to_blog( $site->blog_id );
74 // this way we make sure all blogs get updated eventually
75 WP_CLI::log( 'Blog ID' . $site->blog_id );
76 $this->_doUpdate( ! empty( $assoc_args['force'] ) );
77 restore_current_blog();
78 }
79 } else {
80 $this->_doUpdate( ! empty( $assoc_args['force'] ) );
81 }
82
83 WP_CLI::success( 'Matomo Analytics Updater finished' );
84 }
85
86 /**
87 * @param $assoc_args
88 */
89 public function _doUpdate( $force ) {
90 $settings = new Settings();
91
92 $installer = new Installer( $settings );
93 if ( ! $installer->looks_like_it_is_installed() ) {
94 WP_CLI::log( 'Skipping as looks like Matomo is not yet installed' );
95 return;
96 }
97
98 $updater = new Updater( $settings );
99 if ( $force ) {
100 WP_CLI::log( 'Force running updates' );
101 $updater->update();
102 } else {
103 WP_CLI::log( 'Running update if needed' );
104 $updater->update_if_needed();
105 }
106 }
107 }
108
109 WP_CLI::add_command(
110 'matomo',
111 '\WpMatomo\Commands\MatomoCommands',
112 array(
113 'shortdesc' => 'Manage your Matomo Analytics. Commands are recommended only to be used in development mode',
114 )
115 );
116