Passed
Push — master ( f66da6...7a87af )
by
unknown
02:36 queued 15s
created

class.freebusy.php (9 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * This class is just static class and will not be instantiate and
5
 * It contains the functionality to get freebusy message and folder.
6
 */
7
class FreeBusy {
8
	/**
9
	 *  PR_FREEBUSY_ENTRYIDS contains 4 entryids
10
	 *	PR_FREEBUSY_ENTRYIDS[0] gives associated freebusy folder in calendar
11
	 *	PR_FREEBUSY_ENTRYIDS[1] Localfreebusy (used for delegate properties)
12
	 *	PR_FREEBUSY_ENTRYIDS[2] global Freebusydata in public store
13
	 *	PR_FREEBUSY_ENTRYIDS[3] Freebusydata in IPM_SUBTREE.
14
	 */
15
	public const ASSOCIATED_FREEBUSY_FOLDER = 0;
16
	public const DELEGATE_PROPERTIES = 1;
17
	public const GLOBAL_FREEBUSYDATA = 2;
18
	public const FREEBUSYDATA_IPM_SUBTREE = 3;
19
20
	/**
21
	 * Function will return resource of the local freebusy message of the user's store.
22
	 *
23
	 * @param mixed $store (optional) user's store
24
	 *
25
	 * @return bool|resource local freebusy message, otherwise false if message not found
26
	 */
27
	public static function getLocalFreeBusyMessage($store = false) {
28
		if (!$store) {
29
			error_log("getLocalFreeBusyMessage: store not available");
30
31
			return false;
32
		}
33
34
		// Check for mapi_freebusy_openmsg function,
35
		// If yes then use mapi function to get freebusy message.
36
		if (function_exists('mapi_freebusy_openmsg')) {
37
			return mapi_freebusy_openmsg($store);
38
		}
39
40
		// Get 'LocalFreeBusy' message from FreeBusy Store
41
		$root = mapi_msgstore_openentry($store, null);
0 ignored issues
show
The function mapi_msgstore_openentry was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
		$root = /** @scrutinizer ignore-call */ mapi_msgstore_openentry($store, null);
Loading history...
42
		$storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]);
0 ignored issues
show
The function mapi_getprops was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
		$storeProps = /** @scrutinizer ignore-call */ mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]);
Loading history...
43
		$localFreeBusyEntryids = $storeProps[PR_FREEBUSY_ENTRYIDS];
44
45
		try {
46
			return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]);
47
		}
48
		catch (MAPIException $e) {
49
			// Either user store have malformed entryid in PR_FREEBUSY_ENTRYIDS or
50
			// No message found of given entryid in 'Freebusy Data' folder.
51
			if ($e->getCode() == MAPI_E_NOT_FOUND || $e->getCode() == MAPI_E_INVALID_ENTRYID) {
52
				$freeBusyFolder = mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::FREEBUSYDATA_IPM_SUBTREE]);
53
				$table = mapi_folder_getcontentstable($freeBusyFolder);
0 ignored issues
show
The function mapi_folder_getcontentstable was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
				$table = /** @scrutinizer ignore-call */ mapi_folder_getcontentstable($freeBusyFolder);
Loading history...
54
				mapi_table_restrict(
0 ignored issues
show
The function mapi_table_restrict was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
				/** @scrutinizer ignore-call */ 
55
    mapi_table_restrict(
Loading history...
55
					$table,
56
					[
57
						RES_CONTENT,
58
						[
59
							FUZZYLEVEL => FL_PREFIX,
60
							ULPROPTAG => PR_MESSAGE_CLASS,
61
							VALUE => [PR_MESSAGE_CLASS => "IPM.Microsoft.ScheduleData.FreeBusy"],
62
						],
63
					]
64
				);
65
66
				$items = mapi_table_queryallrows($table, [PR_ENTRYID]);
0 ignored issues
show
The function mapi_table_queryallrows was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
				$items = /** @scrutinizer ignore-call */ mapi_table_queryallrows($table, [PR_ENTRYID]);
Loading history...
67
				if (empty($items)) {
68
					// FIXME recreate local freebusy message in 'Freebusy Data' folder.
69
					error_log("Unable to find local free busy message in 'Freebusy Data' folder");
70
71
					return false;
72
				}
73
74
				$localFreeBusyEntryids[1] = $items[0][PR_ENTRYID];
75
76
				// Updating the entryid in the PR_FREEBUSY_ENTRYIDS property of user store.
77
				mapi_setprops($root, [PR_FREEBUSY_ENTRYIDS => $localFreeBusyEntryids]);
0 ignored issues
show
The function mapi_setprops was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
				/** @scrutinizer ignore-call */ 
78
    mapi_setprops($root, [PR_FREEBUSY_ENTRYIDS => $localFreeBusyEntryids]);
Loading history...
78
				mapi_savechanges($root);
0 ignored issues
show
The function mapi_savechanges was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

78
				/** @scrutinizer ignore-call */ 
79
    mapi_savechanges($root);
Loading history...
79
80
				return mapi_msgstore_openentry($store, $localFreeBusyEntryids[self::DELEGATE_PROPERTIES]);
81
			}
82
83
			// Ensure to return false if an exception occurs
84
			error_log("getLocalFreeBusyMessage: unhandled MAPIException " . $e->getMessage());
85
		        return false;
86
87
		}
88
89
		// Fallback, should not typically reach here.
90
		error_log("getLocalFreeBusyMessage: reached unexpected code path");
91
		return false;
92
93
	}
94
95
	/**
96
	 * Function will return resource of the freebusy folder of the user's store.
97
	 *
98
	 * @param mixed $store (optional) user's store
99
	 *
100
	 * @return bool|resource freebusy folder
101
	 */
102
	public static function getLocalFreeBusyFolder($store = false) {
103
		if (!$store) {
104
			error_log("getLocalFreeBusyFolder: store not available");
105
106
			return false;
107
		}
108
		// Get 'LocalFreeBusy' message from FreeBusy Store
109
		$root = mapi_msgstore_openentry($store, null);
0 ignored issues
show
The function mapi_msgstore_openentry was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
		$root = /** @scrutinizer ignore-call */ mapi_msgstore_openentry($store, null);
Loading history...
110
		$storeProps = mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]);
0 ignored issues
show
The function mapi_getprops was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

110
		$storeProps = /** @scrutinizer ignore-call */ mapi_getprops($root, [PR_FREEBUSY_ENTRYIDS]);
Loading history...
111
112
		return mapi_msgstore_openentry($store, $storeProps[PR_FREEBUSY_ENTRYIDS][self::FREEBUSYDATA_IPM_SUBTREE]);
113
	}
114
}
115