The first and only rule with EntityRepository is not to ever inherit them, ever. The only valid reason to inherit EntityRepository is to add more common methods to all EntityRepositories in application, when you're creating your own framework (but do we really need to go any deeper than this?).
Автор: Filip Procházka (filip@prochazka.su)
Наследование: extends Doctrine\ORM\EntityRepository, implements Kdyby\Persistence\QueryExecutor, implements Kdyby\Persistence\Queryable
Пример #1
0
 /**
  * @param \Venne\Queue\Job $job
  * @param integer $priority
  */
 public function run(Job $job, $priority)
 {
     /** @var Notification $notificationEntity */
     $notificationEntity = $this->notificationRepository->find($job->arguments[0]);
     if ($notificationEntity === null) {
         return;
     }
     $qb = $this->notificationSettingRepository->createQueryBuilder('a')->andWhere('a.type IS NULL OR a.type = :type')->setParameter('type', $notificationEntity->type->id);
     if ($notificationEntity->user) {
         $qb = $qb->andWhere('a.targetUser IS NULL OR a.targetUser = :targetUser')->setParameter('targetUser', $notificationEntity->user->id);
     }
     if ($notificationEntity->target) {
         $qb = $qb->andWhere('a.target IS NULL OR a.target = :target')->setParameter('target', $notificationEntity->target);
     }
     if ($notificationEntity->targetKey) {
         $qb = $qb->andWhere('a.targetKey IS NULL OR a.targetKey = :targetKey')->setParameter('targetKey', $notificationEntity->targetKey);
     }
     $users = array();
     foreach ($qb->getQuery()->getResult() as $setting) {
         $user = $setting->user !== null ? $setting->user : $notificationEntity->user;
         if (isset($users[$user->id]) && !$users[$user->id]['email']) {
             $users[$user->id]['email'] = $setting->email;
         } else {
             $users[$user->id] = array('user' => $user, 'email' => $setting->user !== null ? $setting->email : $notificationEntity->user->getEmail());
         }
     }
     foreach ($users as $user) {
         $notificationUser = new NotificationUser($notificationEntity, $user['user']);
         $this->entityManager->persist($notificationUser);
         $this->entityManager->flush($notificationUser);
         if ($user['email']) {
             $this->jobManager->scheduleJob(new Job(EmailJob::getName(), null, array('user' => $user['user'] instanceof User ? $user['user']->id : $user['user'], 'notification' => $notificationUser->id)), $priority);
         }
     }
 }
Пример #2
0
 /**
  * @return \Venne\System\Components\AdminGrid\AdminGrid
  */
 protected function createComponentTable()
 {
     $qb = $this->notificationSettingRepository->createQueryBuilder('a')->andWhere('a.user = :user')->setParameter('user', $this->presenter->user->identity->getId());
     $admin = $this->adminGridFactory->create($this->notificationSettingRepository);
     $table = $admin->getTable();
     $table->setTranslator($this->translator);
     $table->setModel(new Doctrine($qb));
     // columns
     $table->addColumnText('user', 'User')->getCellPrototype()->width = '15%';
     $table->addColumnText('type', 'Type')->setSortable()->setCustomRender(function (NotificationSetting $entity) {
         return $entity->type !== null ? $this->notificationManager->getType($entity->type->type)->getHumanName() : '';
     })->getCellPrototype()->width = '20%';
     $table->addColumnText('action', 'Action')->setCustomRender(function (NotificationSetting $entity) {
         return $entity->type !== null ? $entity->type->action : '';
     })->getCellPrototype()->width = '15%';
     $table->addColumnText('target', 'Target')->getCellPrototype()->width = '20%';
     $table->addColumnText('targetKey', 'Target key')->getCellPrototype()->width = '10%';
     $table->addColumnText('targetUser', 'Target user')->getCellPrototype()->width = '20%';
     // actions
     $event = $table->addActionEvent('edit', 'Edit');
     $event->getElementPrototype()->class[] = 'ajax';
     $form = $admin->addForm('notification', 'Notification setting', function (NotificationSetting $notificationSetting = null) {
         return $this->notificationSettingFormService->getFormFactory($notificationSetting !== null ? $notificationSetting->getId() : null);
     });
     $admin->connectFormWithAction($form, $event);
     // Toolbar
     $toolbar = $admin->getNavbar();
     $section = $toolbar->addSection('new', 'Create', 'file');
     $admin->connectFormWithNavbar($form, $section);
     $deleteEvent = $table->addActionEvent('delete', 'Delete');
     $deleteEvent->getElementPrototype()->class[] = 'ajax';
     $admin->connectActionAsDelete($deleteEvent);
     return $admin;
 }
