Пример #1
0
 public function ajaxMigrationProducts()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration products START.', 'jigoshop'), true);
         }
         $wpdb = $this->wp->getWPDB();
         $productsIdsMigration = array();
         if (($TMP_productsIdsMigration = $this->wp->getOption('jigoshop_products_migrate_id')) === false) {
             $query = $wpdb->prepare("\n\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_type IN (%s, %s) AND post_status <> %s", 'product', 'product_variation', 'auto-draft');
             $products = $wpdb->get_results($query);
             $countMeta = count($products);
             for ($aa = 0; $aa < $countMeta; $aa++) {
                 $productsIdsMigration[] = $products[$aa]->ID;
             }
             $productsIdsMigration = array_unique($productsIdsMigration);
             $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             $this->wp->updateOption('jigoshop_products_migrate_count', count($productsIdsMigration));
         } else {
             $productsIdsMigration = unserialize($TMP_productsIdsMigration);
         }
         $countAll = $this->wp->getOption('jigoshop_products_migrate_count');
         $singleProductId = array_shift($productsIdsMigration);
         $countRemain = count($productsIdsMigration);
         $query = $wpdb->prepare("\n\t\t\tSELECT DISTINCT p.ID, pm.* FROM {$wpdb->posts} p\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID\n\t\t\t\tWHERE p.post_type IN (%s, %s) AND p.post_status <> %s AND p.ID = %d", 'product', 'product_variation', 'auto-draft', $singleProductId);
         $product = $wpdb->get_results($query);
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($singleProductId) {
             if ($this->migrate($product)) {
                 $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration products end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             $this->wp->deleteOption('jigoshop_attributes_anti_duplicate');
             Migration::saveLog(__('Migration products END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration products end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Пример #2
0
 public function ajaxMigrationEmails()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration emails START.', 'jigoshop'), true);
         }
         $wpdb = $this->wp->getWPDB();
         $query = $wpdb->prepare("\n\t\t\t\tSELECT DISTINCT p.ID, pm.* FROM {$wpdb->posts} p\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID\n\t\t\t\t\tWHERE p.post_type IN (%s) AND p.post_status <> %s", array('shop_email', 'auto-draft'));
         $emails = $wpdb->get_results($query);
         $joinEmails = array();
         $emailsIdsMigration = array();
         for ($aa = 0; $aa < count($emails); $aa++) {
             $joinEmails[$emails[$aa]->ID][$emails[$aa]->meta_id] = new \stdClass();
             foreach ($emails[$aa] as $k => $v) {
                 $joinEmails[$emails[$aa]->ID][$emails[$aa]->meta_id]->{$k} = $v;
                 $emailsIdsMigration[] = $emails[$aa]->ID;
             }
         }
         $emailsIdsMigration = array_unique($emailsIdsMigration);
         $countAll = count($emailsIdsMigration);
         if (($TMP_emailsIdsMigration = $this->wp->getOption('jigoshop_emails_migrate_id')) !== false) {
             $emailsIdsMigration = unserialize($TMP_emailsIdsMigration);
         }
         $singleEmailsId = array_shift($emailsIdsMigration);
         $countRemain = count($emailsIdsMigration);
         sort($joinEmails[$singleEmailsId]);
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($singleEmailsId) {
             if ($this->migrate($joinEmails[$singleEmailsId])) {
                 $this->wp->updateOption('jigoshop_emails_migrate_id', serialize($emailsIdsMigration));
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration emails end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             $this->wp->updateOption('jigoshop_emails_migrate_id', serialize($emailsIdsMigration));
             Migration::saveLog(__('Migration emails END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration emails end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Пример #3
0
 public function ajaxMigrationOptions()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration options START.', 'jigoshop'), true);
         }
         $countAll = 93;
         $countRemain = 93;
         if (($itemsFromBase = $this->wp->getOption('jigoshop_options_migrate_id')) !== false) {
             if ($itemsFromBase === '1') {
                 $countRemain = 0;
             }
         }
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($countRemain > 0) {
             if ($this->migrate()) {
                 $this->wp->updateOption('jigoshop_options_migrate_id', '1');
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration coupons end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             Migration::saveLog(__('Migration coupons END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration options end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Пример #4
0
 private function getLogs()
 {
     $log_dir = JIGOSHOP_LOG_DIR . Helper\Migration::getLogsFile();
     if (file_exists($log_dir) && ($logs = file_get_contents($log_dir) && !empty($logs))) {
         $logs = nl2br(substr(trim($logs), 6));
     } else {
         file_put_contents($log_dir, '');
         $logs = __('Just start migration from "Migrate options"', 'jigoshop');
     }
     return $logs;
 }