| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 205 |
| Code Lines | 110 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 106 | public function save($store, $parententryid, $entryid, $action) { |
||
| 107 | $properiesToDelete = []; // create an array of properties which should be deleted |
||
| 108 | // this array is passed to $GLOBALS['operations']->saveMessage() function |
||
| 109 | |||
| 110 | if (!$store && !$parententryid) { |
||
| 111 | if (isset($action['props']['message_class'])) { |
||
| 112 | $store = $GLOBALS['mapisession']->getDefaultMessageStore(); |
||
| 113 | $parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
||
| 114 | } |
||
| 115 | elseif ($entryid) { |
||
| 116 | $data = $this->getStoreParentEntryIdFromEntryId($entryid); |
||
| 117 | $store = $data["store"]; |
||
| 118 | $parententryid = $data["parent_entryid"]; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | elseif (!$parententryid) { |
||
| 122 | if (isset($action['props']['message_class'])) { |
||
| 123 | $parententryid = $this->getDefaultFolderEntryID($store, $action['props']['message_class']); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | if ($store && $parententryid && isset($action['props'])) { |
||
| 128 | if (isset($action['members'])) { |
||
| 129 | // DistList |
||
| 130 | |||
| 131 | // for distlist we need to use different set of properties |
||
| 132 | $this->properties = $GLOBALS['properties']->getDistListProperties(); |
||
| 133 | |||
| 134 | // do conversion of client data |
||
| 135 | $props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
||
| 136 | |||
| 137 | // collect members |
||
| 138 | $members = []; |
||
| 139 | $oneoff_members = []; |
||
| 140 | |||
| 141 | $items = $action['members']; |
||
| 142 | |||
| 143 | foreach ($items as $item) { |
||
| 144 | if (empty($item['email_address'])) { |
||
| 145 | // if no email address is given then mapi_parseoneoff fails, so always give |
||
| 146 | // email address, OL07 uses Unknown as email address so we do same here |
||
| 147 | $item['email_address'] = 'Unknown'; |
||
| 148 | } |
||
| 149 | |||
| 150 | $oneoff = mapi_createoneoff($item['display_name'], $item['address_type'], $item['email_address']); |
||
| 151 | |||
| 152 | if ($item['distlist_type'] == DL_EXTERNAL_MEMBER) { |
||
| 153 | $member = $oneoff; |
||
| 154 | } |
||
| 155 | else { |
||
| 156 | $parts = []; |
||
| 157 | $parts['distlist_guid'] = WAB_GUID; |
||
| 158 | $parts['distlist_type'] = $item['distlist_type']; |
||
| 159 | $parts['entryid'] = hex2bin($item['entryid']); |
||
| 160 | $member = pack('VA16CA*', 0, $parts['distlist_guid'], $parts['distlist_type'], $parts['entryid']); |
||
| 161 | } |
||
| 162 | |||
| 163 | $oneoff_members[] = $oneoff; |
||
| 164 | $members[] = $member; |
||
| 165 | } |
||
| 166 | |||
| 167 | if (!empty($members) && !empty($oneoff_members)) { |
||
| 168 | $props[$this->properties['members']] = $members; |
||
| 169 | $props[$this->properties['oneoff_members']] = $oneoff_members; |
||
| 170 | } |
||
| 171 | else { |
||
| 172 | $properiesToDelete[] = $this->properties['members']; |
||
| 173 | $properiesToDelete[] = $this->properties['oneoff_members']; |
||
| 174 | } |
||
| 175 | |||
| 176 | unset($action['members']); |
||
| 177 | } |
||
| 178 | else { |
||
| 179 | // Contact |
||
| 180 | |||
| 181 | $isCopyGABToContact = isset($action["message_action"], $action["message_action"]["action_type"]) && |
||
| 182 | |||
| 183 | $action["message_action"]["action_type"] === "copyToContact"; |
||
| 184 | |||
| 185 | if ($isCopyGABToContact) { |
||
| 186 | $this->copyGABRecordProps($action); |
||
| 187 | } |
||
| 188 | // generate one-off entryids for email addresses |
||
| 189 | for ($index = 1; $index < 4; ++$index) { |
||
| 190 | if (!empty($action['props']['email_address_' . $index]) && !empty($action['props']['email_address_display_name_' . $index])) { |
||
| 191 | $action['props']['email_address_entryid_' . $index] = bin2hex(mapi_createoneoff($action['props']['email_address_display_name_' . $index], $action['props']['email_address_type_' . $index], $action['props']['email_address_' . $index])); |
||
| 192 | } |
||
| 193 | } |
||
| 194 | |||
| 195 | // set properties for primary fax number |
||
| 196 | if (isset($action['props']['fax_1_email_address']) && !empty($action['props']['fax_1_email_address'])) { |
||
| 197 | $action['props']['fax_1_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_1_original_display_name'], $action['props']['fax_1_address_type'], $action['props']['fax_1_email_address'], MAPI_UNICODE)); |
||
| 198 | } |
||
| 199 | else { |
||
| 200 | // delete properties to remove previous values |
||
| 201 | $properiesToDelete[] = $this->properties['fax_1_address_type']; |
||
| 202 | $properiesToDelete[] = $this->properties['fax_1_original_display_name']; |
||
| 203 | $properiesToDelete[] = $this->properties['fax_1_email_address']; |
||
| 204 | $properiesToDelete[] = $this->properties['fax_1_original_entryid']; |
||
| 205 | } |
||
| 206 | |||
| 207 | // set properties for business fax number |
||
| 208 | if (isset($action['props']['fax_2_email_address']) && !empty($action['props']['fax_2_email_address'])) { |
||
| 209 | $action['props']['fax_2_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_2_original_display_name'], $action['props']['fax_2_address_type'], $action['props']['fax_2_email_address'], MAPI_UNICODE)); |
||
| 210 | } |
||
| 211 | else { |
||
| 212 | $properiesToDelete[] = $this->properties['fax_2_address_type']; |
||
| 213 | $properiesToDelete[] = $this->properties['fax_2_original_display_name']; |
||
| 214 | $properiesToDelete[] = $this->properties['fax_2_email_address']; |
||
| 215 | $properiesToDelete[] = $this->properties['fax_2_original_entryid']; |
||
| 216 | } |
||
| 217 | |||
| 218 | // set properties for home fax number |
||
| 219 | if (isset($action['props']['fax_3_email_address']) && !empty($action['props']['fax_3_email_address'])) { |
||
| 220 | $action['props']['fax_3_original_entryid'] = bin2hex(mapi_createoneoff($action['props']['fax_3_original_display_name'], $action['props']['fax_3_address_type'], $action['props']['fax_3_email_address'], MAPI_UNICODE)); |
||
| 221 | } |
||
| 222 | else { |
||
| 223 | $properiesToDelete[] = $this->properties['fax_3_address_type']; |
||
| 224 | $properiesToDelete[] = $this->properties['fax_3_original_display_name']; |
||
| 225 | $properiesToDelete[] = $this->properties['fax_3_email_address']; |
||
| 226 | $properiesToDelete[] = $this->properties['fax_3_original_entryid']; |
||
| 227 | } |
||
| 228 | |||
| 229 | // check for properties which should be deleted |
||
| 230 | if (isset($action['entryid']) && !empty($action['entryid'])) { |
||
| 231 | // check for empty email address properties |
||
| 232 | for ($i = 1; $i < 4; ++$i) { |
||
| 233 | if (isset($action['props']['email_address_' . $i]) && empty($action['props']['email_address_' . $i])) { |
||
| 234 | array_push($properiesToDelete, $this->properties['email_address_entryid_' . $i]); |
||
| 235 | array_push($properiesToDelete, $this->properties['email_address_' . $i]); |
||
| 236 | array_push($properiesToDelete, $this->properties['email_address_display_name_' . $i]); |
||
| 237 | array_push($properiesToDelete, $this->properties['email_address_display_name_email_' . $i]); |
||
| 238 | array_push($properiesToDelete, $this->properties['email_address_type_' . $i]); |
||
| 239 | } |
||
| 240 | } |
||
| 241 | |||
| 242 | // check for empty address_book_mv and address_book_long properties |
||
| 243 | if (isset($action['props']['address_book_long']) && $action['props']['address_book_long'] === 0) { |
||
| 244 | $properiesToDelete[] = $this->properties['address_book_mv']; |
||
| 245 | $properiesToDelete[] = $this->properties['address_book_long']; |
||
| 246 | } |
||
| 247 | |||
| 248 | // Check if the birthday and anniversary properties are empty. If so delete them. |
||
| 249 | if (array_key_exists('birthday', $action['props']) && empty($action['props']['birthday'])) { |
||
| 250 | array_push($properiesToDelete, $this->properties['birthday']); |
||
| 251 | array_push($properiesToDelete, $this->properties['birthday_eventid']); |
||
| 252 | if (!empty($action['props']['birthday_eventid'])) { |
||
| 253 | $this->deleteSpecialDateAppointment($store, $action['props']['birthday_eventid']); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | if (array_key_exists('wedding_anniversary', $action['props']) && empty($action['props']['wedding_anniversary'])) { |
||
| 258 | array_push($properiesToDelete, $this->properties['wedding_anniversary']); |
||
| 259 | array_push($properiesToDelete, $this->properties['anniversary_eventid']); |
||
| 260 | if (!empty($action['props']['anniversary_eventid'])) { |
||
| 261 | $this->deleteSpecialDateAppointment($store, $action['props']['anniversary_eventid']); |
||
| 262 | } |
||
| 263 | } |
||
| 264 | } |
||
| 265 | |||
| 266 | /* |
||
| 267 | * convert all line endings(LF) into CRLF |
||
| 268 | * XML parser will normalize all CR, LF and CRLF into LF |
||
| 269 | * but outlook(windows) uses CRLF as line ending |
||
| 270 | */ |
||
| 271 | if (isset($action['props']['business_address'])) { |
||
| 272 | $action['props']['business_address'] = str_replace('\n', '\r\n', $action['props']['business_address']); |
||
| 273 | } |
||
| 274 | |||
| 275 | if (isset($action['props']['home_address'])) { |
||
| 276 | $action['props']['home_address'] = str_replace('\n', '\r\n', $action['props']['home_address']); |
||
| 277 | } |
||
| 278 | |||
| 279 | if (isset($action['props']['other_address'])) { |
||
| 280 | $action['props']['other_address'] = str_replace('\n', '\r\n', $action['props']['other_address']); |
||
| 281 | } |
||
| 282 | |||
| 283 | // check birthday props to make an appointment |
||
| 284 | if (!empty($action['props']['birthday'])) { |
||
| 285 | $action['props']['birthday_eventid'] = $this->updateAppointments($store, $action, 'birthday'); |
||
| 286 | } |
||
| 287 | |||
| 288 | // check anniversary props to make an appointment |
||
| 289 | if (!empty($action['props']['wedding_anniversary'])) { |
||
| 290 | $action['props']['anniversary_eventid'] = $this->updateAppointments($store, $action, 'wedding_anniversary'); |
||
| 291 | } |
||
| 292 | |||
| 293 | // do the conversion when all processing has been finished |
||
| 294 | $props = Conversion::mapXML2MAPI($this->properties, $action['props']); |
||
| 295 | } |
||
| 296 | |||
| 297 | $messageProps = []; |
||
| 298 | |||
| 299 | $result = $GLOBALS['operations']->saveMessage($store, $entryid, $parententryid, $props, $messageProps, [], isset($action['attachments']) ? $action['attachments'] : [], $properiesToDelete); |
||
| 300 | |||
| 301 | if ($result) { |
||
| 302 | $GLOBALS['bus']->notify(bin2hex($parententryid), TABLE_SAVE, $messageProps); |
||
| 303 | |||
| 304 | if ($isCopyGABToContact) { |
||
| 305 | $message = mapi_msgstore_openentry($store, $messageProps[PR_ENTRYID]); |
||
| 306 | $messageProps = mapi_getprops($message, $this->properties); |
||
| 307 | } |
||
| 308 | |||
| 309 | $this->addActionData('update', ['item' => Conversion::mapMAPI2XML($this->properties, $messageProps)]); |
||
| 310 | $GLOBALS['bus']->addData($this->getResponseData()); |
||
| 311 | } |
||
| 582 |