| @@ -18,7 +18,7 @@ discard block | ||
| 18 | 18 | use Symfony\Component\Form\FormBuilderInterface; | 
| 19 | 19 | use Symfony\Component\HttpFoundation\File\File; | 
| 20 | 20 | |
| 21 | -class SonataImportCommand extends ContainerAwareCommand{ | |
| 21 | +class SonataImportCommand extends ContainerAwareCommand { | |
| 22 | 22 | |
| 23 | 23 | /** @var EntityManager $this->em */ | 
| 24 | 24 | protected $em; | 
| @@ -46,17 +46,16 @@ discard block | ||
| 46 | 46 |          $uploadFile = $this->em->getRepository('DoctrsSonataImportBundle:UploadFile')->find($uploadFileId); | 
| 47 | 47 |          $fileLoaders = $this->getContainer()->getParameter('doctrs_sonata_import.class_loaders'); | 
| 48 | 48 | $fileLoader = isset($fileLoaders[$fileLoaderId], $fileLoaders[$fileLoaderId]['class']) ? | 
| 49 | - $fileLoaders[$fileLoaderId]['class'] : | |
| 50 | - null; | |
| 49 | + $fileLoaders[$fileLoaderId]['class'] : null; | |
| 51 | 50 | |
| 52 | -        if(!class_exists($fileLoader)){ | |
| 51 | +        if (!class_exists($fileLoader)) { | |
| 53 | 52 | $uploadFile->setStatus(UploadFile::STATUS_ERROR); | 
| 54 | 53 |              $uploadFile->setMessage('class_loader not found'); | 
| 55 | 54 | $this->em->flush($uploadFile); | 
| 56 | 55 | return; | 
| 57 | 56 | } | 
| 58 | 57 | $fileLoader = new $fileLoader(); | 
| 59 | -        if(!$fileLoader instanceof FileLoaderInterface){ | |
| 58 | +        if (!$fileLoader instanceof FileLoaderInterface) { | |
| 60 | 59 | $uploadFile->setStatus(UploadFile::STATUS_ERROR); | 
| 61 | 60 |              $uploadFile->setMessage('class_loader must be instanceof "FileLoaderInterface"'); | 
| 62 | 61 | $this->em->flush($uploadFile); | 
| @@ -126,7 +125,7 @@ discard block | ||
| 126 | 125 | } | 
| 127 | 126 | |
| 128 | 127 | } | 
| 129 | -                if(!count($errors)) { | |
| 128 | +                if (!count($errors)) { | |
| 130 | 129 |                      $validator = $this->getContainer()->get('validator'); | 
| 131 | 130 | $errors = $validator->validate($entity); | 
| 132 | 131 | } | 
| @@ -153,7 +152,7 @@ discard block | ||
| 153 | 152 | } | 
| 154 | 153 | $uploadFile->setStatus(UploadFile::STATUS_SUCCESS); | 
| 155 | 154 | $this->em->flush($uploadFile); | 
| 156 | -        } catch(\Exception $e){ | |
| 155 | +        } catch (\Exception $e) { | |
| 157 | 156 | /** | 
| 158 | 157 | * Данный хак нужен в случае бросания ORMException | 
| 159 | 158 | * В случае бросания ORMException entity manager останавливается | 
| @@ -178,7 +177,7 @@ discard block | ||
| 178 | 177 |          return $method . str_replace(' ', '', ucfirst(join('', explode('_', $name)))); | 
| 179 | 178 | } | 
| 180 | 179 | |
| 181 | -    protected function setValue($value, FormBuilderInterface $fieldDescription, AbstractAdmin $admin){ | |
| 180 | +    protected function setValue($value, FormBuilderInterface $fieldDescription, AbstractAdmin $admin) { | |
| 182 | 181 | |
| 183 | 182 |          $mappings = $this->getContainer()->getParameter('doctrs_sonata_import.mappings'); | 
| 184 | 183 | |
| @@ -190,9 +189,9 @@ discard block | ||
| 190 | 189 | * Проверяем кастомные типы форм на наличие в конфиге. | 
| 191 | 190 | * В случае совпадения, получаем значение из класса, указанного в конфиге | 
| 192 | 191 | */ | 
| 193 | -        foreach($mappings as $item){ | |
| 194 | -            if($item['name'] === $type){ | |
| 195 | -                if($this->getContainer()->has($item['class']) && $this->getContainer()->get($item['class']) instanceof ImportInterface){ | |
| 192 | +        foreach ($mappings as $item) { | |
| 193 | +            if ($item['name'] === $type) { | |
| 194 | +                if ($this->getContainer()->has($item['class']) && $this->getContainer()->get($item['class']) instanceof ImportInterface) { | |
| 196 | 195 | /** @var ImportInterface $class */ | 
| 197 | 196 | $class = $this->getContainer()->get($item['class']); | 
| 198 | 197 | return $class->getFormatValue($value); | 
| @@ -219,7 +218,7 @@ discard block | ||
| 219 | 218 |                  $fieldDescription->getOption('class') | 
| 220 | 219 | ) | 
| 221 | 220 |          ) { | 
| 222 | -            if(!$value){ | |
| 221 | +            if (!$value) { | |
| 223 | 222 | return null; | 
| 224 | 223 | } | 
| 225 | 224 | /** @var \Doctrine\ORM\Mapping\ClassMetadata $metaData */ | 
| @@ -245,7 +244,7 @@ discard block | ||
| 245 | 244 | * Если значение число, то пытаемся найти его по ID. | 
| 246 | 245 | * Если значение не число, то ищем его по полю name | 
| 247 | 246 | */ | 
| 248 | -            if(is_numeric($value)){ | |
| 247 | +            if (is_numeric($value)) { | |
| 249 | 248 | $value = $repo->find($value); | 
| 250 | 249 |              } else { | 
| 251 | 250 |                  try { | 
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | use Sonata\AdminBundle\Route\RouteCollection; | 
| 7 | 7 | |
| 8 | -trait AdminImportTrait{ | |
| 8 | +trait AdminImportTrait { | |
| 9 | 9 | |
| 10 | 10 | |
| 11 | 11 | protected function configureRoutes(RouteCollection $collection) | 
| @@ -26,8 +26,8 @@ discard block | ||
| 26 | 26 | ]); | 
| 27 | 27 | $form->handleRequest($request); | 
| 28 | 28 | |
| 29 | -        if($form->isValid()){ | |
| 30 | -            if(!$fileEntity->getFile()->getError()) { | |
| 29 | +        if ($form->isValid()) { | |
| 30 | +            if (!$fileEntity->getFile()->getError()) { | |
| 31 | 31 |                  $fileEntity->move($this->getParameter('doctrs_sonata_import.upload_dir')); | 
| 32 | 32 | |
| 33 | 33 | $this->getDoctrine()->getManager()->persist($fileEntity); | 
| @@ -61,7 +61,7 @@ discard block | ||
| 61 | 61 | * @param UploadFile $uploadFile | 
| 62 | 62 | * @return JsonResponse|\Symfony\Component\HttpFoundation\Response | 
| 63 | 63 | */ | 
| 64 | -    public function uploadAction(Request $request, UploadFile $uploadFile){ | |
| 64 | +    public function uploadAction(Request $request, UploadFile $uploadFile) { | |
| 65 | 65 | $em = $this->getDoctrine()->getManager(); | 
| 66 | 66 | |
| 67 | 67 |          $countImport = $em->getRepository('DoctrsSonataImportBundle:ImportLog')->count([ | 
| @@ -87,7 +87,7 @@ discard block | ||
| 87 | 87 | * @param UploadFile $uploadFile | 
| 88 | 88 | * @return JsonResponse | 
| 89 | 89 | */ | 
| 90 | -    public function importStatusAction(UploadFile $uploadFile){ | |
| 90 | +    public function importStatusAction(UploadFile $uploadFile) { | |
| 91 | 91 |          $countImport = $this->getDoctrine()->getManager()->getRepository('DoctrsSonataImportBundle:ImportLog')->count([ | 
| 92 | 92 | 'uploadFile' => $uploadFile->getId() | 
| 93 | 93 | ]); | 
| @@ -103,10 +103,10 @@ discard block | ||
| 103 | 103 | * get array from A to ZZ | 
| 104 | 104 | * @return array | 
| 105 | 105 | */ | 
| 106 | -    private function getLetterArray(){ | |
| 106 | +    private function getLetterArray() { | |
| 107 | 107 |          $array = range('A', 'Z'); | 
| 108 | 108 | $letters = $array; | 
| 109 | -        foreach($array as $first) { | |
| 109 | +        foreach ($array as $first) { | |
| 110 | 110 |              foreach ($array as $second) { | 
| 111 | 111 | $letters[] = $first . $second; | 
| 112 | 112 | } | 
| @@ -117,7 +117,7 @@ discard block | ||
| 117 | 117 | /** | 
| 118 | 118 | * @param UploadFile $fileEntity | 
| 119 | 119 | */ | 
| 120 | -    private function runCommand(UploadFile $fileEntity){ | |
| 120 | +    private function runCommand(UploadFile $fileEntity) { | |
| 121 | 121 | $command = sprintf( | 
| 122 | 122 | '/usr/bin/php %s/console doctrs:sonata:import %d "%s" "%s" %d > /dev/null 2>&1 &', | 
| 123 | 123 |              $this->get('kernel')->getRootDir(), | 
| @@ -7,12 +7,12 @@ | ||
| 7 | 7 | use Doctrine\ORM\EntityRepository; | 
| 8 | 8 | use Symfony\Component\HttpFoundation\Request; | 
| 9 | 9 | |
| 10 | -class DefaultRepository extends EntityRepository{ | |
| 10 | +class DefaultRepository extends EntityRepository { | |
| 11 | 11 | |
| 12 | -    public function pagerfanta(Request $request){ | |
| 12 | +    public function pagerfanta(Request $request) { | |
| 13 | 13 |          $sql = $this->createQueryBuilder('data'); | 
| 14 | 14 |          $sql->select('data'); | 
| 15 | -        switch($request->get('type', 'all')){ | |
| 15 | +        switch ($request->get('type', 'all')) { | |
| 16 | 16 | case 'success': | 
| 17 | 17 |                  $sql->where('data.status = 1 or data.status = 2'); | 
| 18 | 18 | break; | 
| @@ -2,6 +2,6 @@ | ||
| 2 | 2 | |
| 3 | 3 | namespace Doctrs\SonataImportBundle\Service; | 
| 4 | 4 | |
| 5 | -interface ImportInterface{ | |
| 5 | +interface ImportInterface { | |
| 6 | 6 | public function getFormatValue($value); | 
| 7 | 7 | } | 
| @@ -31,21 +31,20 @@ | ||
| 31 | 31 | * @param array $config | 
| 32 | 32 | * @param ContainerBuilder $container | 
| 33 | 33 | */ | 
| 34 | -    private function prepairConfig(array $config, ContainerBuilder $container){ | |
| 34 | +    private function prepairConfig(array $config, ContainerBuilder $container) { | |
| 35 | 35 | $container->setParameter( | 
| 36 | 36 | 'doctrs_sonata_import.mappings', | 
| 37 | 37 | $config['mappings'] | 
| 38 | 38 | ); | 
| 39 | 39 | $container->setParameter( | 
| 40 | 40 | 'doctrs_sonata_import.upload_dir', | 
| 41 | - $config['upload_dir'] ? $config['upload_dir'] : | |
| 42 | -                $container->get('kernel')->getRootDir() . '/../web/uploads' | |
| 41 | +            $config['upload_dir'] ? $config['upload_dir'] : $container->get('kernel')->getRootDir() . '/../web/uploads' | |
| 43 | 42 | ); | 
| 44 | 43 | $container->setParameter( | 
| 45 | 44 | 'doctrs_sonata_import.class_loaders', | 
| 46 | 45 | $config['class_loaders'] | 
| 47 | 46 | ); | 
| 48 | -        if(!isset($config['encode'])){ | |
| 47 | +        if (!isset($config['encode'])) { | |
| 49 | 48 | $config['encode'] = [ | 
| 50 | 49 | 'default' => 'utf8', | 
| 51 | 50 | 'list' => [] | 
| @@ -138,7 +138,7 @@ discard block | ||
| 138 | 138 | /** | 
| 139 | 139 | * @return mixed | 
| 140 | 140 | */ | 
| 141 | -    public function messageEncode(){ | |
| 141 | +    public function messageEncode() { | |
| 142 | 142 | return json_decode($this->message); | 
| 143 | 143 | } | 
| 144 | 144 | |
| @@ -193,7 +193,7 @@ discard block | ||
| 193 | 193 | * @ORM\PreUpdate() | 
| 194 | 194 | * @ORM\PrePersist() | 
| 195 | 195 | */ | 
| 196 | -    public function prePersistUpdate(){ | |
| 196 | +    public function prePersistUpdate() { | |
| 197 | 197 | $this->ts = new \DateTime(); | 
| 198 | 198 | } | 
| 199 | 199 | |
| @@ -201,7 +201,7 @@ discard block | ||
| 201 | 201 | * @param $foreignId | 
| 202 | 202 | * @return ImportLog | 
| 203 | 203 | */ | 
| 204 | -    public function setForeignId($foreignId){ | |
| 204 | +    public function setForeignId($foreignId) { | |
| 205 | 205 | $this->foreignId = $foreignId; | 
| 206 | 206 | |
| 207 | 207 | return $this; | 
| @@ -210,7 +210,7 @@ discard block | ||
| 210 | 210 | /** | 
| 211 | 211 | * @return int | 
| 212 | 212 | */ | 
| 213 | -    public function getForeignId(){ | |
| 213 | +    public function getForeignId() { | |
| 214 | 214 | return $this->foreignId; | 
| 215 | 215 | } | 
| 216 | 216 | |
| @@ -119,8 +119,8 @@ discard block | ||
| 119 | 119 | * @ORM\PrePersist() | 
| 120 | 120 | * @ORM\PreUpdate() | 
| 121 | 121 | */ | 
| 122 | -    public function prePersistUpdate(){ | |
| 123 | -        if(!$this->status){ | |
| 122 | +    public function prePersistUpdate() { | |
| 123 | +        if (!$this->status) { | |
| 124 | 124 | $this->status = self::STATUS_LOAD; | 
| 125 | 125 | } | 
| 126 | 126 | $this->ts = new \DateTime(); | 
| @@ -130,7 +130,7 @@ discard block | ||
| 130 | 130 | * @param $encode | 
| 131 | 131 | * @return UploadFile | 
| 132 | 132 | */ | 
| 133 | -    public function setEncode($encode){ | |
| 133 | +    public function setEncode($encode) { | |
| 134 | 134 | $this->encode = $encode; | 
| 135 | 135 | |
| 136 | 136 | return $this; | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | /** | 
| 140 | 140 | * @return string | 
| 141 | 141 | */ | 
| 142 | -    public function getEncode(){ | |
| 142 | +    public function getEncode() { | |
| 143 | 143 | return $this->encode; | 
| 144 | 144 | } | 
| 145 | 145 | |
| @@ -147,7 +147,7 @@ discard block | ||
| 147 | 147 | * @param $message | 
| 148 | 148 | * @return UploadFile | 
| 149 | 149 | */ | 
| 150 | -    public function setMessage($message){ | |
| 150 | +    public function setMessage($message) { | |
| 151 | 151 | $this->message = $message; | 
| 152 | 152 | |
| 153 | 153 | return $this; | 
| @@ -156,7 +156,7 @@ discard block | ||
| 156 | 156 | /** | 
| 157 | 157 | * @return string | 
| 158 | 158 | */ | 
| 159 | -    public function getMessage(){ | |
| 159 | +    public function getMessage() { | |
| 160 | 160 | return $this->message; | 
| 161 | 161 | } | 
| 162 | 162 | |
| @@ -164,7 +164,7 @@ discard block | ||
| 164 | 164 | * @param $status | 
| 165 | 165 | * @return UploadFile | 
| 166 | 166 | */ | 
| 167 | -    public function setStatus($status){ | |
| 167 | +    public function setStatus($status) { | |
| 168 | 168 | $this->status = $status; | 
| 169 | 169 | |
| 170 | 170 | return $this; | 
| @@ -173,7 +173,7 @@ discard block | ||
| 173 | 173 | /** | 
| 174 | 174 | * @return string | 
| 175 | 175 | */ | 
| 176 | -    public function getStatus(){ | |
| 176 | +    public function getStatus() { | |
| 177 | 177 | return $this->status; | 
| 178 | 178 | } | 
| 179 | 179 | |
| @@ -181,7 +181,7 @@ discard block | ||
| 181 | 181 | * @param $loaderClass | 
| 182 | 182 | * @return $this | 
| 183 | 183 | */ | 
| 184 | -    public function setLoaderClass($loaderClass){ | |
| 184 | +    public function setLoaderClass($loaderClass) { | |
| 185 | 185 | $this->loaderClass = $loaderClass; | 
| 186 | 186 | |
| 187 | 187 | return $this; | 
| @@ -190,11 +190,11 @@ discard block | ||
| 190 | 190 | /** | 
| 191 | 191 | * @return string | 
| 192 | 192 | */ | 
| 193 | -    public function getLoaderClass(){ | |
| 193 | +    public function getLoaderClass() { | |
| 194 | 194 | return $this->loaderClass; | 
| 195 | 195 | } | 
| 196 | 196 | |
| 197 | -    public function move($uploadDir){ | |
| 197 | +    public function move($uploadDir) { | |
| 198 | 198 | $file = $this->getFile(); | 
| 199 | 199 | $fileName = md5(uniqid() . time()) . '.' . $file->guessExtension(); | 
| 200 | 200 | $file->move($uploadDir, $fileName); | 
| @@ -35,7 +35,7 @@ | ||
| 35 | 35 | /** | 
| 36 | 36 | * @return string | 
| 37 | 37 | */ | 
| 38 | -    public function getBlockPrefix(){ | |
| 38 | +    public function getBlockPrefix() { | |
| 39 | 39 | return $this->getName(); | 
| 40 | 40 | } | 
| 41 | 41 | |