Test Failed
Push — main ( 6646cf...aabacf )
by Paul
14:17 queued 05:58
created

MainController::onMigrationEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 1
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Controllers;
4
5
use GeminiLabs\SiteReviews\Commands\RegisterPostMeta;
6
use GeminiLabs\SiteReviews\Commands\RegisterPostType;
7
use GeminiLabs\SiteReviews\Commands\RegisterShortcodes;
8
use GeminiLabs\SiteReviews\Commands\RegisterTaxonomy;
9
use GeminiLabs\SiteReviews\Commands\RegisterWidgets;
10
use GeminiLabs\SiteReviews\Database\OptionManager;
11
use GeminiLabs\SiteReviews\Database\Tables;
12
use GeminiLabs\SiteReviews\Helpers\Arr;
13
use GeminiLabs\SiteReviews\Install;
14
15
class MainController extends AbstractController
16
{
17
    /**
18
     * switch_to_blog() has run before this hook is triggered.
19
     *
20
     * @see http://developer.wordpress.org/reference/functions/wp_uninitialize_site/
21
     *
22
     * @param string[] $tables
23
     *
24
     * @return string[]
25
     *
26
     * @filter wpmu_drop_tables:999
27
     */
28
    public function filterDropTables(array $tables): array
29
    {
30
        // Custom tables have foreign indexes so they must be removed first!
31
        foreach (glsr(Tables::class)->tables() as $classname) {
32
            $table = glsr($classname);
33
            $tables = Arr::prepend($tables, $table->tablename, $table->name($prefixName = true));
34
        }
35
        return $tables;
36
    }
37
38
    /**
39
     * @action wp_initialize_site:999
40
     */
41
    public function installOnNewSite(\WP_Site $site): void
42
    {
43
        if (is_plugin_active_for_network(glsr()->basename)) {
44
            glsr(Install::class)->runOnSite($site->blog_id);
45
        }
46
    }
47
48
    /**
49
     * @param ?string $data We are not enforcing the type because the "wp_footer" hook does not have a parameter
50
     *
51
     * @action admin_footer
52
     * @action wp_footer
53
     */
54
    public function logOnce($data = ''): void
55
    {
56
        if ('update.php' !== $data) {
57
            glsr_log()->logOnce();
58
        }
59
    }
60
61
    /**
62
     * Initialize the Application settings config and defaults.
63
     *
64
     * @action init:5
65
     */
66
    public function onInit(): void
67
    {
68
        $defaults = glsr()->defaults();
69
        glsr(OptionManager::class)->mergeDefaults($defaults);
70
        glsr(OptionManager::class)->updateVersion();
71
    }
72
73
    /**
74
     * @action site-reviews/migration/end
75
     */
76
    public function onMigrationEnd(): void
77
    {
78
        $settings = glsr(OptionManager::class)->wp(OptionManager::databaseKey(), []);
79
        $settings = glsr(OptionManager::class)->clean($settings);
80
        update_option(OptionManager::databaseKey(), $settings, true);
81
    }
82
83
    /**
84
     * @action plugins_loaded
85
     */
86
    public function registerAddons(): void
87
    {
88
        glsr()->action('addon/register', glsr());
89
    }
90
91
    /**
92
     * Languages are loaded before "init" because the setting config uses translated strings.
93
     *
94
     * @action after_setup_theme
95
     */
96
    public function registerLanguages(): void
97
    {
98
        load_plugin_textdomain(glsr()->id, false,
99
            trailingslashit(plugin_basename(glsr()->path()).'/'.glsr()->languages)
100
        );
101
    }
102
103
    /**
104
     * @action init
105
     */
106
    public function registerPostMeta(): void
107
    {
108
        $this->execute(new RegisterPostMeta());
109
    }
110
111
    /**
112
     * @action init
113
     */
114
    public function registerPostType(): void
115
    {
116
        $this->execute(new RegisterPostType());
117
    }
118
119
    /**
120
     * @action init
121
     */
122
    public function registerReviewTypes(): void
123
    {
124
        $types = glsr()->filterArray('review/types', []);
125
        $types = wp_parse_args($types, [
126
            'local' => _x('Local Review', 'admin-text', 'site-reviews'),
127
        ]);
128
        glsr()->store('review_types', $types);
129
    }
130
131
    /**
132
     * @action init
133
     */
134
    public function registerShortcodes(): void
135
    {
136
        $this->execute(new RegisterShortcodes());
137
    }
138
139
    /**
140
     * @action init
141
     */
142
    public function registerTaxonomy(): void
143
    {
144
        $this->execute(new RegisterTaxonomy());
145
    }
146
147
    /**
148
     * @action widgets_init
149
     */
150
    public function registerWidgets(): void
151
    {
152
        $this->execute(new RegisterWidgets());
153
    }
154
}
155