Passed
Push — master ( 2da942...d633d7 )
by Paul
15:03 queued 05:40
created

Migrate_4_0_2::deleteSessions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules\Migrations;
4
5
use GeminiLabs\SiteReviews\Database\OptionManager;
6
use GeminiLabs\SiteReviews\Helpers\Arr;
7
8
class Migrate_4_0_2
9
{
10
    /**
11
     * @return void
12
     */
13 7
    public function deleteSessions()
14
    {
15 7
        global $wpdb;
16 7
        $wpdb->query("
17
            DELETE
18 7
            FROM {$wpdb->options}
19
            WHERE option_name LIKE '_glsr_session%'
20
        ");
21 7
    }
22
23
    /**
24
     * @return void
25
     */
26 7
    public function migrateSettings()
27
    {
28 7
        if ($settings = get_option(OptionManager::databaseKey(3))) {
29
            $multilingual = 'yes' == Arr::get($settings, 'settings.general.support.polylang')
30
                ? 'polylang'
31
                : '';
32
            $settings = Arr::set($settings, 'settings.general.multilingual', $multilingual);
33
            $settings = Arr::set($settings, 'settings.general.rebusify', 'no');
34
            $settings = Arr::set($settings, 'settings.general.rebusify_email', '');
35
            $settings = Arr::set($settings, 'settings.general.rebusify_serial', '');
36
            $settings = Arr::set($settings, 'settings.reviews.name.format', '');
37
            $settings = Arr::set($settings, 'settings.reviews.name.initial', '');
38
            $settings = Arr::set($settings, 'settings.submissions.blacklist.integration', '');
39
            $settings = Arr::set($settings, 'settings.submissions.limit', '');
40
            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.email', '');
41
            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.ip_address', '');
42
            $settings = Arr::set($settings, 'settings.submissions.limit_whitelist.username', '');
43
            unset($settings['settings']['general']['support']);
44
            update_option(OptionManager::databaseKey(4), $settings);
45
        }
46 7
    }
47
48
    /**
49
     * @return void
50
     */
51 7
    public function protectMetaKeys()
52
    {
53 7
        global $wpdb;
54 7
        $postType = glsr()->post_type;
55 7
        $wpdb->query("
56 7
            UPDATE {$wpdb->postmeta} pm
57 7
            INNER JOIN {$wpdb->posts} p ON p.id = pm.post_id
58
            SET pm.meta_key = CONCAT('_', pm.meta_key)
59
            WHERE pm.meta_key IN ('assigned_to','author','avatar','content','custom','date','email','ip_address','pinned','rating','response','review_id','review_type','title','url')
60 7
            AND p.post_type = '{$postType}'
61
        ");
62 7
    }
63
64
    /**
65
     * @return bool
66
     */
67 7
    public function run()
68
    {
69 7
        $this->migrateSettings();
70 7
        $this->protectMetaKeys();
71 7
        $this->deleteSessions();
72 7
        delete_transient(glsr()->id.'_cloudflare_ips');
73 7
        return true;
74
    }
75
}
76