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

178 lines 4.3 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\Object\ObjectHandler;
21 use UserAccessManager\Setup\Database\DatabaseHandler;
22 use UserAccessManager\Wrapper\Wordpress;
23
24 /**
25 * Class SetupHandler
26 *
27 * @package UserAccessManager\SetupHandler
28 */
29 class SetupHandler
30 {
31 /**
32 * @var Wordpress
33 */
34 private $wordpress;
35
36 /**
37 * @var Database
38 */
39 private $database;
40
41 /**
42 * @var DatabaseHandler
43 */
44 private $databaseHandler;
45
46 /**
47 * @var FileHandler
48 */
49 private $fileHandler;
50
51 /**
52 * SetupHandler constructor.
53 *
54 * @param Wordpress $wordpress
55 * @param Database $database
56 * @param DatabaseHandler $databaseHandler
57 * @param ObjectHandler $objectHandler
58 * @param FileHandler $fileHandler
59 */
60 public function __construct(
61 Wordpress $wordpress,
62 Database $database,
63 DatabaseHandler $databaseHandler,
64 ObjectHandler $objectHandler,
65 FileHandler $fileHandler
66 ) {
67 $this->wordpress = $wordpress;
68 $this->database = $database;
69 $this->databaseHandler = $databaseHandler;
70 $this->fileHandler = $fileHandler;
71 }
72
73 /**
74 * Returns the database handler object.
75 *
76 * @return DatabaseHandler
77 */
78 public function getDatabaseHandler()
79 {
80 return $this->databaseHandler;
81 }
82
83 /**
84 * Returns all blog of the network.
85 *
86 * @return integer[]
87 */
88 public function getBlogIds()
89 {
90 $currentBlogId = $this->database->getCurrentBlogId();
91 $blogIds = [$currentBlogId => $currentBlogId];
92 $sites = $this->wordpress->getSites();
93
94 foreach ($sites as $site) {
95 $blogIds[$site->blog_id] = $site->blog_id;
96 }
97
98 return $blogIds;
99 }
100
101 /**
102 * Creates the needed tables at the database and adds the options
103 */
104 private function runInstall()
105 {
106 $this->databaseHandler->install();
107 }
108
109 /**
110 * Installs the user access manager.
111 *
112 * @param bool $networkWide
113 */
114 public function install($networkWide = false)
115 {
116 if ($networkWide === true) {
117 $blogIds = $this->getBlogIds();
118 $currentBlogId = $this->database->getCurrentBlogId();
119
120 foreach ($blogIds as $blogId) {
121 $this->wordpress->switchToBlog($blogId);
122 $this->runInstall();
123 }
124
125 $this->wordpress->switchToBlog($currentBlogId);
126 } else {
127 $this->runInstall();
128 }
129 }
130
131 /**
132 * Updates the user access manager if an old version was installed.
133 *
134 * @return bool
135 */
136 public function update()
137 {
138 $uamVersion = $this->wordpress->getOption('uam_version', '0');
139
140 if (version_compare($uamVersion, '1.0', '<') === true) {
141 $this->wordpress->deleteOption('allow_comments_locked');
142 }
143
144 return $this->databaseHandler->updateDatabase();
145 }
146
147 /**
148 * Clean up wordpress if the plugin will be uninstalled.
149 */
150 public function uninstall()
151 {
152 $currentBlogId = $this->database->getCurrentBlogId();
153 $blogIds = $this->getBlogIds();
154
155 foreach ($blogIds as $blogId) {
156 $this->wordpress->switchToBlog($blogId);
157 $this->databaseHandler->removeTables();
158
159 $this->wordpress->deleteOption(MainConfig::MAIN_CONFIG_KEY);
160 $this->wordpress->deleteOption('uam_version');
161 $this->wordpress->deleteOption('uam_db_version');
162 }
163
164 $this->wordpress->switchToBlog($currentBlogId);
165 $this->fileHandler->deleteFileProtection();
166 }
167
168 /**
169 * Remove the htaccess file if the plugin is deactivated.
170 *
171 * @return bool
172 */
173 public function deactivate()
174 {
175 return $this->fileHandler->deleteFileProtection();
176 }
177 }
178