Пример #3
0
 public function actionImage()
 {
     if (substr($this->url, 0, 7) === self::DIRECTORY_CACHE . '/') {
         $this->cached = true;
         $this->url = substr($this->url, 7);
     }
     if (($entity = $this->fileRepository->findOneBy(array('path' => $this->url))) === null) {
         throw new \Nette\Application\BadRequestException(sprintf('File \'%s\' does not exist.', $this->url));
     }
     $image = Image::fromFile($entity->getFilePath());
     $this->session->close();
     // resize
     if ($this->size && $this->size !== 'default') {
         if (strpos($this->size, 'x') !== false) {
             $format = explode('x', $this->size);
             $width = $format[0] !== '?' ? $format[0] : null;
             $height = $format[1] !== '?' ? $format[1] : null;
             $image->resize($width, $height, $this->format !== 'default' ? $this->format : Image::FIT);
         }
     }
     if (!$this->type) {
         $this->type = substr($entity->getName(), strrpos($entity->getName(), '.'));
     }
     $type = $this->type === 'jpg' ? Image::JPEG : $this->type === 'gif' ? Image::GIF : Image::PNG;
     $file = sprintf('%s/%s/%s/%s/%s/%s', $this->cacheDir, self::DIRECTORY_CACHE, $this->size, $this->format, $this->type, $entity->getPath());
     $dir = dirname($file);
     umask(00);
     @mkdir($dir, 0777, true);
     $image->save($file, 90, $type);
     $image->send($type, 90);
 }
Пример #4
0
 /**
  * @param \Venne\Queue\Job $job
  * @param integer $priority
  */
 public function run(Job $job, $priority)
 {
     $user = $this->userRepository->find($job->arguments['user']);
     $notificationUser = $this->notificationUserRepository->find($job->arguments['notification']);
     $notification = $notificationUser->getNotification();
     $this->emailManager->send($user->email, $user->name, NotificationEvent::getName(), 'userNotification', array('type' => $notification->type->type, 'action' => $notification->type->action, 'message' => $notification->type->message, 'user' => $notification->user, 'notification' => $notification, 'notificationManager' => $this));
 }
Пример #5
0
 public function render()
 {
     $this->template->job = $this->dataTransferManager->createQuery(JobDto::class, function () {
         return $this->jobRepository->find($this->id);
     })->enableCache()->fetch();
     $this->template->render();
 }
