/** * @return Tx_Doctrine2_Query */ public function create($className) { $query = new Tx_Doctrine2_Query($className); $query->injectEntityManager($this->manager->getEntityManager()); if (!$this->objectManager || !$this->configurationManager) { return $query; } $querySettings = $this->objectManager->create('Tx_Extbase_Persistence_QuerySettingsInterface'); $frameworkConfiguration = $this->configurationManager->getConfiguration(Tx_Extbase_Configuration_ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK); $querySettings->setStoragePageIds(t3lib_div::intExplode(',', $frameworkConfiguration['persistence']['storagePid'])); $query->setQuerySettings($querySettings); return $query; }
/** * one (of likely many) loops of processing a given * chunk of events * * @param $events */ protected function indexEvents($events) { foreach ($events as $event) { $this->indexer->update($event); } $this->persistenceManager->persistAll(); }
/** * Replaces an object by another. * * @param object $existingObject The existing object * @param object $newObject The new object * @return void * @api */ public function replace($existingObject, $newObject) { if (!$existingObject instanceof $this->objectType) { throw new Tx_Extbase_Persistence_Exception_IllegalObjectType('The existing object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363434); } if (!$newObject instanceof $this->objectType) { throw new Tx_Extbase_Persistence_Exception_IllegalObjectType('The new object given to replace was not of the type (' . $this->objectType . ') this repository manages.', 1248363439); } $backend = $this->persistenceManager->getBackend(); $session = $this->persistenceManager->getSession(); $uuid = $backend->getIdentifierByObject($existingObject); if ($uuid !== NULL) { $backend->replaceObject($existingObject, $newObject); $session->unregisterReconstitutedObject($existingObject); $session->registerReconstitutedObject($newObject); if ($this->removedObjects->contains($existingObject)) { $this->removedObjects->detach($existingObject); $this->removedObjects->attach($newObject); } } elseif ($this->addedObjects->contains($existingObject)) { $this->addedObjects->detach($existingObject); $this->addedObjects->attach($newObject); } else { throw new Tx_Extbase_Persistence_Exception_UnknownObject('The "existing object" is unknown to the persistence backend.', 1238068475); } }
/** * action update * * @param Tx_Contentstage_Domain_Model_Review $review * @param array $reviewers Array of be_user ids * @return void */ public function updateAction(Tx_Contentstage_Domain_Model_Review $review, array $reviewers = array()) { $this->checkPermission(); try { $this->mapReviewers($reviewers, iterator_to_array($review->getReviewed())); } catch (Exception $e) { $this->log->log($this->translate('error.' . $e->getCode(), array($e->getMessage())) ?: $e->getMessage(), Tx_CabagExtbase_Utility_Logging::ERROR); $this->redirect('compare', 'Content'); } // at the moment, it is not possible to inject a storage object at creation, so we have to cheat a bit $tempData = t3lib_div::_GP('tx_contentstage_web_contentstagestage_temp'); if (!$review->getPushPageChanges() && !empty($tempData['review']['dbrecord']) && count($tempData['review']['dbrecord']) > 0) { $converter = $this->objectManager->get('Tx_Contentstage_Property_TypeConverter_DbrecordConverter'); $review->setDbrecord($converter->convertFrom($tempData['review']['dbrecord'], 'Tx_Extbase_Persistence_ObjectStorage<Tx_Contentstage_Domain_Model_Dbrecord>')); } $this->reviewRepository->update($review); $this->persistenceManager->persistAll(); $this->log->log($this->translate('review.update.success'), Tx_CabagExtbase_Utility_Logging::OK); if ($this->reviewConfiguration['autoReviewIfSelf']) { $found = $review->getActiveReviewed($this->activeBackendUser); if ($found !== null && $found->getState() === Tx_Contentstage_Domain_Model_State::FRESH) { // the action will redirect to compare action and thus prevent the initial mail sent and only sends a "changed" mail $this->reviewedAction($review, $this->translate('review.submit.ok'), true); } } $this->sendReviewMailAndLog('changed', $review); $this->redirect('compare', 'Content'); }
/** * Returns the number of objects in the result * * @return integer The number of matching objects * @api */ public function count() { if (is_array($this->queryResult)) { return count($this->queryResult); } else { return $this->persistenceManager->getObjectCountByQuery($this->query); } }
/** * @test */ public function initializeExecutesQueryWithArrayFetchMode() { $queryResult = $this->getAccessibleMock('Tx_Extbase_Persistence_QueryResult', array('dummy'), array($this->mockQuery)); $queryResult->injectPersistenceManager($this->mockPersistenceManager); $queryResult->injectDataMapper($this->mockDataMapper); $this->mockPersistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->mockQuery)->will($this->returnValue(array('FAKERESULT'))); $queryResult->_call('initialize'); }
/** * @test */ public function executeReturnsRawObjectDataIfRawQueryResultSettingIsTrue() { $this->querySettings->expects($this->once())->method('getReturnRawQueryResult')->will($this->returnValue(TRUE)); $this->persistenceManager->expects($this->once())->method('getObjectDataByQuery')->with($this->query)->will($this->returnValue('rawQueryResult')); $expectedResult = 'rawQueryResult'; $actualResult = $this->query->execute(); $this->assertEquals($expectedResult, $actualResult); }
/** * action push * * @return void */ public function pushAction() { if ($this->review !== null && $this->review->getUid() > 0) { $this->localRepository->setDepth($this->review->getLevels()); $this->remoteRepository->setDepth($this->review->getLevels()); $this->doComparison(); $changed = $this->review->calculateState(null, false, $this->diff->getMaximumSourceTstamp()); if ($changed) { $this->sendReviewMailAndLog('changed', $this->review); $this->log->log($this->translate('info.review.deprecated'), Tx_CabagExtbase_Utility_Logging::WARNING, $this->diff->getMaximumSourceTstamp()); } } if (!$this->isPushable()) { $this->log->log($this->translate('info.review.noPermission'), Tx_CabagExtbase_Utility_Logging::WARNING); $this->redirect('compare'); } else { // check if by any change there would be some posted records $tempData = t3lib_div::_GP('tx_contentstage_web_contentstagestage_temp'); if (!empty($tempData['review']['dbrecord']) && count($tempData['review']['dbrecord']) > 0) { $converter = $this->objectManager->get('Tx_Contentstage_Property_TypeConverter_DbrecordConverter'); $this->review->setDbrecord($converter->convertFrom($tempData['review']['dbrecord'], 'Tx_Extbase_Persistence_ObjectStorage<Tx_Contentstage_Domain_Model_Dbrecord>')); $this->review->setPushPageChanges(false); } } try { $pageTS = $this->getPageTS(); if (empty($pageTS['doNotSnapshotOnPush'])) { $tables = $this->filterTables(array_keys($this->remoteRepository->getTables()), $this->ignoreSnapshotTables, true); $info = $this->snapshotRepository->create($tables, $this->extensionConfiguration['remote.']['db.'], Tx_Contentstage_Domain_Repository_ContentRepository::TYPE_REMOTE); $this->log->log($this->translate('info.push.snapshot', array($info['file'])), Tx_CabagExtbase_Utility_Logging::OK); } else { $this->log->log($this->translate('info.push.noSnapshot'), Tx_CabagExtbase_Utility_Logging::OK); } $this->pushTables($this->page); $this->log->log($this->translate('info.push.done'), Tx_CabagExtbase_Utility_Logging::OK); // TODO: remove the exception that is thrown when the cache could not be cleared or at least catch it $this->remoteRepository->clearCache($this->page, !!$this->extensionConfiguration['clearAllCaches']); $this->log->log($this->translate('info.push.clearCache'), Tx_CabagExtbase_Utility_Logging::OK); if ($this->review !== null && $this->review->getUid() > 0 && $this->review->getLevels() <= $this->localRepository->getDepth()) { $this->review->addChangeString($this->activeBackendUser, Tx_Contentstage_Domain_Model_State::PUSHED); // reset the domain/page tree cache to allow the values to be rebuilt $this->remoteRepository->clearApplicationCaches(); $this->sendReviewMailAndLog('pushed', $this->review); // once everything is done, persist everything if (!is_object($this->persistenceManager)) { $this->persistenceManager = $this->objectManager->get('\\TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager'); } $this->persistenceManager->persistAll(); } } catch (Exception $e) { $this->log->log($this->translate('error.' . $e->getCode(), array($e->getMessage())) ?: $e->getMessage(), Tx_CabagExtbase_Utility_Logging::ERROR); } $this->log->write(); $this->redirect('compare'); }
/** * Replacing a new object which has not yet been persisted by another * new object will just replace them in the repository's list of added * objects. * * @test * @return void */ public function replaceAddsNewObjectToAddedObjects() { $existingObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface'); $newObject = $this->getMock('Tx_Extbase_DomainObject_DomainObjectInterface'); $addedObjects = new SplObjectStorage(); $addedObjects->attach($existingObject); $mockBackend = $this->getMock('Tx_Extbase_Persistence_BackendInterface'); $this->mockPersistenceManager->expects($this->once())->method('getBackend')->will($this->returnValue($mockBackend)); $mockBackend->expects($this->once())->method('getIdentifierByObject')->with($existingObject)->will($this->returnValue(NULL)); $mockBackend->expects($this->never())->method('replaceObject'); $mockSession = $this->getMock('Tx_Extbase_Persistence_Session'); $this->mockPersistenceManager->expects($this->once())->method('getSession')->will($this->returnValue($mockSession)); $this->repository->_set('objectType', get_class($newObject)); $this->repository->_set('addedObjects', $addedObjects); $this->repository->replace($existingObject, $newObject); $this->assertFalse($addedObjects->contains($existingObject)); $this->assertTrue($addedObjects->contains($newObject)); }
/** * destructor * * this will persist all changes */ public function __destruct() { $this->persistenceManager->persistAll(); }
public function injectPersistenceManager(Tx_Extbase_Persistence_ManagerInterface $manager) { $this->entityManager = $manager->getEntityManager(); }
/** * Executes the number of matching objects for the query * * @return integer The number of matching objects * @deprecated since Extbase 1.3.0; was removed in FLOW3; will be removed in Extbase 1.4.0; use Query::execute()::count() instead * @api */ public function count() { t3lib_div::logDeprecatedFunction(); return $this->persistenceManager->getObjectCountByQuery($this); }