Updates fiile permissions on Flush

@param OnFlushEventArgs $eventArgs
@return boolean
327575
public function postRemoveEntity(LifecycleEventArgs $eventArgs)
    {
        $file = $eventArgs->getDocument();
        if (!$file instanceof Attachment) {
            return;
        }
        
        $dm     = $eventArgs->getDocumentManager();
        //$repo   = $dm->getRepository('Applications\Entity\Application');

        $fileId = new \MongoId($file->id);
        
        $dm->createQueryBuilder('Applications\Entity\Application')
           ->update()->multiple(true)
           ->field('attachments')->equals($fileId)->pull($fileId)
           ->getQuery()->execute();
        
        
        $dm->createQueryBuilder('Applications\Entity\Application')
           ->update()->multiple(true)
           ->field('contact.image')->equals($fileId)->set(null)
           ->getQuery()->execute();
    }
412971
public function onFlush(OnFlushEventArgs $args)
    {
        $em = $args->getEntityManager();

        $unitOfWork = $em->getUnitOfWork();

        foreach ($unitOfWork->getScheduledEntityUpdates() as $entity) {
            if ($entity instanceof PageInterface) {
                if ($contentRoute = $entity->getContentRoute()) {
                    $contentRoute->setPath(PageHelper::getPageRoutePath($entity->getPath()));
                    $em->persist($contentRoute);
                    $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);
                    foreach ($entity->getAllChildren() as $child) {
                        $contentRoute = $child->getContentRoute();
                        $contentRoute->setPath(PageHelper::getPageRoutePath($child->getPath()));
                        $em->persist($contentRoute);
                        $unitOfWork->computeChangeSet($em->getClassMetadata(get_class($contentRoute)), $contentRoute);

                        if ($entity->getStatus() == Page::STATUS_PUBLISHED) {
                            if ($childSnapshot = $child->getSnapshot()) {
                                $snapshotRoute = $childSnapshot->getContentRoute();

                                $newPath = PageHelper::getPageRoutePath($child->getPath());

                                $snapshotRoute->setPath($newPath);
                                $childSnapshot->setPath($newPath);

                                $em->persist($childSnapshot);
                                $em->persist($snapshotRoute);

                                $unitOfWork->computeChangeSet(
                                    $em->getClassMetadata(get_class($childSnapshot)),
                                    $childSnapshot
                                );
                                $unitOfWork->computeChangeSet(
                                    $em->getClassMetadata(get_class($snapshotRoute)),
                                    $snapshotRoute
                                );
                            }
                        }
                    }
                }
            }
        }
    }
1107619
public function preFlushModifiedAt(\Doctrine\ORM\Event\PreFlushEventArgs $args) : self
    {
        if (is_null($this->getModifiedAt())) {
            $this->setModifiedAt(new \DateTime('now'));
        }

        return $this;
    }
12357
public function preFlush(PreFlushEventArgs $args)
    {
        $uow = $args->getEntityManager()->getUnitOfWork();
        $result = $uow->getIdentityMap();
        if(isset($result[$this->targetClass])) {
            foreach ($result[$this->targetClass] as $entity) {
                $this->updateEntity($entity);
            }
        }
    }
