Schedule article document for index.

@param AbstractMappingEvent $event
423814
public function handleScheduleIndex(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleDocument) {
            if (!$document instanceof ArticlePageDocument) {
                return;
            }

            $document = $document->getParent();
        }

        $this->documents[$document->getUuid()] = [
            'uuid' => $document->getUuid(),
            'locale' => $document->getLocale(),
        ];
    }
740940
public function prepareSearchQuery(IndexSearchQueryEvent $event)
    {
        $body = [];
        $query = $event->getQuery();

        if (null !== $limit = $query->getLimit()) {
            $body["size"] = $limit;
        }

        if (null !== $offset = $query->getOffset()) {
            $body["from"] = $offset;
        }

        if (null !== $orderBy = $query->getOrderBy()) {
            foreach ($orderBy as $order) {
                list($orderColumn, $orderType) = $order;

                switch ($orderType) {
                    case Order::ASC:
                        $body["sort"][$orderColumn] = "asc";
                        break;

                    case Order::DESC:
                        $body["sort"][$orderColumn] = "desc";
                        break;
                }
            }
        }

        $groups = $query->getCriterionGroups();
        $totalGroupCount = count($groups);

        $previousGroupLink = null;

        if ($totalGroupCount === 1) {
            // Handle simple group
            $criterionGroup = $query->getCriterionGroups();
            /** @var CriterionGroupInterface $criterionGroup */
            $criterionGroup = array_pop($criterionGroup)[0];

            $body["query"] = $this->transformCriterionGroup($criterionGroup);
        } else {
            // Handle complex group
            $splitGroups = [];
            $i = 0;

            foreach ($groups as $groupTuple) {
                /** @var CriterionGroupInterface $criterionGroup */
                list($criterionGroup, $link) = $groupTuple;
                $splitGroups[$i][] = $criterionGroup;

                if ($link === Link::LINK_OR) {
                    $i++;
                }
            }

            if (count($splitGroups) === 1) {
                // Global query without OR

                /** @var CriterionGroupInterface $criterionGroup */
                foreach ($splitGroups[0] as $criterionGroup) {
                    $body["query"]["filtered"]["filter"]["and"][]["query"] = $this->transformCriterionGroup($criterionGroup);
                }
            } else {
                // Global query with OR
                foreach ($splitGroups as $criterionGroups) {
                    $orNode = &$body["query"]["filtered"]["filter"]["or"][];

                    foreach ($criterionGroups as $criterionGroup) {
                        $orNode["query"]["filtered"]["filter"]["and"][]["query"] = $this->transformCriterionGroup($criterionGroup);
                    }
                }
            }
        }

        $event->setExtraData($body);
    }
447678
public function onPostSerialize(ObjectEvent $event)
    {
        $document = $event->getObject();

        if (!$document instanceof LocaleBehavior || !$this->documentRegistry->hasDocument($document)) {
            return;
        }

        $visitor = $event->getVisitor();

        $visitor->addData('availableLocales', $this->documentInspector->getLocales($document));
        $visitor->addData('contentLocales', $this->documentInspector->getConcreteLocales($document));

        $localizationState = $this->documentInspector->getLocalizationState($document);

        if (LocalizationState::GHOST === $localizationState) {
            $visitor->addData('type', ['name' => 'ghost', 'value' => $document->getLocale()]);
        }

        if (LocalizationState::SHADOW === $localizationState) {
            $visitor->addData('type', ['name' => 'shadow', 'value' => $document->getLocale()]);
        }
    }
434306
public function scheduleForSynchronization(object $document) : void
    {
        $class                                                                       = $this->dm->getClassMetadata(get_class($document));
        $this->scheduledForSynchronization[$class->name][spl_object_hash($document)] = $document;
    }
239957
public function onSchemaIndexDefinition(SchemaIndexDefinitionEventArgs $event): void
    {
        $event->preventDefault();
        $data = $event->getTableIndex();

        $name = str_replace('.', '__', $data['name']);
        $event->setIndex(new Index($name, $data['columns'], $data['unique'], $data['primary'], $data['flags'], $data['options']));
    }
152273
public static function onFlushContent(Event $event)
    {
        $content = $event->getTarget();
        if (!($content instanceof AbstractClassContent)) {
            return;
        }

        $page = $content->getMainNode();
        if (null === $page) {
            return;
        }

        $url = $page->getUrl(false);
        if (!empty($url) && in_array($page->getUid(), self::$alreadyDone)) {
            return false;
        }

        $newEvent = new Event($page);
        $newEvent->setDispatcher($event->getDispatcher());
        self::onFlushPage($newEvent);
    }
868913
public function publish(GenericEvent $event)
    {
        $legacyArticle = $event->getSubject();
        $arguments = $event->getArguments();

        if ($legacyArticle instanceof \Article) {
            $entry = $this->em
                ->getRepository('Newscoop\IngestPluginBundle\Entity\Feed\Entry')
                ->findOneByArticleId($legacyArticle->getArticleNumber());
            if ($entry !== null) {
                $entry->setPublished(new \DateTime($legacyArticle->getPublishDate()));
                $this->em->persist($entry);
                $this->em->flush();
            }
        }
    }
