コード例 #1
0
ファイル: WPL_AjaxHandler.php プロジェクト: booklein/wpbookle
 public function jobs_load_tasks()
 {
     // quit if no job name provided
     if (!isset($_REQUEST['job'])) {
         return false;
     }
     $jobname = $_REQUEST['job'];
     // check if an array of listing IDs was provided
     $listing_ids = isset($_REQUEST['listing_ids']) && is_array($_REQUEST['listing_ids']) ? $_REQUEST['listing_ids'] : false;
     if ($listing_ids) {
         $items = WPLE_ListingQueryHelper::getItemsByIdArray($listing_ids);
     }
     // handle job name
     switch ($jobname) {
         case 'updateEbayData':
             // call EbayController
             $site_id = isset($_REQUEST['site_id']) ? $_REQUEST['site_id'] : get_option('wplister_ebay_site_id');
             $account_id = isset($_REQUEST['account_id']) ? $_REQUEST['account_id'] : get_option('wplister_default_account_id');
             $this->initEC($account_id);
             $tasks = $this->EC->initCategoriesUpdate($site_id);
             $this->EC->closeEbay();
             // update store categories for each account using this site_id
             $accounts = WPLE_eBayAccount::getAll();
             foreach ($accounts as $account) {
                 if ($site_id != $account->site_id) {
                     continue;
                 }
                 // add task - load user specific details
                 $tasks[] = array('task' => 'loadUserAccountDetails', 'displayName' => 'update eBay account details for ' . $account->title, 'account_id' => $account->id);
                 // add task - load store categories
                 $tasks[] = array('task' => 'loadStoreCategories', 'displayName' => 'update custom store categories for ' . $account->title, 'account_id' => $account->id);
             }
             // for each account
             // build response
             $response = new stdClass();
             $response->tasklist = $tasks;
             $response->total_tasks = count($tasks);
             $response->error = '';
             $response->success = true;
             // create new job
             $newJob = new stdClass();
             $newJob->jobname = $jobname;
             $newJob->tasklist = $tasks;
             $job = new JobsModel($newJob);
             $response->job_key = $job->key;
             $this->returnJSON($response);
             exit;
         case 'verifyItems':
             $response = $this->_create_bulk_listing_job('verifyItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishItems':
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'reviseItems':
             $response = $this->_create_bulk_listing_job('reviseItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateItems':
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'endItems':
             $response = $this->_create_bulk_listing_job('endItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'relistItems':
             $response = $this->_create_bulk_listing_job('relistItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'verifyAllPreparedItems':
             // get prepared items
             $items = WPLE_ListingQueryHelper::getAllPrepared();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('verifyItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishAllVerifiedItems':
             // get verified items
             $items = WPLE_ListingQueryHelper::getAllVerified();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'publishAllPreparedItems':
             // get prepared items
             $items = WPLE_ListingQueryHelper::getAllPrepared();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('publishItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'reviseAllChangedItems':
             // get changed items
             $items = WPLE_ListingQueryHelper::getAllChangedItemsToRevise();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('reviseItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'relistAllRestockedItems':
             // get restocked items
             $items = WPLE_ListingQueryHelper::getAllEndedItemsToRelist();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('relistItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateAllPublishedItems':
             // get published items
             $items = WPLE_ListingQueryHelper::getAllPublished();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'updateAllRelistedItems':
             // get published items
             $items = WPLE_ListingQueryHelper::getAllRelisted();
             // create job from items and send response
             $response = $this->_create_bulk_listing_job('updateItem', $items, $jobname);
             $this->returnJSON($response);
             exit;
         case 'runDelayedProfileApplication':
             // get items using given profile
             $profile_id = get_option('wple_job_reapply_profile_id');
             if (!$profile_id) {
                 return;
             }
             $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);
             $batch_size = get_option('wplister_apply_profile_batch_size', 1000);
             $tasks = array();
             // echo "<pre>profile_id: ";echo $profile_id;echo"</pre>";
             // echo "<pre>total: ";echo $total_items;echo"</pre>";die();
             for ($page = 0; $page < $total_items / $batch_size; $page++) {
                 $from = $page * $batch_size + 1;
                 $to = $page * $batch_size + $batch_size;
                 $to = min($to, $total_items);
                 // add task - load user specific details
                 $tasks[] = array('task' => 'applyProfileDelayed', 'displayName' => 'Apply profile to items ' . $from . ' to ' . $to, 'profile_id' => $profile_id, 'offset' => $page * $batch_size, 'limit' => $batch_size);
             }
             // build response
             $response = new stdClass();
             $response->tasklist = $tasks;
             $response->total_tasks = count($tasks);
             $response->error = '';
             $response->success = true;
             // create new job
             $newJob = new stdClass();
             $newJob->jobname = $jobname;
             $newJob->tasklist = $tasks;
             $job = new JobsModel($newJob);
             $response->job_key = $job->key;
             $this->returnJSON($response);
             exit;
         default:
             // echo "unknown job";
             // break;
     }
     // 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();
     }
 }