Completed
Branch 2.0.0 (814c19)
by Jimmy
03:05
created

Update_Manager_Action   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1
1
<?php
2
/**
3
 * Gestion des actions pour les mises à jours.
4
 *
5
 * @author Eoxia <[email protected]>
6
 * @since 1.0.0
7
 * @version 1.0.0
8
 * @copyright 2015-2018 Eoxia
9
 * @package EO_Framework\EO_Update_Manager\Action
10
 */
11
12
namespace eoxia;
13
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
/**
19
 * Classe de gestion des "actions" pour le module de mise à jour des données suite aux différentes version de l'extension
20
 */
21
class Update_Manager_Action {
22
23
	/**
24
	 * Définition du namespace courant pour le module de mise à jour.
25
	 *
26
	 * @var string
27
	 */
28
	protected $current_plugin_slug = null;
29
30
	/**
31
	 * Instanciation de la classe de gestions des mises à jour des données suite aux différentes versions de l'extension
32
	 *
33
	 * @since 1.0.0
34
	 * @version 1.0.0
35
	 */
36
	public function __construct() {
37
		$element_namespace         = new \ReflectionClass( get_called_class() );
38
		$this->current_plugin_slug = str_replace( '_', '-', $element_namespace->getNamespaceName() );
39
40
		add_action( 'admin_enqueue_scripts', array( $this, 'callback_admin_scripts' ) );
41
	}
42
43
	/**
44
	 * Charges le CSS et le JS de WPEO_Update_Manager
45
	 *
46
	 * @since 1.0.0
47
	 * @version 1.0.0
48
	 */
49
	public function callback_admin_scripts() {
50
		wp_enqueue_style( 'wpeo_update_manager_style', \eoxia\Config_Util::$init['eo-framework']->wpeo_update_manager->url . '/assets/css/style.css', array() );
51
		wp_enqueue_script( 'wpeo_update_manager_script', \eoxia\Config_Util::$init['eo-framework']->wpeo_update_manager->url . '/assets/js/wpeo-update-manager.js', array( 'jquery', 'jquery-form' ), \eoxia\Config_Util::$init['eo-framework']->wpeo_update_manager->version );
52
	}
53
54
	/**
55
	 * On récupère la version actuelle de l'extension principale pour savoir si une mise à jour est nécessaire
56
	 * On regarde également si des mises à jour n'ont pas été faite suite à un suivi des mises à jours non régulier
57
	 *
58
	 * @since 1.0.0
59
	 * @version 1.0.0
60
	 */
61
	public function automatic_update_redirect() {
62
		$waiting_updates = get_option( Config_Util::$init[ $this->current_plugin_slug ]->key_waiting_updates, array() );
63
64
		if ( ! strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) ) {
65
			$current_version_to_check = (int) str_replace( '.', '', Config_Util::$init[ $this->current_plugin_slug ]->version );
66
			$last_version_done        = (int) get_option( Config_Util::$init[ $this->current_plugin_slug ]->key_last_update_version, Config_Util::$init[ $this->current_plugin_slug ]->update_manager->first_version );
67
			if ( 3 === strlen( $current_version_to_check ) ) {
68
				$current_version_to_check *= 10;
69
			}
70
71
			if ( $last_version_done !== $current_version_to_check ) {
72
				$update_data_path = Config_Util::$init[ $this->current_plugin_slug ]->update_manager->path . 'data/';
73
				for ( $i = ( (int) substr( $last_version_done, 0, 4 ) + 1 ); $i <= $current_version_to_check; $i++ ) {
74
					if ( is_file( $update_data_path . 'update-' . $i . '-data.php' ) ) {
75
						require_once $update_data_path . 'update-' . $i . '-data.php';
76
						$waiting_updates[ $i ] = $datas;
77
78
						update_option( Config_Util::$init[ $this->current_plugin_slug ]->key_waiting_updates, $waiting_updates );
79
					}
80
				}
81
			}
82
		}
83
	}
84
85
	/**
86
	 * Ajoutes une page invisible qui vas permettre la gestion des mises à jour.
87
	 *
88
	 * @return void
89
	 *
90
	 * @since 1.0.0
91
	 * @version 1.0.0
92
	 */
93
	public function callback_admin_menu() {
94
95
		$element_namespace             = new \ReflectionClass( get_called_class() );
96
		$current_plugin_update_manager = '\\' . $element_namespace->getNamespaceName() . '\Update_Manager';
97
		add_submenu_page( 'eo-update-manager-' . $this->current_plugin_slug, __( 'Update Manager', 'eoxia' ), __( 'Update Manager', 'eoxia' ), 'manage_options', Config_Util::$init[ $this->current_plugin_slug ]->update_page_url, array( $current_plugin_update_manager::g(), 'display' ) );
98
99
	}
100
101
}
102