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

112 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace UserAccessManager\Setup;
6
7 use UserAccessManager\Config\MainConfig;
8 use UserAccessManager\Database\Database;
9 use UserAccessManager\File\FileHandler;
10 use UserAccessManager\Setup\Database\DatabaseHandler;
11 use UserAccessManager\Setup\Database\MissingColumnsException;
12 use UserAccessManager\Wrapper\Wordpress;
13
14 class SetupHandler
15 {
16 public function __construct(
17 private Wordpress $wordpress,
18 private Database $database,
19 private DatabaseHandler $databaseHandler,
20 private MainConfig $mainConfig,
21 private FileHandler $fileHandler
22 ) {
23 }
24
25 public function getDatabaseHandler(): DatabaseHandler
26 {
27 return $this->databaseHandler;
28 }
29
30 /**
31 * @return integer[]
32 */
33 public function getBlogIds(): array
34 {
35 $currentBlogId = $this->database->getCurrentBlogId();
36 $blogIds = [$currentBlogId => $currentBlogId];
37 $sites = $this->wordpress->getSites();
38
39 foreach ($sites as $site) {
40 $blogIds[$site->blog_id] = $site->blog_id;
41 }
42
43 return $blogIds;
44 }
45
46 /**
47 * @throws MissingColumnsException
48 */
49 private function runInstall(): void
50 {
51 $this->databaseHandler->install();
52 }
53
54 /**
55 * @throws MissingColumnsException
56 */
57 public function install(bool $networkWide = false): void
58 {
59 if ($networkWide === true) {
60 $blogIds = $this->getBlogIds();
61
62 foreach ($blogIds as $blogId) {
63 $this->wordpress->switchToBlog($blogId);
64 $this->runInstall();
65 $this->wordpress->restoreCurrentBlog();
66 }
67 } else {
68 $this->runInstall();
69 }
70 }
71
72 public function update(): bool
73 {
74 $uamVersion = (string) $this->wordpress->getOption('uam_version', '0');
75
76 if (version_compare($uamVersion, '1.0', '<') === true) {
77 $this->wordpress->deleteOption('allow_comments_locked');
78 }
79
80 if (version_compare($uamVersion, '2.1.7', '<') === true) {
81 $this->mainConfig->setConfigParameters(['locked_directory_type' => 'all']);
82 }
83
84 return $this->databaseHandler->updateDatabase();
85 }
86
87 /**
88 * @throws MissingColumnsException
89 */
90 public function uninstall(): void
91 {
92 $blogIds = $this->getBlogIds();
93
94 foreach ($blogIds as $blogId) {
95 $this->wordpress->switchToBlog($blogId);
96 $this->databaseHandler->removeTables();
97
98 $this->wordpress->deleteOption(MainConfig::MAIN_CONFIG_KEY);
99 $this->wordpress->deleteOption('uam_version');
100 $this->wordpress->deleteOption('uam_db_version');
101 $this->wordpress->restoreCurrentBlog();
102 }
103
104 $this->fileHandler->deleteFileProtection();
105 }
106
107 public function deactivate(): bool
108 {
109 return $this->fileHandler->deleteFileProtection();
110 }
111 }
112