PluginProbe
User Access Manager / 2.2.12
User Access Manager v2.2.12
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
user-access-manager / src / Setup / SetupHandler.php

SetupHandler.php in User Access Manager 2.2.12, at src/Setup/SetupHandler.php

185 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 */
15
16 declare(strict_types=1);
17
18 namespace UserAccessManager\Setup;
19
20 use UserAccessManager\Config\MainConfig;
21 use UserAccessManager\Database\Database;
22 use UserAccessManager\File\FileHandler;
23 use UserAccessManager\Setup\Database\DatabaseHandler;
24 use UserAccessManager\Setup\Database\MissingColumnsException;
25 use UserAccessManager\Wrapper\Wordpress;
26
27 /**
28 * Class SetupHandler
29 *
30 * @package UserAccessManager\SetupHandler
31 */
32 class SetupHandler
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 */
67 public function __construct(
68 Wordpress $wordpress,
69 Database $database,
70 DatabaseHandler $databaseHandler,
71 MainConfig $mainConfig,
72 FileHandler $fileHandler
73 ) {
74 $this->wordpress = $wordpress;
75 $this->database = $database;
76 $this->databaseHandler = $databaseHandler;
77 $this->mainConfig = $mainConfig;
78 $this->fileHandler = $fileHandler;
79 }
80
81 /**
82 * Returns the database handler object.
83 * @return DatabaseHandler
84 */
85 public function getDatabaseHandler(): DatabaseHandler
86 {
87 return $this->databaseHandler;
88 }
89
90 /**
91 * Returns all blog of the network.
92 * @return integer[]
93 */
94 public function getBlogIds(): array
95 {
96 $currentBlogId = $this->database->getCurrentBlogId();
97 $blogIds = [$currentBlogId => $currentBlogId];
98 $sites = $this->wordpress->getSites();
99
100 foreach ($sites as $site) {
101 $blogIds[$site->blog_id] = $site->blog_id;
102 }
103
104 return $blogIds;
105 }
106
107 /**
108 * Creates the needed tables at the database and adds the options
109 * @throws MissingColumnsException
110 */
111 private function runInstall()
112 {
113 $this->databaseHandler->install();
114 }
115
116 /**
117 * Installs the user access manager.
118 * @param bool $networkWide
119 * @throws MissingColumnsException
120 */
121 public function install($networkWide = false)
122 {
123 if ($networkWide === true) {
124 $blogIds = $this->getBlogIds();
125
126 foreach ($blogIds as $blogId) {
127 $this->wordpress->switchToBlog($blogId);
128 $this->runInstall();
129 $this->wordpress->restoreCurrentBlog();
130 }
131 } else {
132 $this->runInstall();
133 }
134 }
135
136 /**
137 * Updates the user access manager if an old version was installed.
138 * @return bool
139 */
140 public function update(): bool
141 {
142 $uamVersion = $this->wordpress->getOption('uam_version', '0');
143
144 if (version_compare($uamVersion, '1.0', '<') === true) {
145 $this->wordpress->deleteOption('allow_comments_locked');
146 }
147
148 if (version_compare($uamVersion, '2.1.7', '<') === true) {
149 $this->mainConfig->setConfigParameters(['locked_directory_type' => 'all']);
150 }
151
152 return $this->databaseHandler->updateDatabase();
153 }
154
155 /**
156 * Clean up wordpress if the plugin will be uninstalled.
157 * @throws MissingColumnsException
158 */
159 public function uninstall()
160 {
161 $blogIds = $this->getBlogIds();
162
163 foreach ($blogIds as $blogId) {
164 $this->wordpress->switchToBlog($blogId);
165 $this->databaseHandler->removeTables();
166
167 $this->wordpress->deleteOption(MainConfig::MAIN_CONFIG_KEY);
168 $this->wordpress->deleteOption('uam_version');
169 $this->wordpress->deleteOption('uam_db_version');
170 $this->wordpress->restoreCurrentBlog();
171 }
172
173 $this->fileHandler->deleteFileProtection();
174 }
175
176 /**
177 * Remove the htaccess file if the plugin is deactivated.
178 * @return bool
179 */
180 public function deactivate(): bool
181 {
182 return $this->fileHandler->deleteFileProtection();
183 }
184 }
185