1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
   | $em = $this->getContainer()->get('doctrine')->getEntityManager();
        $em->getConnection()->getConfiguration()->setSQLLogger(null);
        $connection = $em->getConnection();
        $platform = $connection->getDatabasePlatform();
        $connection->executeUpdate($platform->getTruncateTableSQL('search', true));
        $limit = (int) $input->getArgument('limit');
 
        $numfilms = $em->getRepository('MPMPBundle:Film')->count();
        $output->writeln($numfilms . " FILMS DANS LA BASE");
        $max = ceil($numfilms / $limit);
 
        $films = $em->createQuery('SELECT f FROM MPMPBundle:Film f');
 
        $iterableResult = $films->iterate();
        $i = 0;
        $batchSize = $limit;
        foreach ($iterableResult AS $row) {
 
            //$film = $row[0];
            if (($i % $batchSize) == 0) {
                $output->write(" Memory usage inside loop: " . floor((memory_get_usage() / 1024)) . " KB\r");
            }
            $em->detach($row[0]);
            ++$i;
        }
        $em->flush(); // Executes all updates.
        $em->clear(); // Detaches all objects from Doctrine! | 
Partager