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

103 lines 2.7 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 public function install(bool $networkWide = false): void
50 {
51 if ($networkWide === false) {
52 $this->databaseHandler->install();
53 return;
54 }
55
56 foreach ($this->getBlogIds() as $blogId) {
57 $this->wordpress->switchToBlog($blogId);
58 $this->databaseHandler->install();
59 $this->wordpress->restoreCurrentBlog();
60 }
61 }
62
63 public function update(): bool
64 {
65 $uamVersion = (string) $this->wordpress->getOption('uam_version', '0');
66
67 if (version_compare($uamVersion, '1.0', '<') === true) {
68 $this->wordpress->deleteOption('allow_comments_locked');
69 }
70
71 if (version_compare($uamVersion, '2.1.7', '<') === true) {
72 $this->mainConfig->setConfigParameters(['locked_directory_type' => 'all']);
73 }
74
75 return $this->databaseHandler->updateDatabase();
76 }
77
78 /**
79 * @throws MissingColumnsException
80 */
81 public function uninstall(): void
82 {
83 $blogIds = $this->getBlogIds();
84
85 foreach ($blogIds as $blogId) {
86 $this->wordpress->switchToBlog($blogId);
87 $this->databaseHandler->removeTables();
88
89 $this->wordpress->deleteOption(MainConfig::MAIN_CONFIG_KEY);
90 $this->wordpress->deleteOption('uam_version');
91 $this->wordpress->deleteOption('uam_db_version');
92 $this->wordpress->restoreCurrentBlog();
93 }
94
95 $this->fileHandler->deleteFileProtection();
96 }
97
98 public function deactivate(): bool
99 {
100 return $this->fileHandler->deleteFileProtection();
101 }
102 }
103