Пример #6
0
 /**
  * @return \Venne\System\Components\AdminGrid\AdminGrid
  */
 protected function createComponentTable()
 {
     $admin = $this->adminGridFactory->create($this->jobRepository);
     $table = $admin->getTable();
     $table->addColumnText('type', 'Type')->getCellPrototype()->width = '35%';
     $table->addColumnText('state', 'State')->getCellPrototype()->width = '15%';
     $table->addColumnText('priority', 'Priority')->getCellPrototype()->width = '10%';
     $table->addColumnDate('date', 'Date')->getCellPrototype()->width = '15%';
     $table->addColumnDate('dateInterval', 'Interval')->getCellPrototype()->width = '15%';
     $table->addColumnDate('round', 'Round')->getCellPrototype()->width = '10%';
     // actions
     $table->addActionEvent('run', 'Run')->onClick[] = function ($id) {
         $job = $this->jobRepository->find($id);
         try {
             $this->jobManager->scheduleJob($job, JobManager::PRIORITY_REALTIME);
             $this->flashMessage($this->getTranslator()->translate('Job has been done.'), 'success');
         } catch (JobFailedException $e) {
             $this->flashMessage($this->getTranslator()->translate('Job failed.'), 'warning');
         }
         $this->redirect('this');
     };
     $table->addActionEvent('edit', 'Edit')->getElementPrototype()->class[] = 'ajax';
     $form = $admin->addForm('job', 'Job', function (Job $job = null) {
         return $this->jobFormService->getFormFactory($job !== null ? $job->getId() : null);
     });
     $admin->connectFormWithAction($form, $table->getAction('edit'));
     $table->addActionEvent('delete', 'Delete')->getElementPrototype()->class[] = 'ajax';
     $admin->connectActionAsDelete($table->getAction('delete'));
     return $admin;
 }
 /**
  * @inheritdoc
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     ini_set('memory_limit', '4G');
     $lang = $input->getArgument(self::LANGUAGE_ARGUMENT);
     /** @var Language $language */
     if (($language = $this->languagesRepository->findOneBy(['shortCode' => $lang])) === NULL) {
         $output->writeln("<error>Unknown language {$lang} given!");
         return 1;
     }
     $index = $this->elastic->getIndex('dwarf');
     $type = $index->getType($language->getShortCode() . '_screenplay');
     /** @var Season[] $seasons */
     $seasons = $this->seasonsRepository->findBy(['language' => $language]);
     foreach ($seasons as $season) {
         $output->writeln("Importing season {$season->getNumber()}...");
         foreach ($season->getEpisodes() as $episode) {
             foreach ($episode->getScenarios() as $screenplay) {
                 if ($screenplay->getCharacter() !== NULL) {
                     $document = new Document($screenplay->getId(), ['text' => $screenplay->getText(), 'episode' => ['id' => $episode->getId(), 'number' => $episode->getNumber(), 'name' => $episode->getName(), 'slug' => $episode->getSlug()], 'season' => ['id' => $season->getId(), 'number' => $season->getNumber()], 'character' => ['name' => $screenplay->getCharacter()->getName(), 'slug' => $screenplay->getCharacter()->getSLug()], 'line' => $screenplay->getLine()], $type, $index);
                     $type->addDocument($document);
                 }
             }
         }
     }
 }
Пример #8
0
 /**
  * @return \Venne\System\Components\AdminGrid\AdminGrid
  */
 public function create()
 {
     $admin = $this->adminGridFactory->create($this->invitationRepository);
     $qb = $this->invitationRepository->createQueryBuilder('a')->andWhere('a.author = :author')->setParameter('author', $this->netteUser->identity->getId());
     $table = $admin->getTable();
     $table->setModel(new Doctrine($qb));
     $table->setTranslator($this->translator);
     $table->addColumnText('email', 'E-mail')->setSortable()->getCellPrototype()->width = '60%';
     $table->getColumn('email')->setFilterText()->setSuggestion();
     $table->addColumnText('type', 'Type')->setCustomRender(function (Invitation $invitationEntity) {
         return $invitationEntity->registration->getName();
     })->getCellPrototype()->width = '40%';
     $form = $admin->addForm('invitation', 'Invitation', function (Invitation $invitation = null) {
         return $this->invitationFormService->getFormFactory($invitation !== null ? $invitation->getId() : null);
     });
     $toolbar = $admin->getNavbar();
     $newSection = $toolbar->addSection('new', 'Create', 'file');
     $editAction = $table->addActionEvent('edit', 'Edit');
     $editAction->getElementPrototype()->class[] = 'ajax';
     $deleteAction = $table->addActionEvent('delete', 'Delete');
     $deleteAction->getElementPrototype()->class[] = 'ajax';
     $admin->connectFormWithNavbar($form, $newSection);
     $admin->connectFormWithAction($form, $editAction);
     $admin->connectActionAsDelete($deleteAction);
     return $admin;
 }
 public function getFreeAddress() : Address
 {
     if ($this->addressRepository->countBy([]) == 0) {
         $this->generateAndPersistNewAddresses(10);
     }
     $this->entityManager->beginTransaction();
     $addressMaxAge = new \DateTime($this->addressLockTime);
     $qb = $this->addressRepository->createQueryBuilder('address');
     $qb->addSelect('count(address) as free')->where('address.lastUsed IS NULL')->orWhere('address.lastUsed < :maxAge')->setParameter('maxAge', $addressMaxAge)->setMaxResults(1);
     /** @var Address $address */
     $result = $qb->getQuery()->getSingleResult();
     $address = $result[0];
     $free = $result['free'];
     $address->useAddress();
     $this->entityManager->flush($address);
     $qb = $this->entityManager->createQueryBuilder();
     $qb->select('COUNT(address) AS total')->from(Address::getClassName(), 'address');
     $total = $qb->getQuery()->getSingleScalarResult();
     $occupied = $total - $free;
     if ($occupied / $total >= $this->occupiedAddressesTreshold) {
         $this->generateAndPersistNewAddresses(round($total * $this->increaseRatio));
     }
     $this->entityManager->commit();
     return $address;
 }
