connectionParams = array( 'dbname' => 'ae000_parser', 'user' => 'root', 'password' => '', 'host' => 'localhost', 'driver' => 'pdo_mysql', 'charset' => 'utf8mb4' ); else $this->connectionParams = array( 'dbname' => 'tm_parser', 'user' => 'timodna', 'password' => '8073Rjkz', 'host' => '0.0.0.0:3310', 'driver' => 'pdo_mysql', 'charset' => 'utf8mb4' ); $config = new \Doctrine\DBAL\Configuration(); $this->conn = \Doctrine\DBAL\DriverManager::getConnection($this->connectionParams, $config); $this->em=$em; } public function getProducts($with_discount=1, $from=0, $limit=20) { $sql="select * from product where status=1 and discount>0 order by id desc limit 20"; $result = $this->conn->query($sql); $products=[]; while ($row = $result->fetch()) { $products[]=$row; } return $products; } public function syncCategories() { $sql = "Select * from categories"; $result = $this->conn->query($sql); $added = []; while($category = $result->fetch()) { //check if category does not exist - add. if(!$this->em->getRepository(Category::class)->findOneBy(['tmId'=>$category['id']])) { $newCat=new Category(); $newCat->setName($category['name']); $newCat->setParent($category['parent']); $newCat->setDescription($category['meta_description']); $newCat->setKeywords($category['keywords']); $newCat->setTmId($category['id']); $this->em->persist($newCat); $this->em->flush(); array_push($added,$newCat->getTmId()); } } return $added; } public function syncProducts() { $sql="select * from product where status=1 and discount>0 order by id";// desc limit 20 $result = $this->conn->query($sql); //sett all products to status 0, then sync with TM $this->em->createQueryBuilder()->update('product')->set('status',0); $added = 0; while($item = $result->fetch()) { //new product - add, old - update $product = $this->em->getRepository(Product::class)->findOneBy(['tmId'=>$item['id']]); if(!$product) { $new=new Product(); $new->setTmId($item['id']); $new->setName($item['name']); $new->setKeywords($item['keywords']); $new->setDescription($item['description']); $new->setArticul($item['articul']); $new->setCategory($item['cat_main']); $new->setDateParsed(new \DateTime($item['date_parsed'])); $new->setDiscount($item['discount']); $new->setHasDiscount($item['has_discount']); $new->setImagesTimodna($item['images_timodna']); $new->setIsNew($item['is_new']); $new->setMetaDescription($item['meta_description']); $new->setModel($item['model']); $new->setParams(json_decode($item['params']));//json_encode($item['params']) $new->setPrice($item['price']); $new->setSizes($item['sizes']); $new->setSale($item['on_sale']); $new->setStatus($item['status']); $new->setArticul($item['articul']); $this->em->persist($new); $this->em->flush(); $new = NULL; }else{//update $product->setName($item['name']); $product->setKeywords($item['keywords']); $product->setDescription($item['description']); $product->setArticul($item['articul']); $product->setCategory($item['cat_main']); $product->setDateParsed(new \DateTime($item['date_parsed'])); $product->setDiscount($item['discount']); $product->setHasDiscount($item['has_discount']); $product->setImagesTimodna($item['images_timodna']); $product->setIsNew($item['is_new']); $product->setMetaDescription($item['meta_description']); $product->setModel($item['model']); $product->setParams(json_decode($item['params'])); $product->setPrice($item['price']); $product->setSizes($item['sizes']); $product->setSale($item['on_sale']); $product->setStatus($item['status']); $this->em->flush(); $product=NULL; } $added++; } return $added; } }
Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Expected to find class "App\Service\SyncTMProducts" in file "/home/okhwulkq/app/src/Service/SyncTMProducts.php" while importing services from resource "../src/*", but it was not found! Check the namespace prefix used with the resource. in /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/FileLoader.php:224 Stack trace: #0 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/FileLoader.php(105): Symfony\Component\DependencyInjection\Loader\FileLoader->findClasses() #1 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(699): Symfony\Component\DependencyInjection\Loader\FileLoader->registerClasses() #2 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(256): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseDefinition() #3 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(176): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseDefinitions() #4 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php(132): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->loadContent() #5 /home/okhwulkq/app/vendor/symfony/config/Loader/FileLoader.php(159): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->load() #6 /home/okhwulkq/app/vendor/symfony/config/Loader/FileLoader.php(98): Symfony\Component\Config\Loader\FileLoader->doImport() #7 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/FileLoader.php(66): Symfony\Component\Config\Loader\FileLoader->import() #8 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/GlobFileLoader.php(27): Symfony\Component\DependencyInjection\Loader\FileLoader->import() #9 /home/okhwulkq/app/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInjection\Loader\GlobFileLoader->load() #10 /home/okhwulkq/app/src/Kernel.php(42): Symfony\Component\Config\Loader\DelegatingLoader->load() #11 /home/okhwulkq/app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(81): App\Kernel->configureContainer() #12 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(39): App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}() #13 /home/okhwulkq/app/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInjection\Loader\ClosureLoader->load() #14 /home/okhwulkq/app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(84): Symfony\Component\Config\Loader\DelegatingLoader->load() #15 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(651): App\Kernel->registerContainerConfiguration() #16 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(547): Symfony\Component\HttpKernel\Kernel->buildContainer() #17 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(789): Symfony\Component\HttpKernel\Kernel->initializeContainer() #18 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(190): Symfony\Component\HttpKernel\Kernel->preBoot() #19 /home/okhwulkq/app/public/index.php(25): Symfony\Component\HttpKernel\Kernel->handle() #20 {main} Next Symfony\Component\Config\Exception\LoaderLoadException: Expected to find class "App\Service\SyncTMProducts" in file "/home/okhwulkq/app/src/Service/SyncTMProducts.php" while importing services from resource "../src/*", but it was not found! Check the namespace prefix used with the resource in /home/okhwulkq/app/config/services.yaml (which is loaded in resource "/home/okhwulkq/app/config/services.yaml"). in /home/okhwulkq/app/vendor/symfony/config/Loader/FileLoader.php:174 Stack trace: #0 /home/okhwulkq/app/vendor/symfony/config/Loader/FileLoader.php(98): Symfony\Component\Config\Loader\FileLoader->doImport() #1 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/FileLoader.php(66): Symfony\Component\Config\Loader\FileLoader->import() #2 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/GlobFileLoader.php(27): Symfony\Component\DependencyInjection\Loader\FileLoader->import() #3 /home/okhwulkq/app/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInjection\Loader\GlobFileLoader->load() #4 /home/okhwulkq/app/src/Kernel.php(42): Symfony\Component\Config\Loader\DelegatingLoader->load() #5 /home/okhwulkq/app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(81): App\Kernel->configureContainer() #6 /home/okhwulkq/app/vendor/symfony/dependency-injection/Loader/ClosureLoader.php(39): App\Kernel->Symfony\Bundle\FrameworkBundle\Kernel\{closure}() #7 /home/okhwulkq/app/vendor/symfony/config/Loader/DelegatingLoader.php(40): Symfony\Component\DependencyInjection\Loader\ClosureLoader->load() #8 /home/okhwulkq/app/vendor/symfony/framework-bundle/Kernel/MicroKernelTrait.php(84): Symfony\Component\Config\Loader\DelegatingLoader->load() #9 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(651): App\Kernel->registerContainerConfiguration() #10 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(547): Symfony\Component\HttpKernel\Kernel->buildContainer() #11 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(789): Symfony\Component\HttpKernel\Kernel->initializeContainer() #12 /home/okhwulkq/app/vendor/symfony/http-kernel/Kernel.php(190): Symfony\Component\HttpKernel\Kernel->preBoot() #13 /home/okhwulkq/app/public/index.php(25): Symfony\Component\HttpKernel\Kernel->handle() #14 {main} thrown in /home/okhwulkq/app/vendor/symfony/config/Loader/FileLoader.php on line 174