PluginProbe
User Access Manager / 2.1.11
User Access Manager v2.1.11
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 +92 -20 2.3.17 → 2.1.11 View file →
@@ -1,8 +1,18 @@
1 1 <?php
2 -
3 -declare(strict_types=1);
4 -
2 +/**
3 + * SetupHandler.php
4 + *
5 + * The SetupHandler class file.
6 + *
7 + * PHP versions 5
8 + *
9 + * @author Alexander Schneider <[email protected]>
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 + */
5 15 namespace UserAccessManager\Setup;
6 16
7 17 use UserAccessManager\Config\MainConfig;
8 18 use UserAccessManager\Database\Database;
@@ -7,31 +17,81 @@
7 17 use UserAccessManager\Config\MainConfig;
8 18 use UserAccessManager\Database\Database;
9 19 use UserAccessManager\File\FileHandler;
10 20 use UserAccessManager\Setup\Database\DatabaseHandler;
11 -use UserAccessManager\Setup\Database\MissingColumnsException;
12 21 use UserAccessManager\Wrapper\Wordpress;
13 22
23 +/**
24 + * Class SetupHandler
25 + *
26 + * @package UserAccessManager\SetupHandler
27 + */
14 28 class SetupHandler
15 29 {
30 + /**
31 + * @var Wordpress
32 + */
33 + private $wordpress;
34 +
35 + /**
36 + * @var Database
37 + */
38 + private $database;
39 +
40 + /**
41 + * @var DatabaseHandler
42 + */
43 + private $databaseHandler;
44 +
45 + /**
46 + * @var MainConfig
47 + */
48 + private $mainConfig;
49 +
50 + /**
51 + * @var FileHandler
52 + */
53 + private $fileHandler;
54 +
55 + /**
56 + * SetupHandler constructor.
57 + *
58 + * @param Wordpress $wordpress
59 + * @param Database $database
60 + * @param DatabaseHandler $databaseHandler
61 + * @param MainConfig $mainConfig
62 + * @param FileHandler $fileHandler
63 + */
16 64 public function __construct(
17 - private Wordpress $wordpress,
18 - private Database $database,
19 - private DatabaseHandler $databaseHandler,
20 - private MainConfig $mainConfig,
21 - private FileHandler $fileHandler
65 + Wordpress $wordpress,
66 + Database $database,
67 + DatabaseHandler $databaseHandler,
68 + MainConfig $mainConfig,
69 + FileHandler $fileHandler
22 70 ) {
71 + $this->wordpress = $wordpress;
72 + $this->database = $database;
73 + $this->databaseHandler = $databaseHandler;
74 + $this->mainConfig = $mainConfig;
75 + $this->fileHandler = $fileHandler;
23 76 }
24 77
25 - public function getDatabaseHandler(): DatabaseHandler
78 + /**
79 + * Returns the database handler object.
80 + *
81 + * @return DatabaseHandler
82 + */
83 + public function getDatabaseHandler()
26 84 {
27 85 return $this->databaseHandler;
28 86 }
29 87
30 88 /**
89 + * Returns all blog of the network.
90 + *
31 91 * @return integer[]
32 92 */
33 - public function getBlogIds(): array
93 + public function getBlogIds()
34 94 {
35 95 $currentBlogId = $this->database->getCurrentBlogId();
36 96 $blogIds = [$currentBlogId => $currentBlogId];
37 97 $sites = $this->wordpress->getSites();
@@ -43,19 +103,21 @@
43 103 return $blogIds;
44 104 }
45 105
46 106 /**
47 - * @throws MissingColumnsException
107 + * Creates the needed tables at the database and adds the options
48 108 */
49 - private function runInstall(): void
109 + private function runInstall()
50 110 {
51 111 $this->databaseHandler->install();
52 112 }
53 113
54 114 /**
55 - * @throws MissingColumnsException
115 + * Installs the user access manager.
116 + *
117 + * @param bool $networkWide
56 118 */
57 - public function install(bool $networkWide = false): void
119 + public function install($networkWide = false)
58 120 {
59 121 if ($networkWide === true) {
60 122 $blogIds = $this->getBlogIds();
61 123
@@ -68,11 +130,16 @@
68 130 $this->runInstall();
69 131 }
70 132 }
71 133
72 - public function update(): bool
134 + /**
135 + * Updates the user access manager if an old version was installed.
136 + *
137 + * @return bool
138 + */
139 + public function update()
73 140 {
74 - $uamVersion = (string) $this->wordpress->getOption('uam_version', '0');
141 + $uamVersion = $this->wordpress->getOption('uam_version', '0');
75 142
76 143 if (version_compare($uamVersion, '1.0', '<') === true) {
77 144 $this->wordpress->deleteOption('allow_comments_locked');
78 145 }
@@ -84,11 +151,11 @@
84 151 return $this->databaseHandler->updateDatabase();
85 152 }
86 153
87 154 /**
88 - * @throws MissingColumnsException
155 + * Clean up wordpress if the plugin will be uninstalled.
89 156 */
90 - public function uninstall(): void
157 + public function uninstall()
91 158 {
92 159 $blogIds = $this->getBlogIds();
93 160
94 161 foreach ($blogIds as $blogId) {
@@ -103,9 +170,14 @@
103 170
104 171 $this->fileHandler->deleteFileProtection();
105 172 }
106 173
107 - public function deactivate(): bool
174 + /**
175 + * Remove the htaccess file if the plugin is deactivated.
176 + *
177 + * @return bool
178 + */
179 + public function deactivate()
108 180 {
109 181 return $this->fileHandler->deleteFileProtection();
110 182 }
111 183 }