Completed
Pull Request — master (#2233)
by Revin
64:12
created

Uninstaller   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 57
c 0
b 0
f 0
wmc 5
lcom 1
cbo 3
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A uninstall() 0 14 1
A deleteBackendNavigation() 0 7 1
A deleteFrontendFilesDirectories() 0 8 1
A deleteFrontendPages() 0 22 2
1
<?php
2
3
namespace Backend\Modules\Profiles\Installer;
4
5
/*
6
 * This file is part of Fork CMS.
7
 *
8
 * For the full copyright and license information, please view the license
9
 * file that was distributed with this source code.
10
 */
11
12
use Backend\Core\Installer\ModuleUninstaller;
13
use Backend\Core\Installer\UninstallerInterface;
14
use Backend\Core\Language\Language;
15
use Symfony\Component\Filesystem\Filesystem;
16
17
/**
18
 * Uninstaller for the profiles module.
19
 */
20
class Uninstaller extends ModuleUninstaller implements UninstallerInterface
21
{
22
    public function uninstall(): void
23
    {
24
        $this->setModule('Profiles');
25
26
        $this->deleteFrontendFilesDirectories();
27
        $this->deleteFrontendPages();
28
        $this->deleteBackendNavigation();
29
30
        $this->dropDatabase([
31
            'profiles_settings', 'profiles_sessions', 'profiles_groups_rights', 'profiles_groups', 'profiles',
32
        ]);
33
34
        $this->dropModule();
35
    }
36
37
    private function deleteBackendNavigation(): void
38
    {
39
        $this->deleteNavigation('Modules.' . $this->getModule() . '.Overview');
40
        $this->deleteNavigation('Modules.' . $this->getModule() . '.Groups');
41
        $this->deleteNavigation('Modules.' . $this->getModule());
42
        $this->deleteNavigation('Settings.Modules.' . $this->getModule());
43
    }
44
45
    private function deleteFrontendFilesDirectories(): void
46
    {
47
        $filesystem = new Filesystem();
48
        $filesystem->remove(PATH_WWW . '/src/Frontend/Files/Profiles/Avatars/source/');
49
        $filesystem->remove(PATH_WWW . '/src/Frontend/Files/Profiles/Avatars/240x240/');
50
        $filesystem->remove(PATH_WWW . '/src/Frontend/Files/Profiles/Avatars/64x64/');
51
        $filesystem->remove(PATH_WWW . '/src/Frontend/Files/Profiles/Avatars/32x32/');
52
    }
53
54
    private function deleteFrontendPages(): void
55
    {
56
        foreach ($this->getLanguages() as $language) {
57
            // We must define the locale we want to insert the page into
58
            Language::setLocale($language);
59
60
            /** @noinspection DisconnectedForeachInstructionInspection */
61
            $this->deletePages([
62
                ucfirst(Language::lbl('Profile')),
63
                ucfirst(Language::lbl('Activate')),
64
                ucfirst(Language::lbl('ForgotPassword')),
65
                ucfirst(Language::lbl('ResetPassword')),
66
                ucfirst(Language::lbl('ResendActivation')),
67
                ucfirst(Language::lbl('Login')),
68
                ucfirst(Language::lbl('Register')),
69
                ucfirst(Language::lbl('Logout')),
70
                ucfirst(Language::lbl('ProfileSettings')),
71
                ucfirst(Language::lbl('ChangeEmail')),
72
                ucfirst(Language::lbl('ChangePassword')),
73
            ]);
74
        }
75
    }
76
}
77