379455
public function onFlush(OnFlushEventArgs $args)
    {
        $this->em = $args->getEntityManager();
        $this->uow = $this->em->getUnitOfWork();
        $this->widgetRepo = $this->em->getRepository('Victoire\Bundle\WidgetBundle\Entity\Widget');
        $this->viewRepo = $this->em->getRepository('Victoire\Bundle\CoreBundle\Entity\View');

        $updatedEntities = $this->uow->getScheduledEntityUpdates();
        $deletedEntities = $this->uow->getScheduledEntityDeletions();

        //Update View's CSS and inheritors of updated and deleted widgets
        foreach (array_merge($updatedEntities, $deletedEntities) as $entity) {
            if (!($entity instanceof Widget)) {
                continue;
            }

            /* @var Widget $entity */
            $widgetMap = $entity->getWidgetMap();
            if ($widgetMap->getAction() !== WidgetMap::ACTION_DELETE) {
                $view = $widgetMap->getView();
                if ($this->em->contains($view)) {
                    $this->updateViewCss($view);
                    $this->setTemplateInheritorsCssToUpdate($view);
                }
            }
        }

        //Remove CSS of deleted View and update its inheritors
        foreach ($deletedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->viewCssBuilder->removeCssFile($entity->getCssHash());
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        //Update CSS of updated View and its inheritors
        foreach ($updatedEntities as $entity) {
            if (!($entity instanceof View)) {
                continue;
            }

            $this->updateViewCss($entity);
            $this->setTemplateInheritorsCssToUpdate($entity);
        }

        $this->uow->computeChangeSets();
    }
1062997
public function set(array $args = array()) {
        if (!file_exists('application/data/cache')
            || !file_exists('application/data/logs')
            || !file_exists('public/uploads')
        ) {
            Garp_Cli::lineOut(
                'It looks like there are no directories for me to set permissions on.',
                Garp_Cli::YELLOW
            );
            return true;
        }
        Garp_Cli::lineOut('Setting permissions on writable folders...');
        passthru('chmod -R 777 application/data/cache');
        passthru('chmod -R 777 application/data/logs');
        passthru('chmod -R 777 public/uploads');

        Garp_Cli::lineOut('Done.');
        Garp_Cli::lineOut('');
        return true;
    }
454928
public function postUpdate(LifecycleEventArgs $args)
    {
        $object = $args->getObject();

        if (!$object instanceof FileInterface) {
            return;
        }

        // should clear file object also.
        if ($object->isShouldRemove()) {
            $args->getObjectManager()->remove($object);
        }
    }
1281594
public function preRemove($eventArgs)
    {
        $entity = $eventArgs->getEntity();
        foreach ($this->metadata->getManagedFields($entity) as $field) {
            $file = PropertyHelper::getValue($entity, $field);

            if ($file) {
                $filepath = $this->fileManager->getFilePath($entity, $field, $file);

                $this->unitOfWork[spl_object_hash($entity)][$field]['delete'] = function (FileManager $fm) use ($filepath) {
                    $fm->delete($filepath);
                };
            }
        }
    }
118881
public function preUpdate(LifecycleEventArgs $eventArgs)
    {
        $document = $eventArgs->getDocument();
        if (!$document instanceof JobInterface) {
            return;
        }
        $dm = $eventArgs->getDocumentManager();
        $changeset = $dm->getUnitOfWork()->getDocumentChangeset($document);
        
        if (!isset($changeset['user'])) {
            return;
        }
        
        $userId = $document->getUser()->getId();

        $dm->createQueryBuilder('Applications\Entity\Application')
            ->update()->multiple(true)
            ->field('refs.jobs.userId')->set($userId)
            ->field('refs.jobs.__id__')->equals($document->getId())
            ->field('refs.jobs.userId')->notEqual($userId)
            ->getQuery()
            ->execute();
    }
192936
public function preUpdate(PreUpdateEventArgs $eventArgs)
    {
        $entity = $eventArgs->getEntity();
        if ($entity instanceof CategoryInterface) {
            $this->removeParentCategoryForRootCategory($entity);
        }

        return $this;
    }
265270
public function handleFlush(FlushEvent $event)
    {
        foreach ($this->persistEvents as $persistEvent) {
            $document = $persistEvent->getDocument();
            $structure = $this->documentToStructure($document);

            $event = new ContentNodeEvent($this->documentInspector->getNode($document), $structure);
            $this->eventDispatcher->dispatch(ContentEvents::NODE_POST_SAVE, $event);
        }

        $this->persistEvents = [];
    }
876117
public function onFlush(OnFlushEventArgs $args): void
    {
        $token = $this->getTokenStorage()->getToken();

        if (!$this->getPermissionManager()->isEnabled()
                || null === $token || $token instanceof ConsoleToken) {
            return;
        }

        $uow = $args->getEntityManager()->getUnitOfWork();
        $createEntities = $uow->getScheduledEntityInsertions();
        $updateEntities = $uow->getScheduledEntityUpdates();
        $deleteEntities = $uow->getScheduledEntityDeletions();

        $this->postResetPermissions = array_merge($createEntities, $updateEntities, $deleteEntities);
        $this->getPermissionManager()->preloadPermissions($this->postResetPermissions);

        $this->checkAllScheduledByAction($createEntities, 'create');
        $this->checkAllScheduledByAction($updateEntities, 'update');
        $this->checkAllScheduledByAction($deleteEntities, 'delete');
    }
367839
public function onFlush(\Doctrine\ORM\Event\OnFlushEventArgs $eventArgs) {
        $reCacheEntities = [];
        
        $em = $eventArgs->getEntityManager();
        $uow = $em->getUnitOfWork();
        
        foreach ($uow->getScheduledEntityInsertions() as $entity) {
            $reCacheEntities[get_class($entity)] = true;
        }

        foreach ($uow->getScheduledEntityUpdates() as $entity) {
            $reCacheEntities[get_class($entity)] = true;
        }

        foreach ($uow->getScheduledEntityDeletions() as $entity) {
            $reCacheEntities[get_class($entity)] = true;
        }

        foreach ($uow->getScheduledCollectionDeletions() as $col) {
            $reCacheEntities[get_class($entity)] = true;
        }

        foreach ($uow->getScheduledCollectionUpdates() as $col) {
            $reCacheEntities[get_class($entity)] = true;
        }
        
        foreach ($reCacheEntities as $entityNamespace => $flag) {
            $this->recache($entityNamespace);
        }
    }
434518
public function onFlush(OnFlushEventArgs $args)
    {
        $unit = $args->getEntityManager()->getUnitOfWork();
        $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');


        foreach($unit->getScheduledEntityUpdates() as $entity) {

            if(     $entity instanceof RoutableNodeInterface
                &&  $entity->hasAutoNodeRouteGeneration()
            ) {

                $hasNodeRoute = false;
                $routeGenerated = false;

                foreach ($entity->getRoutes() as $route) {
                    if($route instanceof AutoNodeRoute) {
                        $hasNodeRoute = true;
                        break;
                    }
                }

                if(!$hasNodeRoute) {
                    $routeManager = $this->container->get('mm_cmf_routing.node_route_manager');
                    $entity->addRoute($routeManager->generateAutoNodeRoute($entity));
                    $routeGenerated = true;
                }


                // check if Node::name has changed
                $changed = $unit->getEntityChangeSet($entity);

                if(     array_key_exists('name', $changed)
                    ||  array_key_exists('parent', $changed)
                    ||  $routeGenerated
                ) {

                    // update all child AutoNodeRoutes
                    $routeManager->getAutoNodeRoutesRecursive($entity);
                    $unit->computeChangeSets();
                }
            }
        }
    }
910131
public function onFlush(OnFlushEventArgs $args)
    {
        $entityManager = $args->getEntityManager();

        $unitOfWork = $entityManager->getUnitOfWork();

        foreach ($unitOfWork->getScheduledEntityDeletions() as $entity) {

            $traits = class_uses(get_class($entity));

            if (in_array('BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityIsDeletedTrait', $traits)) {
                /**
                 * @var $entity \BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityIsDeletedTrait
                 */
                // hard delete
                if ($entity->isDeleted()) {
                    continue;
                }

                //soft delete
                $entity->setIsDeleted(true);

                $entityManager->persist($entity);
                $unitOfWork->scheduleExtraUpdate($entity, array('isDeleted'=> array(0, 1)));
            }

            if (in_array('BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityDeletedTrait', $traits)) {
                /**
                 * @var $entity \BespokeSupport\CreatedUpdatedDeletedBundle\Traits\EntityDeletedTrait
                 */

                // hard delete
                if ($entity->getDeleted()) {
                    continue;
                }

                //soft delete
                $entity->setDeleted(new \DateTime());
                $entityManager->persist($entity);
                $unitOfWork->scheduleExtraUpdate($entity, array('deleted'=> array(null, new \DateTime())));
            }
        }
    }
22318
public function preRemove(EventArgs $eventArgs)
    {
        if (method_exists($eventArgs, 'getEntity')) {
            $this->_triggerEvent(Events::preRemove, $eventArgs->getEntity(), $eventArgs);
        }
    }
23348
public function postLoad(LifecycleEventArgs $eventArgs)
    {
        $entityManager = $eventArgs->getEntityManager();
        $object = $eventArgs->getEntity();
        $uploadableMeta = $this->getObjectExtendedMetadata($entityManager, $object);

        if ($uploadableMeta->hasUploadableProperties()) {
            $this->loadFiles($entityManager, $object, $uploadableMeta);
        }
    }