コード例 #1
0
 /**
  * singleton pattern
  *
  * @return PlentyItemDataPushCategory
  */
 public static function getInstance()
 {
     if (!isset(self::$instance) || !self::$instance instanceof PlentyItemDataPushCategory) {
         self::$instance = new PlentyItemDataPushCategory();
     }
     return self::$instance;
 }
 public function __construct()
 {
     /*
      * select some data, we will use them for new items
      */
     PlentyItemDataPushCategory::getInstance()->execute();
     PlentyItemDataPushWarehouse::getInstance()->execute();
     PlentyItemDataPushProducer::getInstance()->execute();
     $this->warehouseId = PlentyItemDataPushWarehouse::getInstance()->getFirstWarehouseId();
 }
 public function execute()
 {
     foreach (array_keys($this->urlList) as $category) {
         $this->getLogger()->debug(__FUNCTION__ . ' current category: ' . $category);
         /*
          * check category
          */
         $categoryId = PlentyItemDataPushCategory::getInstance()->checkCategoryLevel1($category);
         if (!$categoryId) {
             /*
              * save category
              */
             PlentyItemDataPushCategory::getInstance()->saveNewCategoryLevel1($category);
             $categoryId = PlentyItemDataPushCategory::getInstance()->checkCategoryLevel1($category);
         }
         if ($categoryId > 0) {
             foreach ($this->urlList[$category] as $url) {
                 $itemUrls = $this->getItemUrlList($url);
                 if (isset($itemUrls) && is_array($itemUrls)) {
                     foreach ($itemUrls as $itemUrl) {
                         if (count($this->itemList) > 0 && $this->quantity <= count($this->itemList)) {
                             $this->getLogger()->debug(__FUNCTION__ . ' quantity ' . $this->quantity . ' reached');
                             break 3;
                         } else {
                             $this->generateItem($categoryId, $itemUrl);
                             /*
                              * sleep a while 
                              */
                             usleep(500000);
                         }
                     }
                 }
             }
         } else {
             $this->getLogger()->crit(__FUNCTION__ . ' I can not add a new category. I will shut down.');
             exit;
         }
     }
 }