コード例 #1
0
ファイル: WPL_AjaxHandler.php プロジェクト: booklein/wpbookle
 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
ファイル: ProfilesPage.php プロジェクト: booklein/wpbookle
 private function saveProfile()
 {
     global $wpdb;
     $details = $this->getPreprocessedPostDetails();
     $profile_id = $this->getValueFromPost('profile_id');
     $account_id = $this->getValueFromPost('account_id');
     if (!$account_id) {
         $account_id = get_option('wplister_default_account_id');
     }
     // fix entered prices
     $details = self::fixProfilePrices($details);
     // process item specifics
     $item_specifics = array();
     $itmSpecs_name = @$_POST['itmSpecs_name'];
     $itmSpecs_value = @$_POST['itmSpecs_value'];
     $itmSpecs_attrib = @$_POST['itmSpecs_attrib'];
     if (is_array($itmSpecs_name)) {
         foreach ($itmSpecs_name as $key => $name) {
             #$name = str_replace('\\\\', '', $name );
             $name = stripslashes($name);
             $value = trim($itmSpecs_value[$key]);
             $attribute = trim($itmSpecs_attrib[$key]);
             if ($value != '' || $attribute != '') {
                 $spec = new stdClass();
                 $spec->name = $name;
                 $spec->value = $value;
                 $spec->attribute = $attribute;
                 $item_specifics[] = $spec;
             }
         }
     }
     $details['item_specifics'] = $item_specifics;
     // add category names
     $details['ebay_category_1_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_1_id']);
     $details['ebay_category_2_name'] = EbayCategoriesModel::getCategoryName($details['ebay_category_2_id']);
     $details['store_category_1_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_1_id']);
     $details['store_category_2_name'] = EbayCategoriesModel::getStoreCategoryName($details['store_category_2_id']);
     // fix prices - already done in fixProfilePrices()
     // $details['start_price'] = str_replace(',', '.', $details['start_price'] );
     // $details['fixed_price'] = str_replace(',', '.', $details['fixed_price'] );
     // if the user enters only fixed price but no start price, move fixed price to start price
     if ($details['start_price'] == '' && $details['fixed_price'] != '') {
         $details['start_price'] = $details['fixed_price'];
         $details['fixed_price'] = '';
     }
     // fix quantities
     if (!$details['custom_quantity_enabled']) {
         $details['quantity'] = '';
         $details['max_quantity'] = '';
     }
     // do we have a primary category?
     if (intval($details['ebay_category_1_id']) != 0) {
         $primary_category_id = $details['ebay_category_1_id'];
     } else {
         // if not use default category
         $primary_category_id = self::getOption('default_ebay_category_id');
     }
     // // do we have ConditionDetails for primary category?
     // // $conditions = $this->fetchItemConditions( $primary_category_id, $profile_id, $account_id );
     // $conditions = EbayCategoriesModel::getConditionsForCategory( $primary_category_id, false, $account_id );
     // // do we have item specifics for primary category?
     // if ( intval($profile_id) != 0 ) {
     // 	// $saved_specifics = $wpdb->get_var('SELECT category_specifics FROM '.$wpdb->prefix.'ebay_profiles WHERE profile_id = '.$profile_id);
     // 	$saved_specifics = $wpdb->get_var( $wpdb->prepare( "SELECT category_specifics FROM {$wpdb->prefix}ebay_profiles WHERE profile_id = %d", $profile_id ) );
     // 	$saved_specifics = unserialize($saved_specifics);
     // }
     // // fetch required item specifics for primary category
     // if ( ( isset( $saved_specifics[ $primary_category_id ] ) ) && ( $saved_specifics[ $primary_category_id ] != 'none' ) ) {
     // 	$specifics = $saved_specifics;
     // } elseif ( (int)$primary_category_id != 0 ) {
     // 	$this->initEC( $account_id );
     // 	$specifics = $this->EC->getCategorySpecifics( $primary_category_id );
     // 	$this->EC->closeEbay();
     // } else {
     // 	$specifics = array();
     // }
     // // do we have item specifics for primary category?
     // (improved version of the above, using ebay_categories as cache)
     // $specifics = EbayCategoriesModel::getItemSpecificsForCategory( $primary_category_id, false, $account_id );
     // // $specifics = array( $primary_category_id => $specifics );
     if (WPLISTER_LIGHT) {
         $specifics = array();
     }
     // sql columns
     $item = array();
     $item['profile_id'] = $profile_id;
     $item['profile_name'] = $this->getValueFromPost('profile_name');
     $item['profile_description'] = $this->getValueFromPost('profile_description');
     $item['listing_duration'] = $this->getValueFromPost('listing_duration');
     $item['type'] = $this->getValueFromPost('auction_type');
     $item['sort_order'] = intval($this->getValueFromPost('sort_order'));
     $item['details'] = json_encode($details);
     // $item['conditions']			 		= serialize( $conditions );	// deprecated
     // $item['category_specifics']	 		= serialize( $specifics );	// deprecated
     $item['conditions'] = '';
     $item['category_specifics'] = '';
     $item['account_id'] = $account_id;
     $item['site_id'] = WPLE()->accounts[$item['account_id']]->site_id;
     // insert or update
     if ($item['profile_id'] == 0) {
         // insert new profile
         unset($item['profile_id']);
         $result = $wpdb->insert($wpdb->prefix . 'ebay_profiles', $item);
     } else {
         // update profile
         $result = $wpdb->update($wpdb->prefix . 'ebay_profiles', $item, array('profile_id' => $item['profile_id']));
     }
     // proper error handling
     if ($result === false) {
         $this->showMessage("There was a problem saving your profile.<br>SQL:<pre>" . $wpdb->last_query . '</pre>' . $wpdb->last_error, true);
     } else {
         $this->showMessage(__('Profile saved.', 'wplister'));
         // if we were updating this template as part of setup, move to next step
         if ('4' == self::getOption('setup_next_step')) {
             self::updateOption('setup_next_step', 5);
         }
     }
     // if this is a new profile, skip further processing
     if (!$profile_id) {
         return;
     }
     // handle delayed update option
     if (isset($_POST['wple_delay_profile_application'])) {
         update_option('wple_job_reapply_profile_id', $profile_id);
         return;
     }
     // prepare for updating items
     $listingsModel = new ListingsModel();
     $profilesModel = new ProfilesModel();
     $profile = $profilesModel->getItem($this->getValueFromPost('profile_id'));
     // re-apply profile to all prepared
     if ($this->getValueFromPost('apply_changes_to_all_prepared') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllPreparedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s prepared items updated.', 'wplister'), count($items)));
     }
     // re-apply profile to all verified
     if ($this->getValueFromPost('apply_changes_to_all_verified') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllVerifiedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s verified items updated.', 'wplister'), count($items)));
     }
     // re-apply profile to all published
     if ($this->getValueFromPost('apply_changes_to_all_published') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllPublishedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s published items changed.', 'wplister'), count($items)));
     }
     // re-apply profile to all ended
     if ($this->getValueFromPost('apply_changes_to_all_ended') == 'yes') {
         $items = WPLE_ListingQueryHelper::getAllEndedWithProfile($item['profile_id']);
         $listingsModel->applyProfileToItems($profile, $items);
         $this->showMessage(sprintf(__('%s ended items updated.', 'wplister'), count($items)));
         // update ended listings - required for autorelist to be applied
         // $listingsModel->updateEndedListings();
         $this->initEC($account_id);
         $this->EC->updateListings();
         $this->EC->closeEbay();
     }
 }