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

184 lines 4.4 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
124 foreach ($blogIds as $blogId) {
125 $this->wordpress->switchToBlog($blogId);
126 $this->runInstall();
127 $this->wordpress->restoreCurrentBlog();
128 }
129 } else {
130 $this->runInstall();
131 }
132 }
133
134 /**
135 * Updates the user access manager if an old version was installed.
136 *
137 * @return bool
138 */
139 public function update()
140 {
141 $uamVersion = $this->wordpress->getOption('uam_version', '0');
142
143 if (version_compare($uamVersion, '1.0', '<') === true) {
144 $this->wordpress->deleteOption('allow_comments_locked');
145 }
146
147 if (version_compare($uamVersion, '2.1.7', '<') === true) {
148 $this->mainConfig->setConfigParameters(['locked_directory_type' => 'all']);
149 }
150
151 return $this->databaseHandler->updateDatabase();
152 }
153
154 /**
155 * Clean up wordpress if the plugin will be uninstalled.
156 */
157 public function uninstall()
158 {
159 $blogIds = $this->getBlogIds();
160
161 foreach ($blogIds as $blogId) {
162 $this->wordpress->switchToBlog($blogId);
163 $this->databaseHandler->removeTables();
164
165 $this->wordpress->deleteOption(MainConfig::MAIN_CONFIG_KEY);
166 $this->wordpress->deleteOption('uam_version');
167 $this->wordpress->deleteOption('uam_db_version');
168 $this->wordpress->restoreCurrentBlog();
169 }
170
171 $this->fileHandler->deleteFileProtection();
172 }
173
174 /**
175 * Remove the htaccess file if the plugin is deactivated.
176 *
177 * @return bool
178 */
179 public function deactivate()
180 {
181 return $this->fileHandler->deleteFileProtection();
182 }
183 }
184