PluginProbe
User Access Manager / 2.2.3
User Access Manager v2.2.3
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Setup/SetupHandler.php +82 -9 2.3.142.2.3 View file →
@@ -1,5 +1,18 @@
1 1 <?php
2 +/**
3 + * SetupHandler.php
4 + *
5 + * The SetupHandler class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <alexanderschneider85@gmail.com>
10 + * @copyright 2008-2017 Alexander Schneider
11 + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2
12 + * @version SVN: $id$
13 + * @link http://wordpress.org/extend/plugins/user-access-manager/
14 + */
2 15
3 16 declare(strict_types=1);
4 17
5 18 namespace UserAccessManager\Setup;
@@ -10,19 +23,66 @@
10 23 use UserAccessManager\Setup\Database\DatabaseHandler;
11 24 use UserAccessManager\Setup\Database\MissingColumnsException;
12 25 use UserAccessManager\Wrapper\Wordpress;
13 26
27 +/**
28 + * Class SetupHandler
29 + *
30 + * @package UserAccessManager\SetupHandler
31 + */
14 32 class SetupHandler
15 33 {
34 + /**
35 + * @var Wordpress
36 + */
37 + private $wordpress;
38 +
39 + /**
40 + * @var Database
41 + */
42 + private $database;
43 +
44 + /**
45 + * @var DatabaseHandler
46 + */
47 + private $databaseHandler;
48 +
49 + /**
50 + * @var MainConfig
51 + */
52 + private $mainConfig;
53 +
54 + /**
55 + * @var FileHandler
56 + */
57 + private $fileHandler;
58 +
59 + /**
60 + * SetupHandler constructor.
61 + * @param Wordpress $wordpress
62 + * @param Database $database
63 + * @param DatabaseHandler $databaseHandler
64 + * @param MainConfig $mainConfig
65 + * @param FileHandler $fileHandler
66 + */
16 67 public function __construct(
17 - private Wordpress $wordpress,
18 - private Database $database,
19 - private DatabaseHandler $databaseHandler,
20 - private MainConfig $mainConfig,
21 - private FileHandler $fileHandler
68 + Wordpress $wordpress,
69 + Database $database,
70 + DatabaseHandler $databaseHandler,
71 + MainConfig $mainConfig,
72 + FileHandler $fileHandler
22 73 ) {
74 + $this->wordpress = $wordpress;
75 + $this->database = $database;
76 + $this->databaseHandler = $databaseHandler;
77 + $this->mainConfig = $mainConfig;
78 + $this->fileHandler = $fileHandler;
23 79 }
24 80
81 + /**
82 + * Returns the database handler object.
83 + * @return DatabaseHandler
84 + */
25 85 public function getDatabaseHandler(): DatabaseHandler
26 86 {
27 87 return $this->databaseHandler;
28 88 }
@@ -27,8 +87,9 @@
27 87 return $this->databaseHandler;
28 88 }
29 89
30 90 /**
91 + * Returns all blog of the network.
31 92 * @return integer[]
32 93 */
33 94 public function getBlogIds(): array
34 95 {
@@ -43,19 +104,22 @@
43 104 return $blogIds;
44 105 }
45 106
46 107 /**
108 + * Creates the needed tables at the database and adds the options
47 109 * @throws MissingColumnsException
48 110 */
49 - private function runInstall(): void
111 + private function runInstall()
50 112 {
51 113 $this->databaseHandler->install();
52 114 }
53 115
54 116 /**
117 + * Installs the user access manager.
118 + * @param bool $networkWide
55 119 * @throws MissingColumnsException
56 120 */
57 - public function install(bool $networkWide = false): void
121 + public function install($networkWide = false)
58 122 {
59 123 if ($networkWide === true) {
60 124 $blogIds = $this->getBlogIds();
61 125
@@ -68,11 +132,15 @@
68 132 $this->runInstall();
69 133 }
70 134 }
71 135
136 + /**
137 + * Updates the user access manager if an old version was installed.
138 + * @return bool
139 + */
72 140 public function update(): bool
73 141 {
74 - $uamVersion = (string) $this->wordpress->getOption('uam_version', '0');
142 + $uamVersion = $this->wordpress->getOption('uam_version', '0');
75 143
76 144 if (version_compare($uamVersion, '1.0', '<') === true) {
77 145 $this->wordpress->deleteOption('allow_comments_locked');
78 146 }
@@ -84,11 +152,12 @@
84 152 return $this->databaseHandler->updateDatabase();
85 153 }
86 154
87 155 /**
156 + * Clean up wordpress if the plugin will be uninstalled.
88 157 * @throws MissingColumnsException
89 158 */
90 - public function uninstall(): void
159 + public function uninstall()
91 160 {
92 161 $blogIds = $this->getBlogIds();
93 162
94 163 foreach ($blogIds as $blogId) {
@@ -103,8 +172,12 @@
103 172
104 173 $this->fileHandler->deleteFileProtection();
105 174 }
106 175
176 + /**
177 + * Remove the htaccess file if the plugin is deactivated.
178 + * @return bool
179 + */
107 180 public function deactivate(): bool
108 181 {
109 182 return $this->fileHandler->deleteFileProtection();
110 183 }