public function updateFromCsv()
    {
        $files = array_diff(scandir($this->directory . '/in', SCANDIR_SORT_NONE), ['..', '.']);
        foreach ($files as $file) {
            if (0 !== strpos($file, 'game-update')) {
                continue;
            }

            $fileIn  = $this->directory . '/in/' . $file;
            $fileOut = $this->directory . '/out/' . $file;
            $handle  = fopen($fileIn, 'rb');
            $idGame  = substr($file, 11, -4);

            if (!is_numeric($idGame)) {
                continue;
            }

            $group = null;
            $types = null;
            while (($row = fgetcsv($handle, null, ';')) !== false) {
                list($type, $id, $libEn, $libFr) = $row;
                switch ($type) {
                    case 'object':
                        // DO nothing
                        break;
                    case 'group':
                        $group = $this->em->getRepository('VideoGamesRecordsCoreBundle:Group')->find($id);
                        $group->translate('en', false)->setName($libEn);
                        $group->translate('fr', false)->setName($libFr);
                        $group->mergeNewTranslations();
                        $this->em->persist($group);
                        break;
                    case 'chart':
                        $chart = $this->em->getRepository('VideoGamesRecordsCoreBundle:Chart')->find($id);
                        $chart->translate('en', false)->setName($libEn);
                        $chart->translate('fr', false)->setName($libFr);
                        $chart->mergeNewTranslations();
                        $this->em->persist($chart);
                        break;
                }
            }
            $this->em->flush();
            rename($fileIn, $fileOut);
        }
    }
public function updateFromCsv()
    {
        $files = array_diff(scandir($this->directory . '/in', SCANDIR_SORT_NONE), ['..', '.']);
        foreach ($files as $file) {
            if (0 !== strpos($file, 'game-update')) {
                continue;
            }

            $fileIn  = $this->directory . '/in/' . $file;
            $fileOut = $this->directory . '/out/' . $file;
            $handle  = fopen($fileIn, 'rb');
            $idGame  = substr($file, 11, -4);

            if (!is_numeric($idGame)) {
                continue;
            }

            $group = null;
            $types = null;
            while (($row = fgetcsv($handle, null, ';')) !== false) {
                list($type, $id, $libEn, $libFr) = $row;
                switch ($type) {
                    case 'object':
                        // DO nothing
                        break;
                    case 'group':
                        $group = $this->em->getRepository('VideoGamesRecordsCoreBundle:Group')->find($id);
                        $group->translate('en', false)->setName($libEn);
                        $group->translate('fr', false)->setName($libFr);
                        $group->mergeNewTranslations();
                        $this->em->persist($group);
                        break;
                    case 'chart':
                        $chart = $this->em->getRepository('VideoGamesRecordsCoreBundle:Chart')->find($id);
                        $chart->translate('en', false)->setName($libEn);
                        $chart->translate('fr', false)->setName($libFr);
                        $chart->mergeNewTranslations();
                        $this->em->persist($chart);
                        break;
                }
            }
            $this->em->flush();
            rename($fileIn, $fileOut);
        }
    }
public function updateFromCsv ( ) { $ files = array_diff ( scandir ( $ this -> directory . '/in' , SCANDIR_SORT_NONE ) , [ '..' , '.' ] ) ; foreach ( $ files as $ file ) { if ( 0 !== strpos ( $ file , 'game-update' ) ) { continue ; } $ fileIn = $ this -> directory . '/in/' . $ file ; $ fileOut = $ this -> directory . '/out/' . $ file ; $ handle = fopen ( $ fileIn , 'rb' ) ; $ idGame = substr ( $ file , 11 , - 4 ) ; if ( ! is_numeric ( $ idGame ) ) { continue ; } $ group = null ; $ types = null ; while ( ( $ row = fgetcsv ( $ handle , null , ';' ) ) !== false ) { list ( $ type , $ id , $ libEn , $ libFr ) = $ row ; switch ( $ type ) { case 'object' : // DO nothing break ; case 'group' : $ group = $ this -> em -> getRepository ( 'VideoGamesRecordsCoreBundle:Group' ) -> find ( $ id ) ; $ group -> translate ( 'en' , false ) -> setName ( $ libEn ) ; $ group -> translate ( 'fr' , false ) -> setName ( $ libFr ) ; $ group -> mergeNewTranslations ( ) ; $ this -> em -> persist ( $ group ) ; break ; case 'chart' : $ chart = $ this -> em -> getRepository ( 'VideoGamesRecordsCoreBundle:Chart' ) -> find ( $ id ) ; $ chart -> translate ( 'en' , false ) -> setName ( $ libEn ) ; $ chart -> translate ( 'fr' , false ) -> setName ( $ libFr ) ; $ chart -> mergeNewTranslations ( ) ; $ this -> em -> persist ( $ chart ) ; break ; } } $ this -> em -> flush ( ) ; rename ( $ fileIn , $ fileOut ) ; } }
Update groups and charts from a csv file
Update groups and charts from a csv file