|
1 | 1 | <?php |
2 | 2 |
|
3 | | -class DocumentAuthentication_Plugin |
4 | | - extends Pimcore_API_Plugin_Abstract |
5 | | - implements Pimcore_API_Plugin_Interface |
6 | | -{ |
| 3 | + namespace DocumentAuthentication; |
7 | 4 |
|
8 | | - const DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED |
9 | | - = 'documentAuthenticationEnabled'; |
| 5 | + use Pimcore\API\Plugin as PluginApi; |
| 6 | + use Pimcore\Db; |
| 7 | + use Pimcore\Model\Property\Predefined as PropertyPredefined; |
10 | 8 |
|
11 | | - const CONFIG_DOCUMENT_AUTHENTICATION_PASSWORD |
12 | | - = 'documentAuthenticationPassword'; |
| 9 | + class Plugin extends PluginApi\AbstractPlugin implements PluginApi\PluginInterface |
| 10 | + { |
13 | 11 |
|
14 | | - const CONFIG_DOCUMENT_AUTHENTICATION_USERNAME |
15 | | - = 'documentAuthenticationUser'; |
| 12 | + const DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED |
| 13 | + = 'documentAuthenticationEnabled'; |
16 | 14 |
|
17 | | - const DB_TABLE_WEBSITE_SETTINGS |
18 | | - = 'website_settings'; |
| 15 | + const CONFIG_DOCUMENT_AUTHENTICATION_PASSWORD |
| 16 | + = 'documentAuthenticationPassword'; |
19 | 17 |
|
20 | | - const DB_TABLE_PRE_PROPERTIES |
21 | | - = 'properties_predefined'; |
| 18 | + const CONFIG_DOCUMENT_AUTHENTICATION_USERNAME |
| 19 | + = 'documentAuthenticationUser'; |
22 | 20 |
|
23 | | - public function init() |
24 | | - { |
25 | | - Pimcore::getEventManager()->attach("system.startup", function ($event) { |
| 21 | + const DB_TABLE_WEBSITE_SETTINGS |
| 22 | + = 'website_settings'; |
26 | 23 |
|
27 | | - $front = Zend_Controller_Front::getInstance(); |
| 24 | + public function init() |
| 25 | + { |
| 26 | + \Pimcore::getEventManager()->attach("system.startup", function ($event) { |
28 | 27 |
|
29 | | - $frontControllerPlugin = new DocumentAuthentication_FrontControllerPlugin(); |
30 | | - $front->registerPlugin($frontControllerPlugin); |
31 | | - }); |
32 | | - } |
| 28 | + $front = \Zend_Controller_Front::getInstance(); |
33 | 29 |
|
34 | | - public static function install() |
35 | | - { |
| 30 | + $frontControllerPlugin = new FrontControllerPlugin(); |
| 31 | + $front->registerPlugin($frontControllerPlugin); |
| 32 | + }); |
| 33 | + } |
36 | 34 |
|
37 | | - $database = Pimcore_Resource_Mysql::getConnection(); |
38 | | - |
39 | | - if (!self::isInstalled()) { |
40 | | - |
41 | | - $database->insert(self::DB_TABLE_PRE_PROPERTIES, array( |
42 | | - 'name' => self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED, |
43 | | - 'key' => self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED, |
44 | | - 'type' => 'bool', |
45 | | - 'inheritable' => 1, |
46 | | - 'ctype' => 'document' |
47 | | - )); |
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 | | - )); |
| 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.'; |
60 | 63 | } |
61 | 64 |
|
62 | | - return 'Successfully installed plugin DocumentAuthentication.'; |
63 | | - } |
| 65 | + public static function uninstall() |
| 66 | + { |
| 67 | + $database = Db::get(); |
64 | 68 |
|
65 | | - public static function uninstall() |
66 | | - { |
67 | | - $database = Pimcore_Resource_Mysql::getConnection(); |
| 69 | + $prop = PropertyPredefined::getByKey(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED); |
| 70 | + $prop->delete(); |
68 | 71 |
|
69 | | - $sqlQuery = "DELETE FROM " . self::DB_TABLE_PRE_PROPERTIES . " WHERE name = ?"; |
70 | | - $database->query($sqlQuery, array(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED)); |
| 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)); |
71 | 75 |
|
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)); |
| 76 | + return 'Successfully removed plugin DocumentAuthentication.'; |
| 77 | + } |
75 | 78 |
|
76 | | - return 'Successfully removed plugin DocumentAuthentication.'; |
77 | | - } |
| 79 | + public static function isInstalled() |
| 80 | + { |
| 81 | + return (PropertyPredefined::getByKey(self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED) |
| 82 | + != null); |
| 83 | + } |
78 | 84 |
|
79 | | - public static function isInstalled() |
80 | | - { |
81 | | - $database = Pimcore_Resource_Mysql::getConnection(); |
82 | | - |
83 | | - $sqlQuery= "SELECT COUNT(id) as num FROM " . self::DB_TABLE_PRE_PROPERTIES . " WHERE name = ?"; |
84 | | - $isInstalled = ( |
85 | | - (int)$database->fetchOne( |
86 | | - $sqlQuery, |
87 | | - array( |
88 | | - self::DOC_PROPERTY_DOCUMENT_AUTHENTICATION_ENABLED |
89 | | - ) |
90 | | - ) > 0); |
91 | | - |
92 | | - return $isInstalled; |
93 | | - } |
| 85 | + public static function needsReloadAfterInstall() |
| 86 | + { |
| 87 | + return false; // backend only functionality! |
| 88 | + } |
94 | 89 |
|
95 | | - public static function needsReloadAfterInstall() |
96 | | - { |
97 | | - return false; // backend only functionality! |
98 | 90 | } |
99 | | - |
100 | | -} |
0 commit comments