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