PluginProbe
Sessions / 2.3.1
Sessions v2.3.1
2.1.0 2.10.0 2.11.0 2.12.0 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.2.0 2.3.0 2.3.1 2.4.0 2.4.1 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.8.0 2.9.0 2.9.1 3.0.0 3.1.0 3.1.1 All 39 releases
sessions / includes / plugin / class-updater.php

class-updater.php in Sessions 2.3.1, at includes/plugin/class-updater.php

92 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin updates handling.
4 *
5 * @package Plugin
6 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
7 * @since 1.0.0
8 */
9
10 namespace POSessions\Plugin;
11
12 use POSessions\System\Nag;
13 use POSessions\System\Option;
14 use Exception;
15
16 use POSessions\System\Cache;
17 use POSessions\Plugin\Feature\Schema;
18 use POSessions\System\Markdown;
19
20 /**
21 * Plugin updates handling.
22 *
23 * This class defines all code necessary to handle the plugin's updates.
24 *
25 * @package Plugin
26 * @author Pierre Lannoy <https://pierre.lannoy.fr/>.
27 * @since 1.0.0
28 */
29 class Updater {
30
31 /**
32 * Initializes the class, set its properties and performs
33 * post-update processes if needed.
34 *
35 * @since 1.0.0
36 */
37 public function __construct() {
38 $old = Option::network_get( 'version' );
39 if ( POSE_VERSION !== $old ) {
40 if ( '0.0.0' === $old ) {
41 $this->install();
42 // phpcs:ignore
43 $message = sprintf( esc_html__( '%1$s has been correctly installed.', 'sessions' ), POSE_PRODUCT_NAME );
44 } else {
45 $this->update( $old );
46 // phpcs:ignore
47 $message = sprintf( esc_html__( '%1$s has been correctly updated from version %2$s to version %3$s.', 'sessions' ), POSE_PRODUCT_NAME, $old, POSE_VERSION );
48 \DecaLog\Engine::eventsLogger( POSE_SLUG )->notice( $message );
49 // phpcs:ignore
50 $message .= ' ' . sprintf( __( 'See <a href="%s">what\'s new</a>.', 'sessions' ), admin_url( 'admin.php?page=pose-settings&tab=about' ) );
51 }
52 Nag::add( 'update', 'info', $message );
53 Option::network_set( 'version', POSE_VERSION );
54 }
55 }
56
57 /**
58 * Performs post-installation processes.
59 *
60 * @since 1.0.0
61 */
62 private function install() {
63
64 }
65
66 /**
67 * Performs post-update processes.
68 *
69 * @param string $from The version from which the plugin is updated.
70 * @since 1.0.0
71 */
72 private function update( $from ) {
73 $schema = new Schema();
74 $schema->update();
75 Cache::delete_global( 'data/*' );
76 \DecaLog\Engine::eventsLogger( POSE_SLUG )->notice( 'Cache purged.' );
77 }
78
79 /**
80 * Get the changelog.
81 *
82 * @param array $attributes 'style' => 'markdown', 'html'.
83 * 'mode' => 'raw', 'clean'.
84 * @return string The output of the shortcode, ready to print.
85 * @since 1.0.0
86 */
87 public function sc_get_changelog( $attributes ) {
88 $md = new Markdown();
89 return $md->get_shortcode( 'CHANGELOG.md', $attributes );
90 }
91 }
92