Пример #10
0
 /**
  * @param \Nette\Application\UI\Form $form
  * @param string $resetKey
  */
 protected function save(Form $form, $resetKey)
 {
     $user = $this->userRepository->findOneBy(array('resetKey' => $resetKey));
     $user->removeResetKey($resetKey);
     $user->setPassword($form['password']->getValue());
     $this->entityManager->flush();
     $this->securityManager->sendNewPassword($user);
 }
Пример #11
0
 /**
  * Vraci vsechny uzivatele systemu
  * @param array $limits SQL limit a offset
  * @return Entities\User[] 
  */
 public function findAllUsers($limits = [])
 {
     if (empty($limits)) {
         $limits['offset'] = NULL;
         $limits['limit'] = NULL;
     }
     return $this->repository->findBy([], ['id' => 'DESC'], $limits['limit'], $limits['offset']);
 }
Пример #12
0
 /**
  * @param integer|null $primaryKey
  * @param integer|null $parentId
  * @return \Venne\Files\File
  */
 protected function getEntity($primaryKey, $parentId = null)
 {
     $entity = parent::getEntity($primaryKey);
     if ($parentId !== null) {
         $entity->setParent($this->dirRepository->find($parentId));
     }
     return $entity;
 }
Пример #13
0
 /**
  * @param int $id
  * @return Episode|NULL
  */
 public function find($id)
 {
     try {
         return $this->episodesRepository->createQueryBuilder('e')->innerJoin('e.scenarios', 'scenarios')->addSelect('scenarios')->innerJoin('e.season', 'season')->addSelect('season')->leftJoin('scenarios.character', 'character')->addSelect('character')->andWhere('e.id = :id')->setParameter('id', $id)->addOrderBy('scenarios.line')->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         return NULL;
     }
 }
Пример #14
0
 public function render()
 {
     if ($this->id !== null) {
         $this->template->notification = $this->dataTransferManager->createQuery(NotificationDto::class, function () {
             return $this->notificationUserRepository->find($this->id);
         })->enableCache()->fetch();
     }
     $this->template->render();
 }
Пример #15
0
 /**
  * @param string $email
  * @return Invitation
  * @throws InvitationNotFoundException
  */
 public function getInvitationByEmail($email)
 {
     $qb = $this->invitationsRepository->createQueryBuilder('i')->where('i.email = :email')->setParameter('email', $email);
     try {
         return $qb->getQuery()->getSingleResult();
     } catch (NoResultException $e) {
         $this->onInfo("Email: {$email} NOT found. [getInvitationByEmail]", $e, self::class);
         throw new InvitationNotFoundException();
     }
 }
Пример #16
0
 public function getText($ident)
 {
     if ($this->authorizator->canRead($ident)) {
         $et = $this->editableTextRepository->find($ident);
         if ($et === NULL) {
             return NULL;
         } else {
             return $et->getText();
         }
     } else {
         throw new AuthenticationException("You have no authorization to get text");
     }
 }
Пример #17
0
 /**
  * @param \Nette\Application\UI\Form $form
  * @param callable $resetLinkCallback
  */
 protected function save(Form $form, $resetLinkCallback)
 {
     /** @var \Venne\Security\User $user */
     $user = $this->userRepository->findOneBy(array('email' => $form['email']->value));
     if (!$user) {
         $form->addError($form->getTranslator()->translate('User with email %email% does not exist.', null, array('email' => $form['email']->value)));
         return;
     }
     $key = $user->resetPassword();
     $url = Callback::invoke($resetLinkCallback, $key);
     $this->entityManager->persist($user);
     $this->entityManager->flush($user);
     $this->securityManager->sendRecoveryUrl($user, $url);
 }
