Esempio n. 1
0
 /**
  * Parse category page.
  *
  * @throws CurlException
  * @throws InvalidParamException
  * @throws ObjectException
  */
 public function parse()
 {
     GlabsController::showMessage("\n" . 'Parsing category "' . $this->title . '"');
     /** @var \app\models\glabs\objects\BaseObject $object */
     foreach ($this->objects as $object) {
         if (in_array($object->getUrl(), $this->doneObjects, true)) {
             continue;
         }
         $this->i++;
         GlabsController::showMessage("\t" . $this->i . ') Parsing object "' . $object->getTitle() . '" (' . $object->getUrl() . ')');
         try {
             $object->parse();
             $this->doneObjects[] = $object->getUrl();
         } catch (ObjectException $e) {
             $object->removeFiles();
             GlabsController::showMessage("\t\t" . 'Object skipped because of reason: ' . $e->getMessage());
             continue;
         } catch (EmptyCollectionException $e) {
             $object->removeFiles();
             GlabsController::showMessage("\t\t" . 'Object skipped because of reason: ' . $e->getMessage());
             continue;
         }
         GlabsController::showMessage("\t\t" . 'Sending object... ', false);
         try {
             $object->send();
             $object->removeFiles();
             GlabsController::$sentObjects++;
             GlabsController::showMessage('Success.');
         } catch (TransportException $e) {
             $object->removeFiles();
             GlabsController::showMessage('Fail with message: "' . $e->getMessage() . '"');
         }
         GlabsController::saveObjectsEmails($object);
         if ($this->isUsersTitle()) {
             /* @var \app\models\glabs\objects\chatapp\BaseObject $object */
             GlabsController::saveUsersLinks($object);
             GlabsController::saveChatappStatus();
         } else {
             GlabsController::saveProductsLinks($object);
             GlabsController::saveZohenyStatus();
         }
     }
     $done_count = count($this->doneObjects);
     if ($done_count < $this->needCount && count($this->objects)) {
         $this->count = $this->needCount - $done_count;
         $this->objects = [];
         $this->collectObjects($this->getPagedUrl(reset($this->url)));
         $this->parse();
     }
 }