/** * @param Eshop $eshop * @param Category $category * @return Category[] */ public function findCategories(Eshop $eshop, Category $category = null) { $query = ['$and' => [[CategoryMeta::ESHOP_ID => $eshop->getId()]]]; if ($category === null) { $query['$and'][] = [CategoryMeta::PATH => ['$size' => 0]]; } else { $query['$and'][] = [CategoryMeta::PATH => $category->getId()]; $query['$and'][] = [CategoryMeta::PATH => ['$size' => count($category->getPath()) + 1]]; } return $this->find($query, [], ["sort" => [CategoryMeta::NAME => 1]]); }
protected function execute(InputInterface $input, OutputInterface $output) { $categoryCol = $this->mongo->createCollection(CategoryMeta::SHORT_NAME); var_dump($categoryCol->ensureIndex([CategoryMeta::ESHOP_ID => 1, CategoryMeta::HASH => 1], ["unique" => true])); $productCol = $this->mongo->createCollection(ProductMeta::SHORT_NAME); var_dump($productCol->ensureIndex([ProductMeta::ESHOP_ID => 1, ProductMeta::ITEM_GROUP_ID => 1, ProductMeta::ITEM_ID => 1], ["unique" => true])); var_dump($productCol->ensureIndex(["_id" => 1, ProductMeta::V => 1], ["unique" => true])); $eshopCol = $this->mongo->createCollection(EshopMeta::SHORT_NAME); var_dump($eshopCol->ensureIndex([EshopMeta::SLUG => 1]), ["unique" => true]); $f = fopen($input->getArgument("csv"), "r"); while (list($slug, $url, $feedUrl) = fgetcsv($f)) { $eshop = new Eshop(); $eshop->setName($slug)->setSlug($slug)->setUrl($url)->setFeeds([(new Feed())->setId(new \MongoId())->setUrl($feedUrl)]); $eshopDoc = $this->eshopRepository->findAndModify([EshopMeta::SLUG => $slug], EshopMeta::toArray($eshop), ["_id"], ["upsert" => true, "new" => true]); var_dump($eshopDoc); } }