Пример #18
0
 /**
  * @return \Nette\Application\UI\Form
  */
 public function create()
 {
     $form = $this->formFactory->create();
     $reg = array();
     foreach ($this->registrationRepository->findAll() as $registration) {
         $reg[$registration->id] = $registration->name;
     }
     $form->addGroup('Authentication');
     $form->addSelect('autologin', 'Auto login')->setItems($this->securityManager->getLoginProviders(), false)->setPrompt('Deactivated')->addCondition($form::EQUAL, '')->elseCondition()->toggle('form-autoregistration');
     $form->addGroup()->setOption('id', 'form-autoregistration');
     $form->addSelect('autoregistration', 'Auto registration')->setPrompt('Deactivated')->setItems($reg);
     $form->setCurrentGroup();
     $form->addSubmit('_submit', 'Save');
     return $form;
 }
Пример #19
0
 /**
  * Setup permission by role
  *
  * @param \Venne\Security\Authorizator $permission
  * @param string $role
  * @return \Venne\Security\Authorizator
  */
 private function setPermissionsByRole(Authorizator $permission, $role)
 {
     // add role
     if (!$permission->hasRole($role)) {
         $permission->addRole($role);
     }
     // add resources
     $resources = $this->permissionRepository->createQueryBuilder('a')->select('a.resource')->andWhere('a.role = :role')->setParameter('role', $role)->groupBy('a.resource')->getQuery()->getResult();
     foreach ($resources as $resource) {
         if (!$permission->hasResource($resource)) {
             $permission->addResource($resource);
         }
     }
     // set allow/deny
     $roleEntity = $this->roleRepository->findOneByName($role);
     if ($roleEntity) {
         if ($roleEntity->parent) {
             $this->setPermissionsByRole($permission, $roleEntity->parent->name);
         }
         if ($roleEntity && !$permission->hasRole($role)) {
             $permission->addRole($role, $roleEntity->parent ? $roleEntity->parent->name : null);
         }
         foreach ($roleEntity->permissions as $perm) {
             if ($perm->resource === $permission::ALL || $permission->hasResource($perm->resource)) {
                 if ($perm->allow) {
                     $permission->allow($role, $perm->resource, $perm->privilege ? $perm->privilege : null);
                 } else {
                     $permission->deny($role, $perm->resource, $perm->privilege ? $perm->privilege : null);
                 }
             }
         }
     }
     return $permission;
 }
Пример #20
0
 /**
  * @param string[] $credentials
  * @return \Nette\Security\Identity
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     /** @var User $user */
     $user = $this->userRepository->findOneBy(array('email' => $username, 'published' => 1));
     if (!$user) {
         throw new AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     }
     if (!$user->verifyByPassword($password)) {
         throw new AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     }
     if ($user->needsRehash()) {
         $user->setPassword($password);
         $this->entityManager->flush($user);
     }
     return new Identity($user->getId(), $user->getRoles(), array('email' => $user->getEmail()));
 }
Пример #21
0
 /**
  * Finds an entity by criteria array.
  * @param array $criteria
  * @param array $orderBy
  * @return object
  * @throws IOException
  */
 public function findOneBy(array $criteria, array $orderBy = null)
 {
     $result = parent::findOneBy($criteria, $orderBy);
     if ($result === NULL) {
         throw new IOException('Not found', 404);
     }
     return $result;
 }
Пример #22
0
 public function loadState(array $params)
 {
     parent::loadState($params);
     if (isset($params['key'])) {
         $this->resetUser = $this->userRepository->findOneBy(array('resetKey' => $params['key']));
         if ($this->resetUser === null) {
             $this->onError($this, new ResetKeyNotFoundException());
         }
     }
 }
Пример #23
0
 public function hashSongs()
 {
     /** @var Song[] $songs */
     $songs = $this->songRepository->findAssoc([]);
     /** @var \SplFileInfo $song */
     foreach (Finder::findFiles('*')->from($this->songsDirectory) as $song) {
         $songHash = md5_file($song->getRealPath());
         $songEntity = $songs[$song->getBasename('.mp3')];
         $songEntity->setHash($songHash);
     }
     $this->entityManager->flush();
 }
