예제 #1
0
 public function jobs_run_task()
 {
     // quit if no job name provided
     if (!isset($_REQUEST['job'])) {
         return false;
     }
     if (!isset($_REQUEST['task'])) {
         return false;
     }
     $job = $_REQUEST['job'];
     $task = $_REQUEST['task'];
     $site_id = isset($task['site_id']) ? $task['site_id'] : false;
     $account_id = isset($task['account_id']) ? $task['account_id'] : false;
     // register shutdown handler
     global $wpl_shutdown_handler_enabled;
     $wpl_shutdown_handler_enabled = true;
     register_shutdown_function(array($this, 'shutdown_handler'));
     WPLE()->logger->info('running task: ' . print_r($task, 1));
     // handle job name
     switch ($task['task']) {
         case 'loadShippingServices':
             // call EbayController
             $this->initEC($account_id, $site_id);
             $result = $this->EC->loadShippingServices($site_id);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->result = $result;
             $response->errors = array();
             $response->success = true;
             $this->returnJSON($response);
             exit;
         case 'loadPaymentOptions':
             // call EbayController
             $this->initEC($account_id, $site_id);
             $result = $this->EC->loadPaymentOptions($site_id);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->result = $result;
             $response->errors = array();
             $response->success = true;
             $this->returnJSON($response);
             exit;
         case 'loadStoreCategories':
             // call EbayController
             $this->initEC($account_id);
             $result = $this->EC->loadStoreCategories($account_id);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->result = $result;
             $response->errors = array();
             $response->success = true;
             $this->returnJSON($response);
             exit;
         case 'loadUserAccountDetails':
             // call EbayController
             $this->initEC($account_id);
             $result = $this->EC->loadUserAccountDetails();
             $this->EC->closeEbay();
             // update account (seller profiles etc.)
             $account = new WPLE_eBayAccount($account_id);
             if ($account) {
                 $account->updateUserDetails();
             }
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->result = $result;
             $response->errors = array();
             $response->success = true;
             $this->returnJSON($response);
             exit;
         case 'loadEbayCategoriesBranch':
             // call EbayController
             $this->initEC($account_id, $site_id);
             $result = $this->EC->loadEbayCategoriesBranch($task['cat_id'], $task['site_id']);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->result = $result;
             $response->errors = array();
             $response->success = true;
             $this->returnJSON($response);
             exit;
         case 'verifyItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->verifyItems($task['id']);
             $this->EC->closeEbay();
             $this->handleSubTasksInResults($results, $job, $task);
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'publishItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->sendItemsToEbay($task['id']);
             $this->EC->closeEbay();
             $this->handleSubTasksInResults($results, $job, $task);
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'reviseItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->reviseItems($task['id']);
             $this->EC->closeEbay();
             $this->handleSubTasksInResults($results, $job, $task);
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'updateItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->updateItemsFromEbay($task['id']);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'endItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->endItemsOnEbay($task['id']);
             $this->EC->closeEbay();
             $this->handleSubTasksInResults($results, $job, $task);
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'relistItem':
             // call EbayController
             $this->initEC($account_id);
             $results = $this->EC->relistItems($task['id']);
             $this->EC->closeEbay();
             $this->handleSubTasksInResults($results, $job, $task);
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = $results[0]->errors;
             $response->success = $results[0]->success;
             $this->returnJSON($response);
             exit;
         case 'uploadToEPS':
             // call EbayController
             $this->initEC($account_id);
             $lm = new ListingsModel();
             $eps_url = $lm->uploadPictureToEPS($task['img'], $task['id'], $this->EC->session);
             $this->EC->closeEbay();
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             // $response->errors   = $eps_url ? false : $lm->result->errors;
             $response->errors = is_array($lm->result->errors) ? $lm->result->errors : array();
             // $response->success  = $lm->result->success;
             $response->success = $eps_url ? true : false;
             $this->returnJSON($response);
             exit;
         case 'applyProfileDelayed':
             $profile_id = $task['profile_id'];
             $offset = $task['offset'];
             $limit = $task['limit'];
             $profilesModel = new ProfilesModel();
             $profile = $profilesModel->getItem($profile_id);
             $lm = new ListingsModel();
             $items1 = WPLE_ListingQueryHelper::getAllPreparedWithProfile($profile_id);
             $items2 = WPLE_ListingQueryHelper::getAllVerifiedWithProfile($profile_id);
             $items3 = WPLE_ListingQueryHelper::getAllPublishedWithProfile($profile_id);
             $items = array_merge($items1, $items2, $items3);
             $total_items = sizeof($items);
             // extract batch
             $items = array_slice($items, $offset, $limit);
             // apply profile to items
             $lm->applyProfileToItems($profile, $items);
             // reset reminder option when last batch is run
             if ($offset + $limit >= $total_items) {
                 update_option('wple_job_reapply_profile_id', '');
             }
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = array();
             // $response->errors   = array( array( 'HtmlMessage' => ' Profile was applied to '.sizeof($items).' items ') );
             $response->success = true;
             $this->returnJSON($response);
             exit;
         default:
             // echo "unknown task";
             // exit();
     }
 }
예제 #2
0
 protected function newAccount()
 {
     // call FetchToken
     $this->initEC();
     $ebay_token = $this->EC->doFetchToken(false);
     $this->EC->closeEbay();
     // check if we have a token
     if ($ebay_token) {
         // create new account
         $account = new WPLE_eBayAccount();
         // $account->title     = stripslashes( $_POST['wplister_account_title'] );
         $account->title = 'My Account';
         $account->site_id = $_REQUEST['site_id'];
         $account->site_code = EbayController::getEbaySiteCode($_REQUEST['site_id']);
         $account->sandbox_mode = $_REQUEST['sandbox'];
         $account->token = $ebay_token;
         $account->active = 1;
         $account->add();
         // set enabled flag for site
         $site = WPLE_eBaySite::getSiteObj($account->site_id);
         $site->enabled = 1;
         $site->update();
         // update user details
         $account->updateUserDetails();
         // set default account automatically
         if (!get_option('wplister_default_account_id')) {
             update_option('wplister_default_account_id', $account->id);
             $this->makeDefaultAccount($account->id);
         }
         $this->check_wplister_setup('settings');
         $this->showMessage(__('New account was added.', 'wplister') . ' ' . __('Please refresh account and site specific details now.', 'wplister'));
     } else {
         $this->showMessage("There was a problem fetching your token. Make sure you follow the instructions.", 1);
     }
 }