Issues (762)

extensions/permissioninstaller.php (1 issue)

Severity
1
<?php
2
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: RocketCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 10.04.2018
25
 * Time: 18:34
26
 */
27
28
class PermissionInstaller extends PluginInstaller_Plugin {
29
30
	public function install(Plugin $plugin, array $install_json): bool {
31
		if (isset($install_json['permissions'])) {
32
			$permissions = $install_json['permissions'];
33
34
			foreach ($permissions as $permission) {
35
				$token = $permission['token'];
36
				$title = $permission['title'];
37
				$description = $permission['description'];
38
				$category = (isset($permission['category']) ? $permission['category'] : "plugins");
39
				$order = (isset($permission['order']) ? intval($permission['order']) : 100);
40
41
				Permissions::createPermission($token, $title, $description, $category, "plugin_" . $plugin->getName(), $order);
42
			}
43
		}
44
45
		return true;
46
	}
47
48
	public function uninstall(Plugin $plugin, array $install_json): bool {
49
		//delete permissions with plugin owner
50
		if (isset($install_json['permissions'])) {
51
			Permissions::deletePermissionsByOwner("plugin_" . $plugin->getName());
52
		}
53
54
		return true;
55
	}
56
57
	public function upgrade(Plugin $plugin, array $install_json): bool {
58
		//TODO: remove permissions, which arent longer in install json
59
60
		//install queries supports ON DUPLICATE KEY
61
		return $this->install($plugin, $install_json);
62
	}
63
64
}
65
66
?>
0 ignored issues
show
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
67