本文整理汇总了PHP中Akeneo\Component\StorageUtils\Saver\SaverInterface类的典型用法代码示例。如果您正苦于以下问题:PHP SaverInterface类的具体用法?PHP SaverInterface怎么用?PHP SaverInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SaverInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* {@inheritdoc}
*/
public function store(\SplFileInfo $localFile, $destFsAlias, $deleteRawFile = false)
{
$filesystem = $this->mountManager->getFilesystem($destFsAlias);
$file = $this->factory->createFromRawFile($localFile, $destFsAlias);
$error = sprintf('Unable to move the file "%s" to the "%s" filesystem.', $localFile->getPathname(), $destFsAlias);
if (false === ($resource = fopen($localFile->getPathname(), 'r'))) {
throw new FileTransferException($error);
}
try {
$options = [];
$mimeType = $file->getMimeType();
if (null !== $mimeType) {
$options['ContentType'] = $mimeType;
}
$isFileWritten = $filesystem->writeStream($file->getKey(), $resource, $options);
} catch (FileExistsException $e) {
throw new FileTransferException($error, $e->getCode(), $e);
}
if (false === $isFileWritten) {
throw new FileTransferException($error);
}
$this->saver->save($file);
if (true === $deleteRawFile) {
$this->deleteRawFile($localFile);
}
return $file;
}
示例2: move
/**
* {@inheritdoc}
*/
public function move(FileInterface $file, $srcFsAlias, $destFsAlias)
{
$isFileMoved = $this->mountManager->move(sprintf('%s://%s', $srcFsAlias, $file->getKey()), sprintf('%s://%s', $destFsAlias, $file->getKey()));
if (!$isFileMoved) {
throw new FileTransferException(sprintf('Impossible to move the file "%s" from "%s" to "%s".', $file->getKey(), $srcFsAlias, $destFsAlias));
}
$file->setStorage($destFsAlias);
$this->saver->save($file);
}
示例3: postAction
/**
* Saves a history item, by creating a new one if the page is visited for
* the first time, or by updating an existing one if the user has already
* visited the page.
*
* @param Request $request
*
* @return JsonResponse
*/
public function postAction(Request $request)
{
$history = json_decode($request->getContent(), true);
$historyItem = $this->findOrCreate($this->getUser(), $history['url']);
$historyItem->setTitle(json_encode($history['title']));
$historyItem->doUpdate();
$this->saver->save($historyItem);
return new JsonResponse();
}
示例4: write
/**
* {@inheritdoc}
*/
public function write(array $items)
{
$this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
foreach ($items as $item) {
$this->incrementCount($item);
}
$this->mediaManager->handleAllProductsMedias($items);
$this->productSaver->saveAll($items, ['recalculate' => false]);
$this->cacheClearer->clear();
}
示例5: onSuccess
/**
* Call when form is valid
*
* @param GroupInterface $group
*/
protected function onSuccess(GroupInterface $group)
{
$appendProducts = $this->form->get('appendProducts')->getData();
$removeProducts = $this->form->get('removeProducts')->getData();
$options = ['add_products' => $appendProducts, 'remove_products' => $removeProducts];
if ($group->getType()->isVariant()) {
$options['copy_values_to_products'] = true;
}
$this->groupSaver->save($group, $options);
}
示例6: removeAttributeAction
/**
* Remove an attribute form a variant group
*
* @param string $code The variant group code
* @param int $attributeId The attribute id
*
* @AclAncestor("pim_enrich_group_remove_attribute")
*
* @throws NotFoundHttpException If variant group or attribute is not found or the user cannot see it
*
* @return JsonResponse
*/
public function removeAttributeAction($code, $attributeId)
{
$group = $this->findVariantGroupOr404($code);
$attribute = $this->findAttributeOr404($attributeId);
$template = $group->getProductTemplate();
if (null !== $template) {
$this->templateBuilder->removeAttribute($template, $attribute);
$this->groupSaver->save($group);
}
return new JsonResponse();
}
示例7: toggleAction
/**
* Activate/Deactivate a currency
*
* @param Currency $currency
*
* @AclAncestor("pim_enrich_currency_toggle")
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function toggleAction(Currency $currency)
{
try {
$currency->toggleActivation();
$this->currencySaver->save($currency);
$this->addFlash('success', 'flash.currency.updated');
} catch (\Exception $e) {
$this->addFlash('error', 'flash.error ocurred');
}
return $this->redirect($this->generateUrl('pim_enrich_currency_index'));
}
示例8: addAttributes
/**
* Add attributes to a group
*
* @param AttributeGroupInterface $group
* @param AttributeInterface[] $attributes
*/
public function addAttributes(AttributeGroupInterface $group, $attributes)
{
$maxOrder = $group->getMaxAttributeSortOrder();
foreach ($attributes as $attribute) {
$maxOrder++;
$attribute->setSortOrder($maxOrder);
$group->addAttribute($attribute);
}
$this->attributeSaver->saveAll($attributes);
$this->groupSaver->save($group);
}
示例9: process
/**
* {@inheritdoc}
*/
public function process($entity)
{
$this->form->setData($entity);
if ($this->request->isMethod('POST')) {
$this->form->submit($this->request);
if ($this->form->isValid()) {
$this->saver->save($entity);
return true;
}
}
return false;
}
示例10: postRemove
/**
* @param RemoveEvent $event
*/
public function postRemove(RemoveEvent $event)
{
$author = '';
$subject = $event->getSubject();
if (null !== ($token = $this->tokenStorage->getToken()) && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$author = $token->getUser()->getUsername();
}
$previousVersion = $this->versionRepository->getNewestLogEntry(ClassUtils::getClass($subject), $event->getSubjectId());
$version = $this->versionFactory->create(ClassUtils::getClass($subject), $event->getSubjectId(), $author, 'Deleted');
$version->setVersion(null !== $previousVersion ? $previousVersion->getVersion() + 1 : 1)->setSnapshot(null !== $previousVersion ? $previousVersion->getSnapshot() : [])->setChangeset([]);
$this->versionSaver->save($version);
}
示例11: toggleAction
/**
* Activate/Deactivate a currency
*
* @param Currency $currency
*
* @AclAncestor("pim_enrich_currency_toggle")
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function toggleAction(Currency $currency)
{
try {
$currency->toggleActivation();
$this->currencySaver->save($currency);
$this->request->getSession()->getFlashBag()->add('success', new Message('flash.currency.updated'));
} catch (LinkedChannelException $e) {
$this->request->getSession()->getFlashBag()->add('error', new Message('flash.currency.error.linked_to_channel'));
} catch (\Exception $e) {
$this->request->getSession()->getFlashBag()->add('error', new Message('flash.error ocurred'));
}
return new RedirectResponse($this->router->generate('pim_enrich_currency_index'));
}
示例12: notify
/**
* {@inheritdoc}
*/
public function notify(NotificationInterface $notification, array $users)
{
$userNotifications = [];
foreach ($users as $user) {
try {
$user = is_object($user) ? $user : $this->userProvider->loadUserByUsername($user);
$userNotifications[] = $this->userNotifFactory->createUserNotification($notification, $user);
} catch (UsernameNotFoundException $e) {
continue;
}
}
$this->notificationSaver->save($notification);
$this->userNotifsSaver->saveAll($userNotifications);
return $this;
}
示例13: removeAttributeAction
/**
* Remove an attribute
*
* @param int $familyId
* @param int $attributeId
*
* @AclAncestor("pim_enrich_family_edit_attributes")
*
* @throws DeleteException
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function removeAttributeAction($familyId, $attributeId)
{
$family = $this->findOr404('PimCatalogBundle:Family', $familyId);
$attribute = $this->findOr404($this->attributeClass, $attributeId);
if (false === $family->hasAttribute($attribute)) {
throw new DeleteException($this->getTranslator()->trans('flash.family.attribute not found'));
} elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
throw new DeleteException($this->getTranslator()->trans('flash.family.identifier not removable'));
} elseif ($attribute === $family->getAttributeAsLabel()) {
throw new DeleteException($this->getTranslator()->trans('flash.family.label attribute not removable'));
} else {
$family->removeAttribute($attribute);
foreach ($family->getAttributeRequirements() as $requirement) {
if ($requirement->getAttribute() === $attribute) {
$family->removeAttributeRequirement($requirement);
$this->getManagerForClass(ClassUtils::getClass($requirement))->remove($requirement);
}
}
$this->familySaver->save($family);
}
if ($this->getRequest()->isXmlHttpRequest()) {
return new Response('', 204);
} else {
return $this->redirectToRoute('pim_enrich_family_edit', ['id' => $family->getId()]);
}
}
示例14: updateAction
/**
* Update product
*
* @param Request $request
* @param integer $id
*
* @Template("PimEnrichBundle:Product:edit.html.twig")
* @AclAncestor("pim_enrich_product_index")
* @return RedirectResponse
*/
public function updateAction(Request $request, $id)
{
$product = $this->findProductOr404($id);
$this->productManager->ensureAllAssociationTypes($product);
$form = $this->createForm('pim_product_edit', $product, $this->getEditFormOptions($product));
$form->submit($request, false);
if ($form->isValid()) {
try {
$this->mediaManager->handleProductMedias($product);
$this->productSaver->save($product);
$this->addFlash('success', 'flash.product.updated');
} catch (MediaManagementException $e) {
$this->addFlash('error', $e->getMessage());
}
$params = ['id' => $product->getId(), 'dataLocale' => $this->getDataLocaleCode()];
if ($comparisonLocale = $this->getComparisonLocale()) {
$params['compareWith'] = $comparisonLocale;
}
return $this->redirectAfterEdit($params);
} else {
$this->addFlash('error', 'flash.product.invalid');
}
$channels = $this->getRepository('PimCatalogBundle:Channel')->findAll();
$trees = $this->productCatManager->getProductCountByTree($product);
return $this->getProductEditTemplateParams($form, $product, $channels, $trees);
}
示例15: removeAttributeAction
/**
* Remove an attribute
*
* @param int $familyId
* @param int $attributeId
*
* @AclAncestor("pim_enrich_family_edit_attributes")
*
* @throws DeleteException
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
*/
public function removeAttributeAction($familyId, $attributeId)
{
$family = $this->familyRepository->find($familyId);
if (null === $family) {
throw new NotFoundHttpException(sprintf('%s entity not found', $this->familyClass));
}
$attribute = $this->attributeRepo->find($attributeId);
if (null === $attribute) {
throw new NotFoundHttpException(sprintf('%s entity not found', $this->attributeClass));
}
if (false === $family->hasAttribute($attribute)) {
throw new DeleteException($this->translator->trans('flash.family.attribute not found'));
} elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
throw new DeleteException($this->translator->trans('flash.family.identifier not removable'));
} elseif ($attribute === $family->getAttributeAsLabel()) {
throw new DeleteException($this->translator->trans('flash.family.label attribute not removable'));
} else {
$family->removeAttribute($attribute);
foreach ($family->getAttributeRequirements() as $requirement) {
if ($requirement->getAttribute() === $attribute) {
$family->removeAttributeRequirement($requirement);
$this->doctrine->getManagerForClass(ClassUtils::getClass($requirement))->remove($requirement);
}
}
$this->familySaver->save($family);
}
if ($this->request->isXmlHttpRequest()) {
return new Response('', 204);
} else {
return new RedirectResponse($this->router->generate('pim_enrich_family_edit', ['id' => $family->getId()]));
}
}