Plugin   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 82
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 1
B install() 0 29 2
A uninstall() 0 13 1
A isInstalled() 0 5 1
A needsReloadAfterInstall() 0 4 1
1
<?php
2
3
    namespace DocumentAuthentication;
4
5
    use Pimcore\API\Plugin as PluginApi;
6
    use Pimcore\Db;
7
    use Pimcore\Model\Property\Predefined as PropertyPredefined;
8
9
    class Plugin extends PluginApi\AbstractPlugin implements PluginApi\PluginInterface
10
    {
11
12
        const DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED
13
            = 'documentAuthenticationEnabled';
14
15
        const CONFIG_DOCUMENT_AUTHENTICATION_PASSWORD
16
            = 'documentAuthenticationPassword';
17
18
        const CONFIG_DOCUMENT_AUTHENTICATION_USERNAME
19
            = 'documentAuthenticationUser';
20
21
        const DB_TABLE_WEBSITE_SETTINGS
22
            = 'website_settings';
23
24
        public function init()
25
        {
26
            \Pimcore::getEventManager()->attach("system.startup", function ($event) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
27
28
                $front = \Zend_Controller_Front::getInstance();
29
30
                $frontControllerPlugin = new FrontControllerPlugin();
31
                $front->registerPlugin($frontControllerPlugin);
32
            });
33
        }
34
35
        public static function install()
36
        {
37
            $database = Db::get();
38
39
            if (!self::isInstalled()) {
40
41
                $prop = new PropertyPredefined();
42
                $prop->setName(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED);
43
                $prop->setKey(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED);
44
                $prop->setType('bool');
45
                $prop->setInheritable(1);
46
                $prop->setCtype('document');
47
                $prop->save();
48
49
                $database->insert(self::DB_TABLE_WEBSITE_SETTINGS, array(
50
                    'name' => self::CONFIG_DOCUMENT_AUTHENTICATION_USERNAME,
51
                    'type' => 'text',
52
                    'data' => 'preview'
53
                ));
54
55
                $database->insert(self::DB_TABLE_WEBSITE_SETTINGS, array(
56
                    'name' => self::CONFIG_DOCUMENT_AUTHENTICATION_PASSWORD,
57
                    'type' => 'text',
58
                    'data' => md5(uniqid('', true))
59
                ));
60
            }
61
62
            return 'Successfully installed plugin DocumentAuthentication.';
63
        }
64
65
        public static function uninstall()
66
        {
67
            $database = Db::get();
68
69
            $prop = PropertyPredefined::getByKey(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED);
70
            $prop->delete();
71
72
            $sqlQuery = "DELETE FROM " . self::DB_TABLE_WEBSITE_SETTINGS . " WHERE name = ?";
73
            $database->query($sqlQuery, array(self::CONFIG_DOCUMENT_AUTHENTICATION_USERNAME));
74
            $database->query($sqlQuery, array(self::CONFIG_DOCUMENT_AUTHENTICATION_PASSWORD));
75
76
            return 'Successfully removed plugin DocumentAuthentication.';
77
        }
78
79
        public static function isInstalled()
80
        {
81
            return (PropertyPredefined::getByKey(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED)
82
                != null);
83
        }
84
85
        public static function needsReloadAfterInstall()
86
        {
87
            return false; // backend only functionality!
88
        }
89
90
    }
91