1298989
public static function onFlushPage(Event $event)
    {
        $em = $event->getApplication()->getEntityManager();
        $uow = $em->getUnitOfWork();
        $page = $event->getTarget();
        if ($uow->isScheduledForInsert($page) && $page->getParent() !== null && $page->getState() < 4) {
            self::setSectionHasChildren($em, $page->getParent()->getSection(), +1);
        }
    }
482757
public function handlePersist(AbstractMappingEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutablePageBehavior) {
            return;
        }

        $document->setUuid($event->getNode()->getIdentifier());

        $propertyName = $this->getRoutePathPropertyName($document->getStructureType(), $event->getLocale());
        $routePath = $event->getNode()->getPropertyValueWithDefault($propertyName, null);

        $route = $this->conflictResolver->resolve($this->chainRouteGenerator->generate($document, $routePath));
        $document->setRoutePath($route->getPath());

        $event->getNode()->setProperty($propertyName, $route->getPath());

        if (!$document instanceof ChildrenBehavior) {
            return;
        }

        foreach ($document->getChildren() as $child) {
            if (!$child instanceof RoutablePageBehavior) {
                continue;
            }

            $route = $this->chainRouteGenerator->generate($child);
            $child->setRoutePath($route->getPath());

            $node = $this->documentInspector->getNode($child);
            $node->setProperty($propertyName, $route->getPath());
        }
    }
729831
public function prepareIndexMapping(IndexEvent $event)
    {
        $code = $event->getIndexCode();
        $mapping = $event->getMapping();

        $parameters = array("index" => $event->getIndexName());
        $driver = $this->getDriver();

        $shards = $driver->getExtraConfiguration("number_of_shards")->getValue();
        if (null !== $shards) {
            $parameters["body"]["settings"]["number_of_shards"] = $shards;
        }

        $replicas = $driver->getExtraConfiguration("number_of_replicas")->getValue();
        if (null !== $replicas) {
            $parameters["body"]["settings"]["number_of_replicas"] = $replicas;
        }

        $esMapping = &$parameters["body"]["mappings"][$code];

        $esMapping["_source"] = ["enabled" => $driver->getExtraConfiguration("save_source")];

        foreach ($mapping->getMapping() as $column => $type) {
            $resolvedType = $this->resolveType($type);

            $esMapping["properties"][$column] = $resolvedType;
        }

        $event->setExtraData($parameters);
    }
26013
public function onFlushPage(Event $event)
    {
        // Checks if page caching is available
        $this->object = $event->getTarget();
        if (false === ($this->object instanceof Page) || false === $this->checkCachePageEvent(false)) {
            return;
        }

        if (true === $this->page_cache_deletion_done) {
            return;
        }

        $pages = ScheduledEntities::getScheduledEntityUpdatesByClassname(
            $this->application->getEntityManager(), 'BackBee\NestedNode\Page'
        );
        if (0 === count($pages)) {
            return;
        }

        $page_uids = array();
        foreach ($pages as $page) {
            $page_uids[] = $page->getUid();
        }

        $this->cache_page->removeByTag($page_uids);
        $this->page_cache_deletion_done = true;
        $this->application->debug(sprintf(
            'Remove cache for `%s(%s)`.',
            get_class($this->object),
            implode(', ', $page_uids)
        ));
    }
12580
public function onPostConvertToDocument(PostConvertToDocumentEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticleViewDocumentInterface) {
            return;
        }

        $document->setTargetWebspace($this->getTargetWebspace($document));
    }
784142
public function onPostSerialize(ObjectEvent $event)
    {
        $document = $event->getObject();

        if (!$document instanceof ChildrenBehavior || !$this->documentRegistry->hasDocument($document)) {
            return;
        }

        $visitor = $event->getVisitor();
        $visitor->addData('hasSub', $this->documentInspector->hasChildren($document));
    }
775562
public function checkOptions(PersistEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument) {
            return;
        }

        $autoRename = $event->getOption('auto_rename');

        if (false !== $autoRename) {
            throw new \InvalidArgumentException('Persist "ArticlePageDocument" only with option "auto_rename" set to "false" allowed');
        }
    }
51465
@MainThread
    private void scheduleSubscribersInvocation(Event event) {
        for (EventTarget target : targets) {
            for (EventMethod method : target.methods) {
                if (event.getKey().equals(method.eventKey)
                        && method.type == EventMethod.Type.SUBSCRIBE) {

                    Utils.log(event.getKey(), method, "Scheduling event execution");

                    ((EventBase) event).handlersCount++;

                    Task task = Task.create(this, target, method, event);
                    executionQueue.add(task);
                }
            }
        }
    }
425273
public function beforeAction($event)
    {
        if (in_array($event->action->id, $this->actions) || in_array('*', $this->actions)) {
            $sender = $event->sender;
            $command = $sender->id . '/' . $sender->action->id . $this->getActionParams();
            $this->schedule = new CronScheduleModel();
            $this->schedule->startCronSchedule($command);
            $this->setupApplicationErrorHandlers();
        }
    }
1226046
public function onSitemapNodeEdit(SitemapNodeEvent $event)
    {
        $node = $event->getNode();
        if (in_array($node->getType(), $this->textNodeTypes)) {
            $tab = new Tab(
                $event->getTranslator()->trans('text', array(), 'SilvestraTextNodeBundle'),
                'silvestra_text_node',
                $event->getRouter()->generate(
                    'silvestra_text_node',
                    array('_format' => 'json', 'nodeId' => $node->getId())
                )
            );

            $event->addTab($tab);
        }
    }