/** * sample_DeleteMyMessages::dispatchCall() * * Dispatch the call * * @param array $params array of parameters for the eBay API call * * @return boolean success */ public function dispatchCall($params) { $req = new DeleteMyMessagesRequestType(); $MessageIDs = new MyMessagesMessageIDArrayType(); $MessageIDs->setMessageID($params['MessageID']); $req->setMessageIDs($MessageIDs); $res = $this->proxy->DeleteMyMessages($req); if ($this->testValid($res)) { $this->dumpObject($res); return true; } else { return false; } }
function updateMessages($session, $days = null, $current_page = 1, $message_ids = false) { WPLE()->logger->info('*** updateMessages(' . $days . ') - page ' . $current_page); $this->initServiceProxy($session); // set request handler $this->_cs->setHandler('MyMessagesMessageType', array(&$this, 'handleMyMessagesMessageType')); // $this->_cs->setHandler( 'PaginationResultType', array( & $this, 'handlePaginationResultType' ) ); // build request $req = new GetMyMessagesRequestType(); $req->setDetailLevel('ReturnHeaders'); // default, unless message_ids provided // check if we need to calculate lastdate if ($this->current_lastdate) { $lastdate = $this->current_lastdate; WPLE()->logger->info('used current_lastdate from last run: ' . $lastdate); } else { // period 30 days, which is the maximum allowed $now = time(); // $lastdate = $this->getDateOfLastMessage(); // WPLE()->logger->info('getDateOfLastMessage() returned: '.$lastdate); $lastdate = null; if ($lastdate) { $lastdate = mysql2date('U', $lastdate); } // if last date is older than 30 days, fall back to default if ($lastdate < $now - 3600 * 24 * 30) { WPLE()->logger->info('resetting lastdate - fall back default '); $lastdate = false; } } // save lastdate for next page $this->current_lastdate = $lastdate; if (is_array($message_ids)) { $MyMessagesMessageIDArray = new MyMessagesMessageIDArrayType(); foreach ($message_ids as $id) { $message = $this->getItem($id); $MyMessagesMessageIDArray->addMessageID($message['message_id']); } $req->setMessageIDs($MyMessagesMessageIDArray); $req->setDetailLevel('ReturnMessages'); } elseif ($lastdate) { $req->StartTime = gmdate('Y-m-d H:i:s', $lastdate); $this->StartTime = $req->StartTime; WPLE()->logger->info('lastdate: ' . $lastdate); WPLE()->logger->info('StartTime: ' . $req->StartTime); } /* // fetch messages by IDs if ( is_array( $message_ids ) ) { $MyMessagesMessageIDArray = new MyMessagesMessageIDArrayType(); foreach ( $message_ids as $id ) { $message = $this->getItem( $id ); $MyMessagesMessageIDArray->addMessageID( $message['message_id'] ); } $req->setMyMessagesMessageIDArray( $MyMessagesMessageIDArray ); // parameter $days } elseif ( $days ) { $req->NumberOfDays = $days; $this->NumberOfDays = $days; WPLE()->logger->info('NumberOfDays: '.$req->NumberOfDays); // default: messages since last change } elseif ( $lastdate ) { $req->StartTime = gmdate( 'Y-m-d H:i:s', $lastdate ); $this->StartTime = $req->StartTime; WPLE()->logger->info('lastdate: '.$lastdate); WPLE()->logger->info('StartTime: '.$req->StartTime); // fallback: one day (max allowed by ebay: 30 days) } else { $days = 1; $req->NumberOfDays = $days; $this->NumberOfDays = $days; WPLE()->logger->info('NumberOfDays (fallback): '.$req->NumberOfDays); } */ // $req->DetailLevel = $Facet_DetailLevelCodeType->ReturnMessages; // if ( ! $this->is_ajax() ) $req->setDetailLevel('ReturnSummary'); // $req->setFolderID( 0 ); // Inbox (FolderID = 0) and Sent (FolderID = 1) // $req->setDetailLevel( 'ReturnSummary' ); // $req->setDetailLevel( 'ReturnMessages' ); // $req->setDetailLevel( 'ReturnHeaders' ); // set pagination for first page $items_per_page = 100; // should be set to 200 for production $this->current_page = $current_page; $Pagination = new PaginationType(); $Pagination->setEntriesPerPage($items_per_page); $Pagination->setPageNumber($this->current_page); $req->setPagination($Pagination); // get messages (single page) WPLE()->logger->info('fetching messages - page ' . $this->current_page); $res = $this->_cs->GetMyMessages($req); $this->total_pages = $res->PaginationResult->TotalNumberOfPages; $this->total_items = $res->PaginationResult->TotalNumberOfEntries; // get message with pagination helper (doesn't work as expected) // EbatNs_PaginationHelper($proxy, $callName, $request, $responseElementToMerge = '__COUNT_BY_HANDLER', $maxEntries = 200, $pageSize = 200, $initialPage = 1) // $helper = new EbatNs_PaginationHelper( $this->_cs, 'GetMyMessages', $req, 'MessageArray', 20, 10, 1); // $res = $helper->QueryAll(); // handle response and check if successful if ($this->handleResponse($res)) { WPLE()->logger->info("*** Messages updated successfully."); // WPLE()->logger->info( "*** PaginationResult:".print_r($res->PaginationResult,1) ); // WPLE()->logger->info( "*** processed response:".print_r($res,1) ); WPLE()->logger->info("*** current_page: " . $this->current_page); WPLE()->logger->info("*** total_pages: " . $this->total_pages); WPLE()->logger->info("*** total_items: " . $this->total_items); // fetch next page recursively - only in days mode /* if ( $res->HasMoreMessages ) { $this->current_page++; $this->updateMessages( $session, $days, $this->current_page ); } */ } else { WPLE()->logger->error("Error on messages update" . print_r($res, 1)); } }