PluginProbe
User Access Manager / 2.1.9
User Access Manager v2.1.9
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.1.9, at src/Setup/SetupHandler.php

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