PluginProbe
پینوا | Pinova / trunk
پینوا | Pinova vtrunk
pinova / src / Version.php

Version.php in پینوا | Pinova trunk, at src/Version.php

105 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Pinova;
4
5 use Exception;
6 use Illuminate\Database\Schema\Blueprint;
7 use Nabik_Net_Database;
8 use Pinova\Gateways\MaxSMS;
9 use Pinova\Models\OTP;
10 use Pinova\Services\SMSService;
11
12 class Version extends \Nabik\Utils\V1\Version {
13
14 protected string $current_version = PINOVA_VERSION;
15
16 public function updated() {
17
18 flush_rewrite_rules();
19
20 }
21
22 public function update_107() {
23
24 // Change message code option id
25 $message_code = Pinova::get_option( 'sms.message' );
26 Pinova::set_option( 'sms.message_code', $message_code );
27
28 // Fix maxsms panel id
29 $gateway = Pinova::get_option( 'sms.gateway' );
30
31 if ( $gateway == 'Pinova\Gateways\IPPanel' ) {
32 $gateway = MaxSMS::class;
33 Pinova::set_option( 'sms.gateway', MaxSMS::class );
34 } elseif ( empty( $gateway ) ) {
35 return;
36 }
37
38 // Move old general option to gateway option
39 try {
40 $gateway = SMSService::get_gateway_instance( $gateway );
41 } catch ( Exception $e ) {
42 wp_die( $e->getMessage() );
43 }
44
45 foreach ( get_option( 'pinova_sms', [] ) as $key => $value ) {
46 $gateway->set_option( $key, $value );
47
48 if ( $key == 'token' ) {
49 $gateway->set_option( 'api_key', $value );
50 }
51 }
52
53 }
54
55 public function update_108() {
56 global $wpdb;
57
58 Nabik_Net_Database::Schema()->table( 'pinova_blocks', function ( Blueprint $table ) {
59 $table->after( 'identifier', function ( Blueprint $table ) {
60 $table->foreignId( 'blocked_by' )->nullable();
61 } );
62 } );
63
64 $table = $wpdb->prefix . 'pinova_blocks';
65 $query = sprintf( 'ALTER TABLE `%s` MODIFY COLUMN `blocked_until` timestamp NULL;', $table );
66 Nabik_Net_Database::DB()->statement( $query );
67 }
68
69 public function update_109() {
70
71 /** @var OTP[] $OTPs */
72 $OTPs = OTP::all();
73
74 foreach ( $OTPs as $OTP ) {
75 $OTP->channels = array_fill_keys( $OTP->channels, true );
76 $OTP->save();
77 }
78
79 }
80
81 public function update_115() {
82 global $wpdb;
83
84 $indexes = Nabik_Net_Database::DB()->select( "SHOW INDEX FROM `{$wpdb->users}`" );
85
86 $email_unique_indexes = collect( $indexes )
87 ->where( 'Non_unique', 0 )
88 ->where( 'Column_name', 'user_email' )
89 ->pluck( 'Key_name' );
90
91 foreach ( $email_unique_indexes as $email_unique_index ) {
92 Nabik_Net_Database::DB()->statement( sprintf( "ALTER TABLE `{$wpdb->users}` DROP INDEX `%s`", $email_unique_index ) );
93 }
94
95 Nabik_Net_Database::DB()->statement( "UPDATE `{$wpdb->users}` SET `user_email` = '' WHERE `user_email` IS NULL" );
96
97 Nabik_Net_Database::DB()->statement( "ALTER TABLE `{$wpdb->users}` MODIFY COLUMN `user_email` VARCHAR(100) NOT NULL DEFAULT ''" );
98
99 $site_host = parse_url( site_url(), PHP_URL_HOST );
100 $query = sprintf( "UPDATE `%s` SET `user_email` = '' WHERE `user_email` LIKE 'nomail%%%s'", $wpdb->users, $site_host );
101
102 Nabik_Net_Database::DB()->statement( $query );
103 }
104
105 }