Issues (752)

server/includes/modules/class.settingsmodule.php (1 issue)

1
<?php
2
3
/**
4
 * Settings Module.
5
 */
6
class SettingsModule extends Module {
7
	/**
8
	 * Constructor.
9
	 *
10
	 * @param int   $id   unique id
11
	 * @param array $data list of all actions
12
	 */
13
	public function __construct($id, $data) {
14
		parent::__construct($id, $data);
15
	}
16
17
	/**
18
	 * Executes all the actions in the $data variable.
19
	 */
20
	#[Override]
21
	public function execute() {
22
		foreach ($this->data as $actionType => $action) {
23
			if (isset($actionType)) {
24
				try {
25
					switch ($actionType) {
26
						case "retrieveAll":
27
							$this->retrieveAll($actionType);
28
							break;
29
30
						case "set":
31
							if (isset($action["setting"])) {
32
								$this->set($action["setting"], false);
33
							}
34
							if (isset($action["persistentSetting"])) {
35
								$this->set($action["persistentSetting"], true);
36
							}
37
							break;
38
39
						case "delete":
40
						case "reset":
41
							$userStore = $GLOBALS['mapisession']->getDefaultMessageStore();
42
							$inbox = mapi_msgstore_getreceivefolder($userStore);
43
							mapi_deleteprops($inbox, [PR_ADDITIONAL_REN_ENTRYIDS_EX, PR_ADDITIONAL_REN_ENTRYIDS]);
44
							$this->delete($action["setting"]);
45
							break;
46
47
						default:
48
							$this->handleUnknownActionType($actionType);
49
					}
50
				}
51
				catch (MAPIException|SettingsException $e) {
52
					$this->processException($e, $actionType);
53
				}
54
			}
55
		}
56
	}
57
58
	/**
59
	 * Function will retrieve all settings stored in PR_EC_WEBACCESS_SETTINGS_JSON property
60
	 * if property is not defined then it will return generate SettingsException but silently ignores it.
61
	 *
62
	 * @param mixed $type
63
	 */
64
	public function retrieveAll($type) {
65
		$data = $GLOBALS['settings']->get();
66
67
		$this->addActionData($type, $data);
68
		$GLOBALS["bus"]->addData($this->getResponseData());
69
	}
70
71
	/**
72
	 * Function will set a value of a setting indicated by path of the setting.
73
	 *
74
	 * @param mixed $settings   Object containing a $path and $value of the setting
75
	 *                          which must be modified
76
	 * @param bool  $persistent If true the settings will be stored in the persistent settings
77
	 *                          as opposed to the normal settings
78
	 */
79
	public function set($settings, $persistent = false) {
80
		if (isset($settings)) {
81
			// we will set the settings but wait with saving until the entire batch has been applied.
82
			if (is_array($settings)) {
83
				foreach ($settings as $setting) {
84
					if (isset($setting['path'], $setting['value'])) {
85
						if ((bool) $persistent) {
86
							$GLOBALS['settings']->setPersistent($setting['path'], $setting['value']);
87
						}
88
						else {
89
							$GLOBALS['settings']->set($setting['path'], $setting['value']);
90
						}
91
					}
92
				}
93
			}
94
			elseif (isset($settings['path'], $settings['value'])) {
95
				if ((bool) $persistent) {
96
					$GLOBALS['settings']->setPersistent($settings['path'], $settings['value']);
97
				}
98
				else {
99
					$GLOBALS['settings']->set($settings['path'], $settings['value']);
100
				}
101
			}
102
103
			// Finally save the settings, this can throw exception when it fails saving settings
104
			if ((bool) $persistent) {
105
				$GLOBALS['settings']->savePersistentSettings();
106
			}
107
			else {
108
				$GLOBALS['settings']->saveSettings();
109
			}
110
111
			// send success notification to client
112
			$this->sendFeedback(true);
113
		}
114
	}
115
116
	/**
117
	 * Function will delete a setting indicated by setting path.
118
	 *
119
	 * @param $path string/array path of the setting that needs to be deleted
0 ignored issues
show
Documentation Bug introduced by
The doc comment string/array at position 0 could not be parsed: Unknown type name 'string/array' at position 0 in string/array.
Loading history...
120
	 */
121
	public function delete($path) {
122
		if (isset($path)) {
123
			// we will delete the settings but wait with saving until the entire batch has been applied.
124
			if (is_array($path)) {
125
				foreach ($path as $item) {
126
					$GLOBALS['settings']->delete($item);
127
				}
128
			}
129
			else {
130
				$GLOBALS['settings']->delete($path);
131
			}
132
133
			// Finally save the settings, this can throw exception when it fails saving settings
134
			$GLOBALS['settings']->saveSettings();
135
136
			// send success notification to client
137
			$this->sendFeedback(true);
138
		}
139
	}
140
}
141