/** * @param NodeInterface $node * @param Image $newImage * @param string $title * @param string|array $tagLabel * @param string $propertyName * @param boolean $removePreviousProfileImage * @return NodeInterface */ public function setImageToNode(NodeInterface $node, Image $newImage, $title, $tagLabel = NULL, $propertyName = 'image', $removePreviousProfileImage = FALSE) { $newImage->setTitle($title); if ($tagLabel !== NULL) { if (is_array($tagLabel) && !is_string($tagLabel)) { if ($removePreviousProfileImage === TRUE) { $this->removePreviousProfilePictureBasedOnTags($title, $tagLabel); } foreach ($tagLabel as $key => $label) { $tag = $this->tagRepository->findOneByLabel($label); if (!$tag instanceof Tag) { $tag = new Tag($label); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } elseif (is_string($tagLabel) && !is_array($tagLabel)) { $tag = $this->tagRepository->findOneByLabel($tagLabel); if (!$tag instanceof Tag) { $tag = new Tag($tagLabel); $this->tagRepository->add($tag); } $newImage->addTag($tag); } } /** @var Image $image */ $image = $this->imageRepository->findByIdentifier($newImage->getIdentifier()); if ($image !== NULL) { try { $this->imageRepository->update($image); $node->setProperty($propertyName, $image); } catch (\Exception $exception) { // Image repository might give back an image while not stored for some reason. If so, catch that error and store it anyway $image->setTitle($title); $this->imageRepository->add($image); $node->setProperty($propertyName, $image); $this->systemLogger->log('Image with identifier ' . $image->getIdentifier() . ' stored while preceding an error that is not stored yet fetched using ImageRepository', LOG_CRIT); } } else { $this->imageRepository->add($newImage); $node->setProperty($propertyName, $newImage); } return $node; }
/** * Creates a user based on the given information * * The created user and account are automatically added to their respective repositories and thus be persisted. * * @param string $username The username of the user to be created. * @param string $password Password of the user to be created * @param string $firstName First name of the user to be created * @param string $lastName Last name of the user to be created * @param string $department department of the user to be created * @param string $photo photo of the user to be created * @param array $roleIdentifiers A list of role identifiers to assign * @param string $authenticationProviderName Name of the authentication provider to use. Example: "Typo3BackendProvider" * @return User The created user instance * @api */ public function createUserPhlu($username, $password, $firstName, $lastName, $department, $photo, array $roleIdentifiers = null, $authenticationProviderName = null) { $collection = $this->assetCollectionRepository->findByCollectionName('phluCollection2')->getFirst(); if (!$collection) { $collection = new \TYPO3\Media\Domain\Model\AssetCollection('phluCollection2'); $this->assetCollectionRepository->add($collection); $this->persistenceManager->persistAll(); } $user = new User(); $user->setDepartment($department); $name = new PersonName('', $firstName, '', $lastName, '', $username); $user->setName($name); $resource = $this->resourceManager->importResource($photo); $image = new Image($resource); $image->setTitle($name->getFullName()); $tag = $this->tagRepository->findBySearchTerm('Hauswart')->getFirst(); if (!$tag) { $tag = new Tag(); $tag->setLabel('Hauswart'); $this->tagRepository->add($tag); $collection->addTag($tag); } $image->addTag($tag); $user->setPhoto($image); $this->assetRepository->add($image); $collection->addAsset($image); $this->assetCollectionRepository->update($collection); return $this->addUserPhlu($username, $password, $user, $roleIdentifiers, $authenticationProviderName); }