Пример #24
0
 /**
  * @param int $cityId
  * @return array
  */
 protected function streetWithRegions($cityId, $title = NULL)
 {
     $data = [];
     $partCities = $this->partCityRepository->findBy(['city.code' => $cityId], ['title' => Criteria::ASC, 'id' => Criteria::ASC]);
     foreach ($partCities as $key => $partCity) {
         if (!is_numeric($partCity->title)) {
             $data[$key] = ['title' => $partCity->title, 'code' => $partCity->code, 'minZip' => $partCity->minZip, 'maxZip' => $partCity->maxZip];
         }
         $data[$key] += $this->getStreetsFromPartCity($partCity->id, $title);
     }
     return ['partCities' => $data];
 }
Пример #25
0
 /**
  * @param AMQPMessage $message
  * @return bool
  */
 public function process(AMQPMessage $message)
 {
     $ids = Json::decode((string) $message->body, Json::FORCE_ARRAY);
     /** @var Screenplay[] $documents */
     $documents = [];
     foreach ($ids as $id) {
         /** @var Screenplay|NULL $screenplay */
         $screenplay = $this->scenariosRepository->find($id);
         if ($screenplay === NULL) {
             $this->onError("Screenplay with ID #{$id} not found!");
             return FALSE;
         }
         $documents[] = $this->createDocument($screenplay);
     }
     /** @var Index $indexEntity */
     $indexEntity = $this->indicesRepository->findOneBy([], ['createdAt' => 'DESC']);
     $index = $this->client->getIndex($indexEntity->getName());
     $type = $index->getType('screenplay');
     $type->addDocuments($documents);
     return TRUE;
 }
Пример #26
0
 /**
  * @return \Nette\Forms\Form
  */
 protected function createComponentAccountForm()
 {
     $user = $this->userRepository->find($this->getUser()->getIdentity()->getId());
     $formService = $this->securityManager->getUserTypeByClass($user->getClass())->getFrontFormService();
     $form = $formService->getFormFactory($user->getId())->create();
     $form->onSuccess[] = function () {
         $this->flashMessage($this->translator->translate('Account settings has been updated.'), 'success');
         $this->redirect('this');
         $this->redrawControl('content');
     };
     return $form;
 }
Пример #27
0
 /**
  * @param string $type
  * @param string|null $action
  * @param string|null $message
  * @return \Venne\Notifications\NotificationType
  */
 private function getTypeEntity($type, $action = null, $message = null)
 {
     if (($typeEntity = $this->typeRepository->findOneBy(array('type' => $type, 'action' => $action, 'message' => $message))) === null) {
         $typeEntity = new NotificationType();
         $typeEntity->type = $type;
         $typeEntity->action = $action;
         $typeEntity->message = $message;
         $this->entityManager->persist($typeEntity);
         $this->entityManager->flush($typeEntity);
     }
     return $typeEntity;
 }
Пример #28
0
 public function loadState(array $params)
 {
     if (isset($params['dirId'])) {
         $this->dir = $this->dirRepository->find($params['dirId']);
     } elseif ($this->root) {
         $this->dir = $this->root;
     }
     if (isset($params['fileId'])) {
         $this->file = $this->fileRepository->find($params['fileId']);
         $this->dir = $this->file->getParent();
     }
     parent::loadState($params);
 }
Пример #29
0
 /**
  * @param $tagID
  * @throws \Exception
  */
 public function remove($tagID)
 {
     try {
         $this->em->beginTransaction();
         /** @var Tag $tag */
         $tag = $this->tagRepository->find($tagID);
         if ($tag === null) {
             $this->em->commit();
             return;
         }
         $tagSearchUrl = $this->urlFacade->getUrl('Pages:Front:Search', 'tag', $tag->getId());
         $this->em->remove($tag);
         $this->em->remove($tagSearchUrl);
         $this->em->flush();
         $this->em->commit();
         $this->onSuccessTagRemoval($tag, $tagID);
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
 /**
  * @param array $street
  * @param PartCity $partCity
  */
 protected function parseStreet($street, PartCity $partCity)
 {
     $code = isset($street['kod']) ? (string) $street['kod'] : NULL;
     $title = isset($street['nazev']) ? (string) $street['nazev'] : NULL;
     $street = $this->streetRepository->findOneBy(['code' => $code, 'partCity' => $partCity]);
     if (!$street) {
         $street = new Street();
         $street->code = $code;
     }
     $street->title = $title;
     $street->partCity = $partCity;
     $this->em->persist($street);
     $this->em->flush();
 }