/**
  * @param NodeInterface $event
  * @param NodeInterface $person
  */
 public function removeAttendeeFromEvent(NodeInterface $event, NodeInterface $person)
 {
     $personAndEventData = $this->getEventsAndPersonData($event, $person);
     $this->removeEventFromUser($person, $personAndEventData, 'attendeeIdentifiers', 'attendees', 'User is not set in attendees');
     $this->removeEventFromUser($event, $personAndEventData, 'personEventsIdentifiers', 'personEvents', 'Event is not registered for user');
     $this->nodeWriteRepository->updateNode($person, ['events' => $personAndEventData['personEvents']]);
     $this->nodeWriteRepository->updateNode($event, ['attendees' => $personAndEventData['attendees']]);
     $this->persistenceManager->persistAll();
     $this->emitAttendeeRemoved($event, $person);
 }
 /**
  * @param Asset $asset
  * @param MetaDataCollection $metaDataCollection
  */
 public function mapMetaData(Asset $asset, MetaDataCollection $metaDataCollection)
 {
     $contextVariables = array_merge($this->defaultContextVariables, $metaDataCollection->toArray());
     if (isset($this->metaDataMappingConfiguration['title'])) {
         $asset->setTitle(substr((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['title'], $this->eelEvaluator, $contextVariables), 0, 255));
     }
     if (isset($this->metaDataMappingConfiguration['caption'])) {
         $asset->setCaption((string) EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['caption'], $this->eelEvaluator, $contextVariables));
     }
     if (isset($this->metaDataMappingConfiguration['tags'])) {
         $tagLabels = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['tags'], $this->eelEvaluator, $contextVariables);
         $tagLabels = array_unique($tagLabels);
         $tags = new ArrayCollection();
         foreach ($tagLabels as $tagLabel) {
             if (trim($tagLabel) !== '') {
                 $tags->add($this->getOrCreateTag(trim($tagLabel)));
             }
         }
         $asset->setTags($tags);
     }
     if (isset($this->metaDataMappingConfiguration['collections'])) {
         $collectionTitles = EelUtility::evaluateEelExpression($this->metaDataMappingConfiguration['collections'], $this->eelEvaluator, $contextVariables);
         $collectionTitles = array_unique($collectionTitles);
         $collections = new ArrayCollection();
         foreach ($collectionTitles as $collectionTitle) {
             if (trim($collectionTitle) !== '') {
                 $collections->add($this->getOrCreateCollection(trim($collectionTitle)));
             }
         }
         $asset->setAssetCollections($collections);
     }
     if (!$this->persistenceManager->isNewObject($asset)) {
         $this->assetRepository->update($asset);
     }
 }
 /**
  * Increase read counter of the node by one
  *
  * @param NodeInterface $node Node to increase the read counter for
  *
  * @throws BadRequestException
  * @return mixed[]
  */
 public function trackAction(NodeInterface $node)
 {
     // we can only count pages that include the mixin
     if ($node->getNodeType()->isOfType('Futjikato.ReadCounter:CounterMixin')) {
         $node->setProperty('readcounter', $node->getProperty('readcounter') + 1);
         /**
          * Action changes data but is accessible via GET. this issues a error if we do not manually
          * persists the object in the persistence manager
          */
         $this->persistenceManager->persistAll();
         // by default the flow JSON view uses the 'value' variable
         $this->view->assign('value', array('readcounter' => $node->getProperty('readcounter')));
     } else {
         throw new BadRequestException('Node does not contain Futjikato.ReadCounter:CounterMixin.');
     }
 }
 /**
  * @test
  * @expectedException \TYPO3\Flow\Error\Exception
  */
 public function persistAllReconnectsConnectionOnFailure()
 {
     $this->mockEntityManager->expects($this->exactly(2))->method('flush')->will($this->throwException(new \TYPO3\Flow\Error\Exception('Dummy connection error')));
     $this->mockConnection->expects($this->at(0))->method('close');
     $this->mockConnection->expects($this->at(1))->method('connect');
     $this->persistenceManager->persistAll();
 }
 /**
  * Create User on the Command Line
  *
  * @param string $username The email address, which also serves as the username.
  * @param string $password This user's password.
  * @param string $additionalAttributes Additional attributes to pass to the registrationFlow as semicolon-separated list. Example: ./flow sandstormuser:create ... --additionalAttributes="customerType:CUSTOMER;color:blue"
  */
 public function createCommand($username, $password, $additionalAttributes = '')
 {
     // Parse additionalAttributes if they exist
     $attributes = [];
     if (strlen($additionalAttributes) > 0) {
         $attributesSplitBySeparator = explode(';', $additionalAttributes);
         array_map(function ($singleAttribute) use(&$attributes) {
             $splitAttribute = explode(':', $singleAttribute);
             $attributes[$splitAttribute[0]] = $splitAttribute[1];
         }, $attributesSplitBySeparator);
     }
     $passwordDto = new PasswordDto();
     $passwordDto->setPassword($password);
     $passwordDto->setPasswordConfirmation($password);
     $registrationFlow = new RegistrationFlow();
     $registrationFlow->setPasswordDto($passwordDto);
     $registrationFlow->setEmail($username);
     $registrationFlow->setAttributes($attributes);
     // Remove existing registration flows
     $alreadyExistingFlows = $this->registrationFlowRepository->findByEmail($registrationFlow->getEmail());
     if (count($alreadyExistingFlows) > 0) {
         foreach ($alreadyExistingFlows as $alreadyExistingFlow) {
             $this->registrationFlowRepository->remove($alreadyExistingFlow);
         }
     }
     $registrationFlow->storeEncryptedPassword();
     // Store the RF and persist so the activate command will find it
     $this->registrationFlowRepository->add($registrationFlow);
     $this->persistenceManager->persistAll();
     // Directly activate the account
     $this->activateRegistrationCommand($username);
     $this->outputLine('Added the User <b>"%s"</b> with password <b>"%s"</b>.', [$username, $password]);
 }
 /**
  * @param Account $account
  * @param NodeInterface $userStorageNode
  * @param PersonDto $person
  * @return NodeInterface|string
  */
 protected function createProfileNode(Account $account, NodeInterface $userStorageNode, PersonDto $person)
 {
     try {
         $profileNode = $this->findProfileNode($person->getEmailAddress());
         if ($profileNode === NULL) {
             $properties = ['title' => $person->getFirstName() . ' ' . $person->getLastName(), 'firstName' => $person->getFirstName(), 'lastName' => $person->getLastName(), 'address' => $person->getAddress(), 'zipCode' => $person->getZipCode(), 'city' => $person->getCity(), 'emailAddress' => $person->getEmailAddress(), 'phone' => $person->getPhone(), 'dateOfBirth' => $person->getDateOfBirth(), 'jiuJitsu' => $person->getJiuJitsu(), 'buJitsuDo' => $person->getBuJitsuDo(), 'jiuJitsuDegree' => $person->getJiuJitsuDegree(), 'buJitsuDoDegree' => $person->getBuJitsuDoDegree(), 'gender' => $person->getGender()];
             if ($person->getFirstName() && $person->getLastName()) {
                 $nodeName = $person->getFirstName() . ' ' . $person->getLastName();
             }
             $idealNodeName = Utility::renderValidNodeName(isset($nodeName) ? $nodeName : uniqid('node'));
             $idealNodeName = htmlspecialchars($idealNodeName, ENT_NOQUOTES, 'UTF-8');
             $profileNode = $this->nodeWriteRepository->createChildNode($userStorageNode, $idealNodeName, 'BuJitsuDo.Authentication:Person', $properties);
             if ($person->getImage() instanceof Image) {
                 $profileNode = $this->profileService->setImageToNode($profileNode, $person->getImage(), $person->getFirstName(), 'Profile images');
             }
         }
         $account->getParty()->getPreferences()->set('profileNodeIdentifier', $profileNode->getIdentifier());
         $this->partyRepository->update($account->getParty());
         $this->persistenceManager->persistAll();
         $this->emitPersonCreated($profileNode);
         return $profileNode;
     } catch (\Exception $exception) {
         $this->systemLogger->log('Profile node could not be created because: ' . $exception->getMessage(), LOG_CRIT);
         return $exception->getMessage();
     }
 }
 /**
  * Processes the cached meta data and aggregates it to a usable format so they can be used easily
  * for showing some results.
  *
  * @param boolean whether the script should avoid any output
  * @return void
  */
 public function processCommitsCommand($quiet = FALSE)
 {
     $this->quiet = $quiet;
     $unprocessedCommits = $this->commitRepository->findByIsAggregated(FALSE);
     if ($unprocessedCommits->count() == 0) {
         $this->outputLine('There are no commits to be processed.');
         return;
     }
     $numberOfProcessedCommits = 0;
     foreach ($unprocessedCommits as $commit) {
         $this->processSingleCommit($commit);
         $commit->setIsAggregated(TRUE);
         $this->commitRepository->update($commit);
         $this->persistenceManager->persistAll();
         $numberOfProcessedCommits++;
     }
     $this->outputLine('-> aggregated ' . $numberOfProcessedCommits . ' commits.');
 }
 /**
  * @param string $identifier 
  * @return void
  */
 public function showCommand($identifier)
 {
     $deployment = $this->persistenceManager->getObjectByIdentifier($identifier, 'Lightwerk\\SurfCaptain\\Domain\\Model\\Deployment');
     if ($deployment instanceof Deployment) {
         $configuration = $deployment->getConfiguration();
         $this->outputLine(print_r($configuration, TRUE));
     } else {
         $this->outputLine('no deployment found');
     }
 }
 /**
  * RepoDetector for Gitweb
  *
  * Use this command to read a list of repos from a Gitweb "website" and add those repositories
  * to the database for further processing afterwards.
  *
  * Call this with the URL to your Gitweb-Frontend, e.g. http://git.company.tld/ and the base-URL
  * for the access to the Git repositories, could be e.g. "ssh://git@git.company.tld/" (if you're
  * using Gitolite or the like).
  *
  * By default, any newly found repository will *not* directly be marked as active.
  *
  * If you're running CoMo on the same server that hosts your Git repositories, you can prefix
  * the repo's local path with "file://" and CoMo will not try to create a local clone before
  * going to extract the commits of that repository.
  *
  * @param string $url The URL to Gitweb
  * @param string $baseUrl The base URL that is put in front of the single repo's path
  * @param boolean whether the found repos should be marked active, defaults to false
  * @param boolean whether the script should avoid any output
  * @return void
  */
 public function fetchReposCommand($url, $baseUrl, $markAsActive = FALSE, $quiet = FALSE)
 {
     $this->quiet = $quiet;
     $url = $url . '?a=project_index';
     if (!@fopen($url, r)) {
         throw new \TYPO3\Flow\Exception(sprintf('Whoops - somehow I failed to open the list. Try if you can open that URL "%s"', $url));
     }
     $this->baseUrl = $baseUrl;
     $this->outputLine('OK, list fetched from "%s"', array($url));
     $this->outputLine('Base-URL set to: %s', array($this->baseUrl));
     // split the list
     $list = fopen($url, 'r');
     // Read list of repositories from the Gitweb output
     $repoList = file_get_contents($url);
     $repositoryLines = explode("\n", $repoList);
     if (empty($repositoryLines)) {
         $this->outputLine('No repos found, exiting.');
         return;
     }
     // eliminate empty lines first
     foreach ($repositoryLines as $line) {
         if ($line != '') {
             $repoLines[] = $line;
         }
     }
     $this->outputLine('Found %s repositories.', array(count($repoLines)));
     // process each single repository
     $addedCount = 0;
     $skippedCount = 0;
     foreach ($repoLines as $repoLine) {
         $title = $this->getRepoTitleFromRepoLine($repoLine);
         $repoUrl = $this->buildRepoUrl($repoLine);
         if ($this->repositoryRepository->countByUrl($repoUrl) == 0) {
             $repo = new \Mrimann\CoMo\Domain\Model\Repository();
             $repo->setUrl($repoUrl);
             $repo->setTitle($title);
             // only mark the repo as active if this was requested
             if ($markAsActive == TRUE) {
                 $repo->setIsActive(TRUE);
             }
             // Add repository to the database
             $this->repositoryRepository->add($repo);
             $addedCount++;
             $this->outputLine('-> added repository "%s"', array($repoUrl));
         } else {
             $skippedCount++;
             $this->outputLine('-| skipped repository "%s" - exists already', array($repoUrl));
         }
     }
     $this->persistenceManager->persistAll();
     // show some summary output
     $this->outputLine('Added %d new repositories, skipped %d repositories.', array($addedCount, $skippedCount));
     $this->outputLine('Now having a total of %d repositories in the system of which %d are marked active to be checked.', array($this->repositoryRepository->countAll(), $this->repositoryRepository->countByIsActive(TRUE)));
 }
 /**
  * @param DoctrineSqlFilter $sqlFilter
  * @param QuoteStrategy $quoteStrategy
  * @param ClassMetadata $targetEntity
  * @param string $targetTableAlias
  * @param string $targetEntityPropertyName
  * @return string
  * @throws InvalidQueryRewritingConstraintException
  * @throws \Exception
  */
 protected function getSqlForManyToOneAndOneToOneRelationsWithPropertyPath(DoctrineSqlFilter $sqlFilter, QuoteStrategy $quoteStrategy, ClassMetadata $targetEntity, $targetTableAlias, $targetEntityPropertyName)
 {
     $subselectQuery = $this->getSubselectQuery($targetEntity, $targetEntityPropertyName);
     $associationMapping = $targetEntity->getAssociationMapping($targetEntityPropertyName);
     $subselectConstraintQueries = array();
     foreach ($associationMapping['joinColumns'] as $joinColumn) {
         $rootAliases = $subselectQuery->getQueryBuilder()->getRootAliases();
         $subselectQuery->getQueryBuilder()->select($rootAliases[0] . '.' . $targetEntity->getFieldForColumn($joinColumn['referencedColumnName']));
         $subselectSql = $subselectQuery->getSql();
         foreach ($subselectQuery->getParameters() as $parameter) {
             $parameterValue = $parameter->getValue();
             if (is_object($parameterValue)) {
                 $parameterValue = $this->persistenceManager->getIdentifierByObject($parameter->getValue());
             }
             $subselectSql = preg_replace('/\\?/', $this->entityManager->getConnection()->quote($parameterValue, $parameter->getType()), $subselectSql, 1);
         }
         $quotedColumnName = $quoteStrategy->getJoinColumnName($joinColumn, $targetEntity, $this->entityManager->getConnection()->getDatabasePlatform());
         $subselectIdentifier = 'subselect' . md5($subselectSql);
         $subselectConstraintQueries[] = $targetTableAlias . '.' . $quotedColumnName . ' IN (SELECT ' . $subselectIdentifier . '.' . $joinColumn['referencedColumnName'] . '0 FROM (' . $subselectSql . ') AS ' . $subselectIdentifier . ' ) ';
     }
     return ' (' . implode(' ) AND ( ', $subselectConstraintQueries) . ') ';
 }