本文整理汇总了PHP中Registry::persist方法的典型用法代码示例。如果您正苦于以下问题:PHP Registry::persist方法的具体用法?PHP Registry::persist怎么用?PHP Registry::persist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Registry
的用法示例。
在下文中一共展示了Registry::persist方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCode
/**
* @param SymfonyStyle|null $io
*/
public function updateCode(SymfonyStyle $io = null)
{
$io->title('CampaignChain Data Update');
if (empty($this->versions)) {
$io->warning('No code updater Service found, maybe you didn\'t enable a bundle?');
return;
}
$io->comment('The following data versions will be updated');
$migratedVersions = array_map(function (DataUpdateVersion $version) {
return $version->getVersion();
}, $this->em->getRepository('CampaignChainUpdateBundle:DataUpdateVersion')->findAll());
$updated = false;
foreach ($this->versions as $version => $class) {
if (in_array($version, $migratedVersions)) {
continue;
}
$io->section('Version ' . $class->getVersion());
$io->listing($class->getDescription());
$io->text('Begin data update');
$result = $class->execute($io);
if ($result) {
$dbVersion = new DataUpdateVersion();
$dbVersion->setVersion($version);
$this->em->persist($dbVersion);
$this->em->flush();
$io->text('Data update finished');
}
$updated = true;
}
if (!$updated) {
$io->success('All data is up to date.');
} else {
$io->success('Every data version has been updated.');
}
}
示例2: execute
public function execute(SymfonyStyle $io = null)
{
$currentProfiles = $this->em->getRepository('CampaignChainLocationGoogleAnalyticsBundle:Profile')->findAll();
if (empty($currentProfiles)) {
$io->text('There is no Profile entity to update');
return true;
}
foreach ($currentProfiles as $profile) {
if (substr($profile->getProfileId(), 0, 2) != 'UA') {
continue;
}
$profile->setPropertyId($profile->getProfileId());
$gaProfileUrl = $profile->getLocation()->getUrl();
$google_base_url = 'https:\\/\\/www.google.com\\/analytics\\/web\\/#report\\/visitors-overview\\/a' . $profile->getAccountId() . 'w\\d+p';
$pattern = '/' . $google_base_url . '(.*)/';
preg_match($pattern, $gaProfileUrl, $matches);
if (!empty($matches) && count($matches) == 2) {
$profile->setProfileId($matches[1]);
$profile->setIdentifier($profile->getProfileId());
}
$this->em->persist($profile);
}
$this->em->flush();
return true;
}
示例3: setToken
/**
* @param Token $newToken
* @param bool $sameToken
* @return bool|string
*/
public function setToken(Token $newToken, $sameToken = false)
{
if ($newToken->getLocation()) {
$this->em->persist($newToken);
$this->em->flush();
return true;
}
// Check whether the token already exists in relation to a channel.
$repository = $this->em->getRepository('CampaignChainSecurityAuthenticationClientOAuthBundle:Token');
$query = $repository->createQueryBuilder('token')->where('token.application = :application')->andWhere('token.accessToken = :accessToken')->andWhere('token.location IS NOT NULL')->setParameter('application', $newToken->getApplication())->setParameter('accessToken', $newToken->getAccessToken())->setMaxResults(1)->getQuery();
$oldToken = $query->getOneOrNullResult();
if (!$oldToken) {
// So, there's no token related to a specific channel, but perhaps there is one
// that has been persisted at a previous attempt to connect to the channel?
// TODO: Implement what to do if token was persisted previously without channel relationship?
$this->token = $newToken;
$this->em->persist($this->token);
$this->em->flush();
return self::STATUS_NEW_TOKEN;
}
// Has a scope been set?
if (!$newToken->getScope() && !$sameToken) {
return self::STATUS_NO_CHANGE;
}
//With LinkedIn if a user connects multiple times, he will get the same access token
//And even though they are same, it has to be saved as a new token
if ($sameToken) {
$this->token = $newToken;
$this->em->persist($this->token);
$this->em->flush();
return self::STATUS_NEW_TOKEN;
}
$newScope = $newToken->getScope();
$newAccessToken = $newToken->getAccessToken();
$existingScope = $oldToken->getScope();
$existingAccessToken = $oldToken->getAccessToken();
// If the channel has the same access token and the same scope,
// or no scope has been defined, then we're done.
if ($existingScope === $newScope) {
return self::STATUS_SAME_SCOPE;
}
// Is the scope different for the same profile?
if ($existingAccessToken !== $newAccessToken) {
// If the channel has a different scope and access token,
// then create a new token entry for the existing profile.
// This takes care of how Google handles scopes for its APIs.
$this->token = $newToken;
$status = self::STATUS_NEW_TOKEN;
} else {
// If the channel has the same access token, but a different scope,
// then just update the scope for the token.
// This takes care of how Facebook deals with scope changes.
$this->token = $oldToken;
$this->token->setScope($newScope);
$status = self::STATUS_NEW_SCOPE;
}
$this->em->persist($this->token);
$this->em->flush();
return $status;
}
示例4: updateBitlyAccessToken
public function updateBitlyAccessToken($access_token)
{
$activeSystem = $this->getActiveSystem();
$activeSystem->setBitlyAccessToken($access_token);
$this->em->persist($activeSystem);
$this->em->flush();
}
示例5: cloneOperation
/**
* @param Operation $oldOperation
* @param Operation $newOperation
*/
public function cloneOperation(Operation $oldOperation, Operation $newOperation)
{
$newsItem = $this->getNewsItemByOperation($oldOperation);
$clonedNewsItem = clone $newsItem;
$clonedNewsItem->setOperation($newOperation);
$this->em->persist($clonedNewsItem);
$this->em->flush();
}
示例6: readAction
/**
* @param Operation $operation
* @return \Symfony\Component\HttpFoundation\Response
* @throws \Exception
*/
public function readAction(Operation $operation)
{
$newsItem = $this->contentService->getNewsItemByOperation($operation);
$activity = $operation->getActivity();
$locationModuleIdentifier = $activity->getLocation()->getLocationModule()->getIdentifier();
$isCompanyPageShare = 'campaignchain-linkedin-page' == $locationModuleIdentifier;
$isLive = true;
if (!$newsItem->getLinkedinData()) {
$connection = $this->restClient->getConnectionByActivity($activity);
/*
* Below calls to the Linkedin REST API will throw errors if the
* Linkedin App has not been approved by Linkedin as part of their
* partner program.
*/
try {
if ($isCompanyPageShare) {
$response = $connection->getCompanyUpdate($activity, $newsItem);
} else {
$response = $connection->getUserUpdate($activity, $newsItem);
}
if (!is_null($response)) {
$newsItem->setLinkedinData($response);
$this->em->persist($newsItem);
$this->em->flush();
} else {
$isLive = false;
}
} catch (\Exception $e) {
$isLive = true;
}
}
return $this->templating->renderResponse('CampaignChainOperationLinkedInBundle::read.html.twig', array('page_title' => $activity->getName(), 'news_item' => $newsItem, 'activity' => $activity, 'is_live' => $isLive, 'is_company' => $isCompanyPageShare));
}
示例7: prepareReportLocationJobs
protected function prepareReportLocationJobs()
{
/** @var SchedulerReportLocation[] $scheduledReports */
$scheduledReports = $this->em->getRepository('CampaignChainCoreBundle:SchedulerReportLocation')->getScheduledReportJobsForSchedulerCommand($this->scheduler->getPeriodStart(), $this->scheduler->getPeriodEnd());
if (empty($scheduledReports)) {
$this->io->text('No scheduled Location reports.');
$this->logger->info('No scheduled Location reports.');
return;
}
// Queue the scheduled reports.
$this->io->text('Processing scheduled Location reports.');
$this->logger->info('Processing scheduled Location reports.');
foreach ($scheduledReports as $scheduledReport) {
$txt = 'Report ID: ' . $scheduledReport->getId();
$this->io->section($txt);
$this->logger->info($txt);
$this->queueReportJob($scheduledReport);
/*
* Update next run.
*/
// Are we within the regular scheduled period?
if ($scheduledReport->getEndDate() > $this->now && $scheduledReport->getInterval() != null) {
$interval = \DateInterval::createFromDateString($scheduledReport->getInterval());
$nextRun = clone $scheduledReport->getNextRun();
$scheduledReport->setNextRun($nextRun->add($interval));
$txt = 'Regular period. Next run is in ' . $scheduledReport->getInterval();
$this->io->text($txt);
$this->logger->info($txt);
}
$this->em->persist($scheduledReport);
}
//update the next run dates for the scheduler
$this->em->flush();
}
示例8: schedule
public function schedule($operation, $facts = null)
{
$scheduler = new SchedulerReportOperation();
$scheduler->setOperation($operation);
$scheduler->setInterval('1 hour');
$scheduler->setEndAction($operation->getActivity()->getCampaign());
$this->em->persist($scheduler);
// Add initial data to report.
$this->newsitem = $this->em->getRepository('CampaignChainOperationLinkedInBundle:NewsItem')->findOneByOperation($operation);
if (!$this->newsitem) {
throw new \Exception('No Linkedin news item found for an operation with ID: ' . $operation->getId());
}
$facts[self::METRIC_LIKES] = 0;
$facts[self::METRIC_COMMENTS] = 0;
$this->factService->addFacts('activity', self::BUNDLE_NAME, $operation, $facts);
}
示例9: onConsoleException
/**
* In case of an exception in scheduler console command
* the message should be saved into the scheduler entity
*
* @param ConsoleExceptionEvent $event
*/
public function onConsoleException(ConsoleExceptionEvent $event)
{
/** @var SchedulerCommand $command */
$command = $event->getCommand();
if ($command->getName() != 'campaignchain:scheduler') {
return;
}
// if scheduler is null exception happened in early stage
// maybe email should be sent
if (!$command->getScheduler()) {
return;
}
/** @var Scheduler $scheduler */
$scheduler = $command->getScheduler();
$scheduler->setMessage($event->getException()->getMessage());
$scheduler->setStatus(Scheduler::STATUS_ERROR);
$scheduler->setExecutionEnd(new \DateTime());
$this->em->persist($scheduler);
$this->em->flush();
$command->getIo()->error($scheduler->getMessage());
$this->logger->critical($scheduler->getMessage());
}
示例10: load
/**
* @param array $files
* @param bool $doDrop
*/
public function load(array $files, $doDrop = true)
{
try {
$this->em->getConnection()->beginTransaction();
$userProcessor = new UserProcessor(realpath(SystemUtil::getRootDir() . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR), $this->userService, $this->mimeTypeGuesser, $this->extensionGuesser);
// Create Alice manager and fixture set
$this->fixtureManager->addProcessor($userProcessor);
$set = $this->fixtureManager->createFixtureSet();
// Add the fixture files
foreach ($files as $file) {
$set->addFile($file, 'yaml');
}
$set->setDoDrop($doDrop);
$set->setDoPersist(true);
$set->setSeed(1337 + 42);
// TODO Keep Module data intact
$bundles = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Bundle")->findAll();
$modules = $this->em->getRepository("CampaignChain\\CoreBundle\\Entity\\Module")->findAll();
if ($this->fixtureManager->load($set)) {
// TODO: Restore modules data
foreach ($bundles as $bundle) {
$this->em->persist($bundle);
}
foreach ($modules as $module) {
$this->em->persist($module);
}
$this->em->flush();
$this->em->getConnection()->commit();
return true;
}
return false;
} catch (\Exception $e) {
$this->em->getConnection()->rollback();
$this->setException($e);
return false;
}
}
示例11: registerModuleSystemParams
/**
* Store a module's system parameters.
*/
private function registerModuleSystemParams()
{
if (!count($this->systemParams)) {
return;
}
/*
* If a system entry already exists, then update it. Otherwise,
* create a new one.
*/
$system = $this->systemService->getActiveSystem();
if (!$system) {
$system = new System();
$system->setNavigation([]);
$this->em->persist($system);
}
if (!is_array($system->getNavigation())) {
$system->setNavigation([]);
}
foreach ($this->systemParams as $moduleParams) {
foreach ($moduleParams as $key => $params) {
switch ($key) {
case 'navigation':
// Does the app override the modules' navigation?
if (isset($this->appComposerJson['extra']) && isset($this->appComposerJson['extra']['campaignchain']) && isset($this->appComposerJson['extra']['campaignchain']['navigation'])) {
$system->setNavigation($this->appComposerJson['extra']['campaignchain']['navigation']);
} else {
// Merge existing navigations with new modules' navigation.
$navigation = array_merge_recursive($system->getNavigation(), $params);
$system->setNavigation($navigation);
}
break;
}
}
}
$this->em->flush();
}
示例12: persist
/**
* Global implementation of Interfaces\Persistent
*/
protected function persist()
{
Registry::persist($this);
}